forked from len0rd/rockbox
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
This commit is contained in:
parent
dae698cad4
commit
4bd8715449
1 changed files with 32 additions and 35 deletions
|
|
@ -24,6 +24,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
#include "debug.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
#include "SDL.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)
|
void sdl_audio_callback(void *udata, Uint8 *stream, int len)
|
||||||
{
|
{
|
||||||
Uint32 pcm_data_played, need_to_play;
|
Uint32 have_now;
|
||||||
FILE *debug = (FILE *)udata;
|
FILE *debug = (FILE *)udata;
|
||||||
|
|
||||||
/* At all times we need to write a full 'len' bytes to stream. */
|
/* At all times we need to write a full 'len' bytes to stream. */
|
||||||
|
|
||||||
if (pcm_data_size > 0) {
|
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, have_now);
|
||||||
|
|
||||||
memcpy(stream, pcm_data, pcm_data_played);
|
|
||||||
|
|
||||||
if (debug != NULL) {
|
if (debug != NULL) {
|
||||||
fwrite(pcm_data, sizeof(Uint8), pcm_data_played, debug);
|
fwrite(pcm_data, sizeof(Uint8), have_now, debug);
|
||||||
|
}
|
||||||
|
stream += have_now;
|
||||||
|
len -= have_now;
|
||||||
|
pcm_data += have_now;
|
||||||
|
pcm_data_size -= have_now;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream += pcm_data_played;
|
while (len > 0)
|
||||||
need_to_play = len - pcm_data_played;
|
{
|
||||||
pcm_data += pcm_data_played;
|
if (callback_for_more) {
|
||||||
pcm_data_size -= pcm_data_played;
|
|
||||||
|
|
||||||
while(need_to_play > 0) {
|
|
||||||
/* Loop until we have written enough */
|
|
||||||
|
|
||||||
callback_for_more(&pcm_data, &pcm_data_size);
|
callback_for_more(&pcm_data, &pcm_data_size);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
stream += pcm_data_played;
|
|
||||||
need_to_play -= pcm_data_played;
|
|
||||||
pcm_data += pcm_data_played;
|
|
||||||
pcm_data_size -= pcm_data_played;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
pcm_data_size = 0;
|
|
||||||
pcm_data = NULL;
|
pcm_data = NULL;
|
||||||
|
pcm_data_size = 0;
|
||||||
|
}
|
||||||
|
if (pcm_data_size > 0) {
|
||||||
|
have_now = (((Uint32)len) > pcm_data_size) ? pcm_data_size : (Uint32)len;
|
||||||
|
|
||||||
/* No data, try and get some */
|
memcpy(stream, pcm_data, have_now);
|
||||||
callback_for_more(&pcm_data, &pcm_data_size);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue