mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-11-17 15:51:25 +00:00
test: loopwave shouldn't use an audiostream callback.
This commit is contained in:
@@ -37,28 +37,11 @@ static struct
|
|||||||
static SDL_AudioDeviceID device;
|
static SDL_AudioDeviceID device;
|
||||||
static SDL_AudioStream *stream;
|
static SDL_AudioStream *stream;
|
||||||
|
|
||||||
static void SDLCALL
|
static void fillerup(void)
|
||||||
fillerup(SDL_AudioStream *stream, int len, void *unused)
|
|
||||||
{
|
{
|
||||||
Uint8 *waveptr;
|
if (SDL_GetAudioStreamAvailable(stream) < (wave.soundlen / 2)) {
|
||||||
int waveleft;
|
SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen);
|
||||||
|
|
||||||
/*SDL_Log("CALLBACK WANTS %d MORE BYTES!", len);*/
|
|
||||||
|
|
||||||
/* Set up the pointers */
|
|
||||||
waveptr = wave.sound + wave.soundpos;
|
|
||||||
waveleft = wave.soundlen - wave.soundpos;
|
|
||||||
|
|
||||||
/* Go! */
|
|
||||||
while (waveleft <= len) {
|
|
||||||
SDL_PutAudioStreamData(stream, waveptr, waveleft);
|
|
||||||
len -= waveleft;
|
|
||||||
waveptr = wave.sound;
|
|
||||||
waveleft = wave.soundlen;
|
|
||||||
wave.soundpos = 0;
|
|
||||||
}
|
}
|
||||||
SDL_PutAudioStreamData(stream, waveptr, len);
|
|
||||||
wave.soundpos += len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||||
@@ -99,8 +82,6 @@ open_audio(void)
|
|||||||
SDL_free(wave.sound);
|
SDL_free(wave.sound);
|
||||||
quit(2);
|
quit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SetAudioStreamGetCallback(stream, fillerup, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,7 +92,7 @@ static int done = 0;
|
|||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
static void loop(void)
|
static void loop(void)
|
||||||
{
|
{
|
||||||
if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) {
|
if (done) {
|
||||||
emscripten_cancel_main_loop();
|
emscripten_cancel_main_loop();
|
||||||
} else {
|
} else {
|
||||||
fillerup();
|
fillerup();
|
||||||
@@ -195,6 +176,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fillerup();
|
||||||
SDL_Delay(100);
|
SDL_Delay(100);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user