diff options
author | Dan Everton <dan@iocaine.org> | 2007-01-05 10:30:18 +0000 |
---|---|---|
committer | Dan Everton <dan@iocaine.org> | 2007-01-05 10:30:18 +0000 |
commit | 5efed097fd1948fe19bfd9bf1cbbcd7461f3b68d (patch) | |
tree | 89b42af0c0c9fc759b88cc85d64ea306ddd0975b | |
parent | ccfa883d78546de493115faaff8a46d3a5ff087a (diff) | |
download | rockbox-5efed097fd1948fe19bfd9bf1cbbcd7461f3b68d.tar.gz rockbox-5efed097fd1948fe19bfd9bf1cbbcd7461f3b68d.zip |
Implement pcm_set_frequency in the sim. Update Doom plugin to have sound in the simulator.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11916 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/doom/i_sound.c | 6 | ||||
-rw-r--r-- | uisimulator/sdl/sound.c | 79 |
2 files changed, 52 insertions, 33 deletions
diff --git a/apps/plugins/doom/i_sound.c b/apps/plugins/doom/i_sound.c index e2eeab0c3d..0f9e6edd19 100644 --- a/apps/plugins/doom/i_sound.c +++ b/apps/plugins/doom/i_sound.c | |||
@@ -475,17 +475,13 @@ void I_SubmitSound(void) | |||
475 | if (nosfxparm) | 475 | if (nosfxparm) |
476 | return; | 476 | return; |
477 | 477 | ||
478 | #if !defined(SIMULATOR) | ||
479 | rb->pcm_play_data(&get_more, NULL, 0); | 478 | rb->pcm_play_data(&get_more, NULL, 0); |
480 | #endif | ||
481 | } | 479 | } |
482 | 480 | ||
483 | void I_ShutdownSound(void) | 481 | void I_ShutdownSound(void) |
484 | { | 482 | { |
485 | #if !defined(SIMULATOR) | ||
486 | rb->pcm_play_stop(); | 483 | rb->pcm_play_stop(); |
487 | rb->pcm_set_frequency(44100); // 44100 | 484 | rb->pcm_set_frequency(44100); // 44100 |
488 | #endif | ||
489 | } | 485 | } |
490 | 486 | ||
491 | void I_InitSound() | 487 | void I_InitSound() |
@@ -494,10 +490,8 @@ void I_InitSound() | |||
494 | 490 | ||
495 | // Initialize external data (all sounds) at start, keep static. | 491 | // Initialize external data (all sounds) at start, keep static. |
496 | printf( "I_InitSound: "); | 492 | printf( "I_InitSound: "); |
497 | #if !defined(SIMULATOR) | ||
498 | rb->pcm_play_stop(); | 493 | rb->pcm_play_stop(); |
499 | rb->pcm_set_frequency(SAMPLERATE); | 494 | rb->pcm_set_frequency(SAMPLERATE); |
500 | #endif | ||
501 | 495 | ||
502 | vol_lookup=malloc(128*256*sizeof(int)); | 496 | vol_lookup=malloc(128*256*sizeof(int)); |
503 | 497 | ||
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c index 65e2e95da7..d7e3cbd89d 100644 --- a/uisimulator/sdl/sound.c +++ b/uisimulator/sdl/sound.c | |||
@@ -35,6 +35,9 @@ static bool pcm_paused; | |||
35 | static Uint8* pcm_data; | 35 | static Uint8* pcm_data; |
36 | static size_t pcm_data_size; | 36 | static size_t pcm_data_size; |
37 | 37 | ||
38 | static SDL_AudioSpec obtained; | ||
39 | static SDL_AudioCVT cvt; | ||
40 | |||
38 | extern bool debug_audio; | 41 | extern bool debug_audio; |
39 | 42 | ||
40 | static void sdl_dma_start(const void *addr, size_t size) | 43 | static void sdl_dma_start(const void *addr, size_t size) |
@@ -146,8 +149,9 @@ bool pcm_is_playing(void) | |||
146 | 149 | ||
147 | void pcm_set_frequency(unsigned int frequency) | 150 | void pcm_set_frequency(unsigned int frequency) |
148 | { | 151 | { |
149 | /* To be implemented */ | 152 | // FIXME: Check return values |
150 | (void)frequency; | 153 | SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, frequency, |
154 | obtained.format, obtained.channels, obtained.freq); | ||
151 | } | 155 | } |
152 | 156 | ||
153 | /* | 157 | /* |
@@ -214,43 +218,64 @@ void pcm_calculate_peaks(int *left, int *right) | |||
214 | } | 218 | } |
215 | } | 219 | } |
216 | 220 | ||
221 | static long write_to_soundcard(Uint8 *stream, int len, FILE *debug) { | ||
222 | Uint32 written = (((Uint32) len) > pcm_data_size) ? pcm_data_size : (Uint32) len; | ||
223 | |||
224 | if (cvt.needed) { | ||
225 | cvt.buf = (Uint8 *) malloc(written * cvt.len_mult); | ||
226 | cvt.len = written; | ||
227 | |||
228 | memcpy(cvt.buf, pcm_data, written); | ||
229 | |||
230 | SDL_ConvertAudio(&cvt); | ||
231 | |||
232 | memcpy(stream, cvt.buf, cvt.len_cvt); | ||
233 | |||
234 | if (debug != NULL) { | ||
235 | fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, debug); | ||
236 | } | ||
237 | |||
238 | free(cvt.buf); | ||
239 | } else { | ||
240 | memcpy(stream, pcm_data, written); | ||
241 | |||
242 | if (debug != NULL) { | ||
243 | fwrite(pcm_data, sizeof(Uint8), written, debug); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | return written; | ||
248 | } | ||
249 | |||
217 | void sdl_audio_callback(void *udata, Uint8 *stream, int len) | 250 | void sdl_audio_callback(void *udata, Uint8 *stream, int len) |
218 | { | 251 | { |
219 | Uint32 have_now; | 252 | Uint32 have_now; |
220 | FILE *debug = (FILE *)udata; | 253 | FILE *debug = (FILE *) udata; |
221 | 254 | ||
222 | /* At all times we need to write a full 'len' bytes to stream. */ | 255 | /* At all times we need to write a full 'len' bytes to stream. */ |
223 | 256 | ||
257 | /* Write what we have in the PCM buffer */ | ||
224 | if (pcm_data_size > 0) { | 258 | if (pcm_data_size > 0) { |
225 | have_now = (((Uint32)len) > pcm_data_size) ? pcm_data_size : (Uint32)len; | 259 | have_now = write_to_soundcard(stream, len, debug); |
226 | 260 | ||
227 | memcpy(stream, pcm_data, have_now); | ||
228 | |||
229 | if (debug != NULL) { | ||
230 | fwrite(pcm_data, sizeof(Uint8), have_now, debug); | ||
231 | } | ||
232 | stream += have_now; | 261 | stream += have_now; |
233 | len -= have_now; | 262 | len -= have_now; |
234 | pcm_data += have_now; | 263 | pcm_data += have_now; |
235 | pcm_data_size -= have_now; | 264 | pcm_data_size -= have_now; |
236 | } | 265 | } |
237 | 266 | ||
238 | while (len > 0) | 267 | /* Audio card wants more? Get some more then. */ |
239 | { | 268 | while (len > 0) { |
240 | if (callback_for_more) { | 269 | if (callback_for_more) { |
241 | callback_for_more(&pcm_data, &pcm_data_size); | 270 | callback_for_more(&pcm_data, &pcm_data_size); |
242 | } else { | 271 | } else { |
243 | pcm_data = NULL; | 272 | pcm_data = NULL; |
244 | pcm_data_size = 0; | 273 | pcm_data_size = 0; |
245 | } | 274 | } |
246 | if (pcm_data_size > 0) { | ||
247 | have_now = (((Uint32)len) > pcm_data_size) ? pcm_data_size : (Uint32)len; | ||
248 | |||
249 | memcpy(stream, pcm_data, have_now); | ||
250 | 275 | ||
251 | if (debug != NULL) { | 276 | if (pcm_data_size > 0) { |
252 | fwrite(pcm_data, sizeof(Uint8), have_now, debug); | 277 | have_now = write_to_soundcard(stream, len, debug); |
253 | } | 278 | |
254 | stream += have_now; | 279 | stream += have_now; |
255 | len -= have_now; | 280 | len -= have_now; |
256 | pcm_data += have_now; | 281 | pcm_data += have_now; |
@@ -265,7 +290,7 @@ void sdl_audio_callback(void *udata, Uint8 *stream, int len) | |||
265 | 290 | ||
266 | int pcm_init(void) | 291 | int pcm_init(void) |
267 | { | 292 | { |
268 | SDL_AudioSpec fmt; | 293 | SDL_AudioSpec wanted_spec; |
269 | FILE *debug = NULL; | 294 | FILE *debug = NULL; |
270 | 295 | ||
271 | if (debug_audio) { | 296 | if (debug_audio) { |
@@ -273,15 +298,15 @@ int pcm_init(void) | |||
273 | } | 298 | } |
274 | 299 | ||
275 | /* Set 16-bit stereo audio at 44Khz */ | 300 | /* Set 16-bit stereo audio at 44Khz */ |
276 | fmt.freq = 44100; | 301 | wanted_spec.freq = 44100; |
277 | fmt.format = AUDIO_S16SYS; | 302 | wanted_spec.format = AUDIO_S16SYS; |
278 | fmt.channels = 2; | 303 | wanted_spec.channels = 2; |
279 | fmt.samples = 2048; | 304 | wanted_spec.samples = 2048; |
280 | fmt.callback = sdl_audio_callback; | 305 | wanted_spec.callback = sdl_audio_callback; |
281 | fmt.userdata = debug; | 306 | wanted_spec.userdata = debug; |
282 | 307 | ||
283 | /* Open the audio device and start playing sound! */ | 308 | /* Open the audio device and start playing sound! */ |
284 | if(SDL_OpenAudio(&fmt, NULL) < 0) { | 309 | if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) { |
285 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); | 310 | fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError()); |
286 | return -1; | 311 | return -1; |
287 | } | 312 | } |