mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 11:11:35 +02:00
update SDL3 to latest commit
This commit is contained in:
@@ -52,9 +52,9 @@ static void poked(int sig)
|
||||
done = 1;
|
||||
}
|
||||
|
||||
static const char *devtypestr(int iscapture)
|
||||
static const char *devtypestr(int recording)
|
||||
{
|
||||
return iscapture ? "capture" : "output";
|
||||
return recording ? "recording" : "playback";
|
||||
}
|
||||
|
||||
static void iteration(void)
|
||||
@@ -65,21 +65,21 @@ static void iteration(void)
|
||||
if (e.type == SDL_EVENT_QUIT) {
|
||||
done = 1;
|
||||
} else if (e.type == SDL_EVENT_KEY_UP) {
|
||||
if (e.key.keysym.sym == SDLK_ESCAPE) {
|
||||
if (e.key.key == SDLK_ESCAPE) {
|
||||
done = 1;
|
||||
}
|
||||
} else if (e.type == SDL_EVENT_AUDIO_DEVICE_ADDED) {
|
||||
const SDL_AudioDeviceID which = (SDL_AudioDeviceID) e.adevice.which;
|
||||
const SDL_bool iscapture = e.adevice.iscapture ? SDL_TRUE : SDL_FALSE;
|
||||
char *name = SDL_GetAudioDeviceName(which);
|
||||
const bool recording = e.adevice.recording ? true : false;
|
||||
const char *name = SDL_GetAudioDeviceName(which);
|
||||
if (name) {
|
||||
SDL_Log("New %s audio device at id %u: %s", devtypestr(iscapture), (unsigned int)which, name);
|
||||
SDL_Log("New %s audio device at id %u: %s", devtypestr(recording), (unsigned int)which, name);
|
||||
} else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device, id %u, but failed to get the name: %s",
|
||||
devtypestr(iscapture), (unsigned int)which, SDL_GetError());
|
||||
devtypestr(recording), (unsigned int)which, SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
if (!iscapture) {
|
||||
if (!recording) {
|
||||
SDL_AudioStream *stream = SDL_OpenAudioDeviceStream(which, &spec, NULL, NULL);
|
||||
if (!stream) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create/bind an audio stream to %u ('%s'): %s", (unsigned int) which, name, SDL_GetError());
|
||||
@@ -88,14 +88,13 @@ static void iteration(void)
|
||||
/* !!! FIXME: laziness, this used to loop the audio, but we'll just play it once for now on each connect. */
|
||||
SDL_PutAudioStreamData(stream, sound, soundlen);
|
||||
SDL_FlushAudioStream(stream);
|
||||
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
|
||||
SDL_ResumeAudioStreamDevice(stream);
|
||||
/* !!! FIXME: this is leaking the stream for now. We'll wire it up to a dictionary or whatever later. */
|
||||
}
|
||||
}
|
||||
SDL_free(name);
|
||||
} else if (e.type == SDL_EVENT_AUDIO_DEVICE_REMOVED) {
|
||||
dev = (SDL_AudioDeviceID)e.adevice.which;
|
||||
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.iscapture), (unsigned int)dev);
|
||||
SDL_Log("%s device %u removed.\n", devtypestr(e.adevice.recording), (unsigned int)dev);
|
||||
/* !!! FIXME: we need to keep track of our streams and destroy them here. */
|
||||
}
|
||||
}
|
||||
@@ -123,9 +122,6 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
@@ -147,7 +143,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Load the SDL library */
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) {
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
@@ -168,7 +164,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == -1) {
|
||||
if (!SDL_LoadWAV(filename, &spec, &sound, &soundlen)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
|
||||
quit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user