[r115]: / trunk / arm7 / source / audiosys.c  Maximize  Restore  History

Download this file

196 lines (176 with data), 6.7 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include "audiosys.h"
/* ---------------------- */
/* Audio Render Handler */
/* ---------------------- */
#define SHIFT_BITS 8
static Uint frequency = 44100;
static Uint channel = 1;
static NES_AUDIO_HANDLER *nah = 0;
static NES_VOLUME_HANDLER *nvh = 0;
static Uint naf_type = NES_AUDIO_FILTER_LOWPASS;
static Uint32 naf_prev;
void NESAudioFilterSet(Uint filter)
{
naf_type = filter;
naf_prev = 0x8000;
}
void NESAudioRender(Int16 *bufp, Uint buflen)
{
NES_AUDIO_HANDLER *ph;
Int32 accum;
Uint32 output;
while (buflen--)
{
accum=0;
for (ph = nah; ph; ph = ph->next)
accum+=ph->Proc();
accum += (0x8000 << SHIFT_BITS);
if (accum < 0)
output = 0;
else if (accum > (0x10000 << SHIFT_BITS) - 1)
output = (0x10000 << SHIFT_BITS) - 1;
else
output = accum;
output >>= SHIFT_BITS;
switch (naf_type)
{
case NES_AUDIO_FILTER_LOWPASS:
{
Uint32 prev = naf_prev;
naf_prev = output;
output = (output + prev) >> 1;
naf_prev = output;
}
break;
/*
case NES_AUDIO_FILTER_WEIGHTED:
{
Uint32 prev = naf_prev[ch];
naf_prev[ch] = output[ch];
output[ch] = (output[ch] + output[ch] + output[ch] + prev) >> 2;
}
break;*/
}
*bufp++ = ((Int32)output) - 0x8000;
}
}
void NESVolume(Uint volume)
{
NES_VOLUME_HANDLER *ph;
for (ph = nvh; ph; ph = ph->next) ph->Proc(volume);
}
static void NESAudioHandlerInstallOne(NES_AUDIO_HANDLER *ph)
{
/* Add to tail of list*/
ph->next = 0;
if (nah)
{
NES_AUDIO_HANDLER *p = nah;
while (p->next) p = p->next;
p->next = ph;
}
else
{
nah = ph;
}
}
void NESAudioHandlerInstall(NES_AUDIO_HANDLER *ph)
{
for (;(ph->fMode&2)?(!!ph->Proc2):(!!ph->Proc);ph++) NESAudioHandlerInstallOne(ph);
}
void NESVolumeHandlerInstall(NES_VOLUME_HANDLER *ph)
{
for (;ph->Proc;ph++)
{
/* Add to top of list*/
ph->next = nvh;
nvh = ph;
}
}
void NESAudioHandlerInitialize(void)
{
nah = 0;
nvh = 0;
}
void NESAudioFrequencySet(Uint freq)
{
frequency = freq;
}
Uint NESAudioFrequencyGet(void)
{
return frequency;
}
void NESAudioChannelSet(Uint ch)
{
channel = ch;
}
Uint NESAudioChannelGet(void)
{
return channel;
}
const short logtable[1024] = {
0,10,17,23,28,33,38,42,47,51,54,58,62,66,69,73,76,79,
82,86,89,92,95,98,101,104,107,110,113,115,118,121,124,126,
129,132,134,137,139,142,145,147,150,152,155,157,159,162,164,167,
169,171,174,176,178,181,183,185,188,190,192,194,197,199,201,203,
205,208,210,212,214,216,218,220,222,225,227,229,231,233,235,237,
239,241,243,245,247,249,251,253,255,257,259,261,263,265,267,269,
271,272,274,276,278,280,282,284,286,288,289,291,293,295,297,299,
301,302,304,306,308,310,311,313,315,317,319,320,322,324,326,327,
329,331,333,334,336,338,340,341,343,345,346,348,350,352,353,355,
357,358,360,362,363,365,367,368,370,372,373,375,377,378,380,381,
383,385,386,388,390,391,393,394,396,398,399,401,402,404,406,407,
409,410,412,413,415,416,418,420,421,423,424,426,427,429,430,432,
433,435,436,438,439,441,442,444,445,447,448,450,451,453,454,456,
457,459,460,462,463,465,466,468,469,470,472,473,475,476,478,479,
480,482,483,485,486,488,489,490,492,493,495,496,497,499,500,502,
503,504,506,507,509,510,511,513,514,515,517,518,520,521,522,524,
525,526,528,529,530,532,533,534,536,537,538,540,541,542,544,545,
546,548,549,550,551,553,554,555,557,558,559,561,562,563,564,566,
567,568,570,571,572,573,575,576,577,578,580,581,582,583,585,586,
587,588,590,591,592,593,595,596,597,598,600,601,602,603,604,606,
607,608,609,610,612,613,614,615,616,618,619,620,621,622,624,625,
626,627,628,629,631,632,633,634,635,636,638,639,640,641,642,643,
645,646,647,648,649,650,651,653,654,655,656,657,658,659,660,662,
663,664,665,666,667,668,669,670,672,673,674,675,676,677,678,679,
680,681,682,684,685,686,687,688,689,690,691,692,693,694,695,696,
697,698,700,701,702,703,704,705,706,707,708,709,710,711,712,713,
714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,
730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,
746,747,748,749,750,751,752,753,754,755,756,757,758,759,760,760,
761,762,763,764,765,766,767,768,769,770,771,772,773,774,774,775,
776,777,778,779,780,781,782,783,784,784,785,786,787,788,789,790,
791,792,792,793,794,795,796,797,798,799,799,800,801,802,803,804,
805,805,806,807,808,809,810,811,811,812,813,814,815,816,816,817,
818,819,820,821,821,822,823,824,825,826,826,827,828,829,830,830,
831,832,833,834,834,835,836,837,838,838,839,840,841,842,842,843,
844,845,845,846,847,848,849,849,850,851,852,852,853,854,855,855,
856,857,858,858,859,860,861,861,862,863,864,864,865,866,866,867,
868,869,869,870,871,872,872,873,874,874,875,876,876,877,878,879,
879,880,881,881,882,883,883,884,885,885,886,887,888,888,889,890,
890,891,892,892,893,894,894,895,895,896,897,897,898,899,899,900,
901,901,902,903,903,904,905,905,906,906,907,908,908,909,910,910,
911,911,912,913,913,914,914,915,916,916,917,917,918,919,919,920,
920,921,922,922,923,923,924,924,925,926,926,927,927,928,928,929,
930,930,931,931,932,932,933,933,934,935,935,936,936,937,937,938,
938,939,939,940,940,941,942,942,943,943,944,944,945,945,946,946,
947,947,948,948,949,949,950,950,951,951,952,952,953,953,954,954,
955,955,956,956,957,957,957,958,958,959,959,960,960,961,961,962,
962,963,963,963,964,964,965,965,966,966,967,967,967,968,968,969,
969,970,970,970,971,971,972,972,973,973,973,974,974,975,975,975,
976,976,977,977,977,978,978,979,979,979,980,980,980,981,981,982,
982,982,983,983,983,984,984,985,985,985,986,986,986,987,987,987,
988,988,988,989,989,989,990,990,990,991,991,991,992,992,992,993,
993,993,994,994,994,995,995,995,996,996,996,996,997,997,997,998,
998,998,999,999,999,999,1000,1000,1000,1001,1001,1001,1001,1002,1002,1002,
1002,1003,1003,1003,1004,1004,1004,1004,1005,1005,1005,1005,1006,1006,1006,1006,
1007,1007,1007,1007,1007,1008,1008,1008,1008,1009,1009,1009,1009,1009,1010,1010,
1010,1010,1011,1011,1011,1011,1011,1012,1012,1012,1012,1012,1013,1013,1013,1013,
1013,1013,1014,1014,1014,1014,1014,1015,1015,1015,1015,1015,1015,1016,1016,1016,
1016,1016,1016,1017,1017,1017,1017,1017,1017,1017,1018,1018,1018,1018,1018,1018,
1018,1019,1019,1019,1019,1019,1019,1019,1019,1019,1020,1020,1020,1020,1020,1020,
1020,1020,1020,1021,1021,1021,1021,1021,1021,1021,1021,1021,1021,1021,1022,1022,
1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1022,1023,1023,1023,1023,
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,
1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023,1023
};