mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-05 23:10:58 +00:00
Make Xbox GDK code public (and fix some GDK code rot) (#8844)
This commit is contained in:
parent
649556befa
commit
3a4ac15a27
37 changed files with 1550 additions and 1526 deletions
|
@ -53,23 +53,14 @@ static struct
|
|||
int soundpos; /* Current play position */
|
||||
} wave;
|
||||
|
||||
static SDL_AudioDeviceID device;
|
||||
|
||||
static void
|
||||
close_audio()
|
||||
{
|
||||
if (device != 0) {
|
||||
SDL_CloseAudioDevice(device);
|
||||
device = 0;
|
||||
}
|
||||
}
|
||||
static SDL_AudioStream *stream;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_free(sprites);
|
||||
close_audio();
|
||||
SDL_DestroyAudioStream(stream);
|
||||
SDL_free(wave.sound);
|
||||
SDLTest_CommonQuit(state);
|
||||
/* If rc is 0, just let main return normally rather than calling exit.
|
||||
|
@ -80,49 +71,13 @@ quit(int rc)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
open_audio()
|
||||
static int fillerup(void)
|
||||
{
|
||||
/* Initialize fillerup() variables */
|
||||
device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wave.spec, NULL, 0);
|
||||
if (!device) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_free(wave.sound);
|
||||
quit(2);
|
||||
const int minimum = (wave.soundlen / SDL_AUDIO_FRAMESIZE(wave.spec)) / 2;
|
||||
if (SDL_GetAudioStreamQueued(stream) < minimum) {
|
||||
SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen);
|
||||
}
|
||||
|
||||
/* Let the audio run */
|
||||
SDL_PlayAudioDevice(device);
|
||||
}
|
||||
|
||||
static void
|
||||
reopen_audio()
|
||||
{
|
||||
close_audio();
|
||||
open_audio();
|
||||
}
|
||||
|
||||
void SDLCALL
|
||||
fillerup(void *unused, Uint8 *stream, int len)
|
||||
{
|
||||
Uint8 *waveptr;
|
||||
int waveleft;
|
||||
|
||||
/* Set up the pointers */
|
||||
waveptr = wave.sound + wave.soundpos;
|
||||
waveleft = wave.soundlen - wave.soundpos;
|
||||
|
||||
/* Go! */
|
||||
while (waveleft <= len) {
|
||||
SDL_memcpy(stream, waveptr, waveleft);
|
||||
stream += waveleft;
|
||||
len -= waveleft;
|
||||
waveptr = wave.sound;
|
||||
waveleft = wave.soundlen;
|
||||
wave.soundpos = 0;
|
||||
}
|
||||
SDL_memcpy(stream, waveptr, len);
|
||||
wave.soundpos += len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -371,6 +326,7 @@ loop()
|
|||
}
|
||||
DrawSprites(state->renderers[i], sprites[i]);
|
||||
}
|
||||
fillerup();
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -469,13 +425,11 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(soundname, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
|
||||
if (SDL_LoadWAV(soundname, &wave.spec, &wave.sound, &wave.soundlen) == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", soundname, SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
wave.spec.callback = fillerup;
|
||||
|
||||
/* Show the list of available drivers */
|
||||
SDL_Log("Available audio drivers:");
|
||||
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
|
||||
|
@ -484,7 +438,12 @@ main(int argc, char *argv[])
|
|||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
open_audio();
|
||||
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL);
|
||||
if (!stream) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
|
||||
return -1;
|
||||
}
|
||||
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
|
||||
|
||||
/* Main render loop */
|
||||
done = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue