177 static void Mint_CloseAudio(_THIS) |
177 static void Mint_CloseAudio(_THIS) |
178 { |
178 { |
179 /* Stop replay */ |
179 /* Stop replay */ |
180 Buffoper(0); |
180 Buffoper(0); |
181 |
181 |
182 DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n")); |
|
183 |
|
184 /* Uninstall interrupt */ |
182 /* Uninstall interrupt */ |
185 if (NSetinterrupt(2, SI_NONE, SDL_MintAudio_EmptyGsxbInterrupt)<0) { |
183 if (NSetinterrupt(2, SI_NONE, SDL_MintAudio_EmptyGsxbInterrupt)<0) { |
186 DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n")); |
184 DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n")); |
187 } |
185 } |
188 |
186 |
189 DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n")); |
|
190 |
|
191 /* Wait if currently playing sound */ |
187 /* Wait if currently playing sound */ |
192 while (SDL_MintAudio_mutex != 0) { |
188 while (SDL_MintAudio_mutex != 0) { |
193 } |
189 } |
194 |
|
195 DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n")); |
|
196 |
190 |
197 /* Clear buffers */ |
191 /* Clear buffers */ |
198 if (SDL_MintAudio_audiobuf[0]) { |
192 if (SDL_MintAudio_audiobuf[0]) { |
199 Mfree(SDL_MintAudio_audiobuf[0]); |
193 Mfree(SDL_MintAudio_audiobuf[0]); |
200 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; |
194 SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL; |
201 } |
195 } |
202 |
|
203 DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n")); |
|
204 |
196 |
205 /* Unlock sound system */ |
197 /* Unlock sound system */ |
206 Unlocksnd(); |
198 Unlocksnd(); |
207 } |
199 } |
208 |
200 |
276 spec->format |= 0x1000; |
268 spec->format |= 0x1000; |
277 } |
269 } |
278 } |
270 } |
279 |
271 |
280 /* Calculate and select the closest frequency */ |
272 /* Calculate and select the closest frequency */ |
281 MINTAUDIO_sfreq=1; |
273 MINTAUDIO_freqcount=0; |
282 MINTAUDIO_nfreq=12; |
274 for (i=1;i<4;i++) { |
283 for (i=MINTAUDIO_sfreq;i<MINTAUDIO_nfreq;i++) { |
275 SDL_MintAudio_AddFrequency(this, MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(1<<i)), MASTERCLOCK_44K, (1<<i)-1); |
284 MINTAUDIO_hardfreq[i]=MASTERCLOCK_44K/(MASTERPREDIV_MILAN*(i+1)); |
276 } |
285 DEBUG_PRINT((DEBUG_NAME "calc:freq(%d)=%lu\n", i, MINTAUDIO_hardfreq[i])); |
277 |
286 } |
278 #if 1 |
287 |
279 for (i=0; i<MINTAUDIO_freqcount; i++) { |
288 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, 1, spec->freq); |
280 DEBUG_PRINT((DEBUG_NAME "freq %d: %lu Hz, clock %lu, prediv %d\n", |
289 spec->freq=MINTAUDIO_hardfreq[MINTAUDIO_numfreq]; |
281 i, MINTAUDIO_frequencies[i].frequency, MINTAUDIO_frequencies[i].masterclock, |
|
282 MINTAUDIO_frequencies[i].predivisor |
|
283 )); |
|
284 } |
|
285 #endif |
|
286 |
|
287 MINTAUDIO_numfreq=SDL_MintAudio_SearchFrequency(this, spec->freq); |
|
288 spec->freq=MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency; |
290 |
289 |
291 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); |
290 DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",spec->format & 0x00ff)); |
292 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); |
291 DEBUG_PRINT(("signed=%d, ", ((spec->format & 0x8000)!=0))); |
293 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); |
292 DEBUG_PRINT(("big endian=%d, ", ((spec->format & 0x1000)!=0))); |
294 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
293 DEBUG_PRINT(("channels=%d, ", spec->channels)); |
331 } |
330 } |
332 if (Setmode(channels_mode)<0) { |
331 if (Setmode(channels_mode)<0) { |
333 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); |
332 DEBUG_PRINT((DEBUG_NAME "Setmode() failed\n")); |
334 } |
333 } |
335 |
334 |
336 Devconnect(DMAPLAY, DAC, CLKEXT, MINTAUDIO_numfreq, 1); |
335 prediv = MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor; |
|
336 Devconnect(DMAPLAY, DAC, CLKEXT, prediv, 1); |
337 |
337 |
338 /* Set buffer */ |
338 /* Set buffer */ |
339 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
339 buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf]; |
340 if (Setbuffer(0, buffer, buffer + spec->size)<0) { |
340 if (Setbuffer(0, buffer, buffer + spec->size)<0) { |
341 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); |
341 DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n")); |