aud_samples.c
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*************************************************************
aud_samples.c : Nintendo 64 Music Tools Programmers Library
(c) Copyright 1997/1998, Software Creations (Holdings) Ltd.
Version 3.14
Music library frame sample calculations.
**************************************************************/
/* include configuartion */
#include "libmus_config.h"
/* include system headers */
#include <ultra64.h>
/* include current header file */
#include "aud_samples.h"
/* internal macros */
#define N_SAMPLES 184
/* internal workspace */
static u32 frame_samples;
static u32 frame_samples_min;
static u32 frame_samples_max;
static u32 extra_samples;
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[EXTERNAL FUNCTION]
__MusIntSamplesInit(retrace_count, output_rate, vsyncs_per_sec, extra_rate)
[Parameters]
retrace_count number of vsyncs per vsync message
output_rate audio libary output rate value
vsyncs_per_sec number of vsyncs per second
extra_rate ratio of extra samples to download
[Explanation]
Calculate constants for the number of samples required per frame.
[Return value]
Maximum number of samples downloaded per frame
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#ifndef SUPPORT_NAUDIO
u32 __MusIntSamplesInit(u32 retrace_count, u32 output_rate, u32 vsyncs_per_sec, u32 extra_rate)
{
u32 calc;
calc = (retrace_count*output_rate + vsyncs_per_sec - 1)/vsyncs_per_sec;
frame_samples = ((calc/16) + 1)*16;
frame_samples_min = frame_samples-16;
extra_samples = frame_samples*extra_rate/100;
return (frame_samples+16+extra_samples);
}
#else /* SUPPORT_NAUDIO */
u32 __MusIntSamplesInit(u32 retrace_count, u32 output_rate, u32 vsyncs_per_sec, u32 extra_rate)
{
u32 calc;
calc = (retrace_count*output_rate + vsyncs_per_sec - 1)/vsyncs_per_sec;
frame_samples = ((calc/N_SAMPLES) + 1)*N_SAMPLES;
frame_samples_min = frame_samples-N_SAMPLES;
frame_samples_max = frame_samples+N_SAMPLES;
extra_samples = frame_samples*extra_rate/100;
return (frame_samples+N_SAMPLES+extra_samples);
}
#endif /* SUPPORT_NAUDIO */
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[EXTERNAL FUNCTION]
__MusIntSamplesCurrent()
[Parameters]
samples number of samples left.
[Explanation]
Calculate number of samples required per frame.
[Return value]
Number of samples currently required
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#ifndef SUPPORT_NAUDIO
u32 __MusIntSamplesCurrent(u32 samples)
{
samples = (frame_samples+extra_samples+16-samples)&(~15);
if (samples<frame_samples_min)
return (frame_samples_min);
return (samples);
}
#else /* SUPPORT_NAUDIO */
u32 __MusIntSamplesCurrent(u32 samples)
{
static u32 only_one_flag=1;
if (samples>N_SAMPLES+extra_samples)
{
if (only_one_flag)
{
only_one_flag = 0;
return (frame_samples_min);
}
}
else if (samples<extra_samples)
{
if (only_one_flag)
{
only_one_flag = 0;
return (frame_samples_max);
}
}
else
{
only_one_flag = 1;
}
return (frame_samples);
}
#endif /* SUPPORT_NAUDIO */
/* end of file */