summaryrefslogtreecommitdiff
path: root/uisimulator
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-03-11 10:22:20 +0000
committerJens Arnold <amiconn@rockbox.org>2006-03-11 10:22:20 +0000
commit4bd871544908aaf2d6258315923c2d95ec9b7725 (patch)
treea826a746aa473043f7ed588b938bad8fb2c9aeb5 /uisimulator
parentdae698cad4d3b05edccd94c5dd6887997a691502 (diff)
Don't crash the simulator when the pcm callback runs out of data.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8998 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r--uisimulator/sdl/sound.c63
1 files changed, 30 insertions, 33 deletions
diff --git a/uisimulator/sdl/sound.c b/uisimulator/sdl/sound.c
index d23bcc8094..a95b19d417 100644
--- a/uisimulator/sdl/sound.c
+++ b/uisimulator/sdl/sound.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <memory.h>
+#include "debug.h"
#include "kernel.h"
#include "sound.h"
#include "SDL.h"
@@ -209,54 +210,50 @@ void pcm_calculate_peaks(int *left, int *right)
void sdl_audio_callback(void *udata, Uint8 *stream, int len)
{
- Uint32 pcm_data_played, need_to_play;
+ Uint32 have_now;
FILE *debug = (FILE *)udata;
/* At all times we need to write a full 'len' bytes to stream. */
if (pcm_data_size > 0) {
- /* We have some PCM data to play. Play as much as we can. */
+ have_now = (((Uint32)len) > pcm_data_size) ? pcm_data_size : (Uint32)len;
- pcm_data_played = (((Uint32)len) > pcm_data_size) ? pcm_data_size : (Uint32)len;
-
- memcpy(stream, pcm_data, pcm_data_played);
+ memcpy(stream, pcm_data, have_now);
if (debug != NULL) {
- fwrite(pcm_data, sizeof(Uint8), pcm_data_played, debug);
+ fwrite(pcm_data, sizeof(Uint8), have_now, debug);
}
-
- stream += pcm_data_played;
- need_to_play = len - pcm_data_played;
- pcm_data += pcm_data_played;
- pcm_data_size -= pcm_data_played;
-
- while(need_to_play > 0) {
- /* Loop until we have written enough */
+ stream += have_now;
+ len -= have_now;
+ pcm_data += have_now;
+ pcm_data_size -= have_now;
+ }
+ while (len > 0)
+ {
+ if (callback_for_more) {
callback_for_more(&pcm_data, &pcm_data_size);
+ } else {
+ pcm_data = NULL;
+ pcm_data_size = 0;
+ }
+ if (pcm_data_size > 0) {
+ have_now = (((Uint32)len) > pcm_data_size) ? pcm_data_size : (Uint32)len;
- if (pcm_data_size > 0) {
- /* We got more data */
- pcm_data_played = (need_to_play > pcm_data_size) ? pcm_data_size : need_to_play;
-
- memcpy(stream, pcm_data, pcm_data_played);
-
- if (debug != NULL) {
- fwrite(pcm_data, sizeof(Uint8), pcm_data_played, debug);
- }
+ memcpy(stream, pcm_data, have_now);
- stream += pcm_data_played;
- need_to_play -= pcm_data_played;
- pcm_data += pcm_data_played;
- pcm_data_size -= pcm_data_played;
+ if (debug != NULL) {
+ fwrite(pcm_data, sizeof(Uint8), have_now, debug);
}
+ stream += have_now;
+ len -= have_now;
+ pcm_data += have_now;
+ pcm_data_size -= have_now;
+ } else {
+ DEBUGF("sdl_audio_callback: No Data.\n");
+ sdl_dma_stop();
+ break;
}
- } else {
- pcm_data_size = 0;
- pcm_data = NULL;
-
- /* No data, try and get some */
- callback_for_more(&pcm_data, &pcm_data_size);
}
}