audio: Refer to audio devices to "playback" and "recording".

Fixes #9619.
This commit is contained in:
Ryan C. Gordon
2024-06-14 17:57:14 -04:00
parent 031dc0743f
commit 38f0214e8a
66 changed files with 939 additions and 924 deletions

View File

@@ -266,7 +266,7 @@ file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NONINTERACTIVE NONINTERACTIVE_TIMEOUT 120 NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES})
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES TESTUTILS SOURCES testmultiaudio.c)
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES TESTUTILS SOURCES testaudiohotplug.c)
add_sdl_test_executable(testaudiocapture MAIN_CALLBACKS SOURCES testaudiocapture.c)
add_sdl_test_executable(testaudiorecording MAIN_CALLBACKS SOURCES testaudiorecording.c)
add_sdl_test_executable(testatomic NONINTERACTIVE SOURCES testatomic.c)
add_sdl_test_executable(testintersections SOURCES testintersections.c)
add_sdl_test_executable(testrelative SOURCES testrelative.c)

View File

@@ -109,7 +109,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL);
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &wave.spec, NULL, NULL);
if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
return SDL_APP_FAILURE;

View File

@@ -1,3 +1,15 @@
/*
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL_test.h>
#include <SDL3/SDL_test_common.h>
@@ -19,9 +31,9 @@ typedef enum ThingType
{
THING_NULL,
THING_PHYSDEV,
THING_PHYSDEV_CAPTURE,
THING_PHYSDEV_RECORDING,
THING_LOGDEV,
THING_LOGDEV_CAPTURE,
THING_LOGDEV_RECORDING,
THING_TRASHCAN,
THING_STREAM,
THING_POOF,
@@ -38,13 +50,13 @@ struct Thing
union {
struct {
SDL_AudioDeviceID devid;
SDL_bool iscapture;
SDL_bool recording;
SDL_AudioSpec spec;
char *name;
} physdev;
struct {
SDL_AudioDeviceID devid;
SDL_bool iscapture;
SDL_bool recording;
SDL_AudioSpec spec;
Thing *physdev;
SDL_bool visualizer_enabled;
@@ -268,7 +280,7 @@ static void DestroyThing(Thing *thing)
case THING_TRASHCAN: break;
case THING_LOGDEV:
case THING_LOGDEV_CAPTURE:
case THING_LOGDEV_RECORDING:
SDL_CloseAudioDevice(thing->data.logdev.devid);
if (state->renderers[0] != NULL) {
SDL_DestroyTexture(thing->data.logdev.visualizer);
@@ -278,7 +290,7 @@ static void DestroyThing(Thing *thing)
break;
case THING_PHYSDEV:
case THING_PHYSDEV_CAPTURE:
case THING_PHYSDEV_RECORDING:
SDL_free(thing->data.physdev.name);
break;
@@ -537,7 +549,7 @@ static void StreamThing_ondrag(Thing *thing, int button, float x, float y)
if (button == SDL_BUTTON_RIGHT) { /* this is kinda hacky, but use this to disconnect from a playing source. */
if (thing->line_connected_to) {
SDL_UnbindAudioStream(thing->data.stream.stream); /* unbind from current device */
if (thing->line_connected_to->what == THING_LOGDEV_CAPTURE) {
if (thing->line_connected_to->what == THING_LOGDEV_RECORDING) {
SDL_FlushAudioStream(thing->data.stream.stream);
}
thing->line_connected_to = NULL;
@@ -550,19 +562,19 @@ static void StreamThing_ondrop(Thing *thing, int button, float x, float y)
if (droppable_highlighted_thing) {
if (droppable_highlighted_thing->what == THING_TRASHCAN) {
TrashThing(thing);
} else if (((droppable_highlighted_thing->what == THING_LOGDEV) || (droppable_highlighted_thing->what == THING_LOGDEV_CAPTURE)) && (droppable_highlighted_thing != thing->line_connected_to)) {
} else if (((droppable_highlighted_thing->what == THING_LOGDEV) || (droppable_highlighted_thing->what == THING_LOGDEV_RECORDING)) && (droppable_highlighted_thing != thing->line_connected_to)) {
/* connect to a logical device! */
SDL_Log("Binding audio stream ('%s') to logical device %u", thing->titlebar, (unsigned int) droppable_highlighted_thing->data.logdev.devid);
if (thing->line_connected_to) {
SDL_UnbindAudioStream(thing->data.stream.stream); /* unbind from current device */
if (thing->line_connected_to->what == THING_LOGDEV_CAPTURE) {
if (thing->line_connected_to->what == THING_LOGDEV_RECORDING) {
SDL_FlushAudioStream(thing->data.stream.stream);
}
}
SDL_BindAudioStream(droppable_highlighted_thing->data.logdev.devid, thing->data.stream.stream); /* bind to new device! */
thing->data.stream.total_bytes = SDL_GetAudioStreamAvailable(thing->data.stream.stream);
thing->progress = 0.0f; /* ontick will adjust this if we're on an output device.*/
thing->progress = 0.0f; /* ontick will adjust this if we're on a playback device.*/
thing->data.stream.next_level_update = SDL_GetTicks() + 100;
thing->line_connected_to = droppable_highlighted_thing;
}
@@ -592,7 +604,7 @@ static void StreamThing_ondraw(Thing *thing, SDL_Renderer *renderer)
static Thing *CreateStreamThing(const SDL_AudioSpec *spec, const Uint8 *buf, const Uint32 buflen, const char *fname, const float x, const float y)
{
static const ThingType can_be_dropped_onto[] = { THING_TRASHCAN, THING_LOGDEV, THING_LOGDEV_CAPTURE, THING_NULL };
static const ThingType can_be_dropped_onto[] = { THING_TRASHCAN, THING_LOGDEV, THING_LOGDEV_RECORDING, THING_NULL };
Thing *thing = CreateThing(THING_STREAM, x, y, 0, -1, -1, soundboard_texture, fname);
if (thing) {
SDL_Log("Adding audio stream for %s", fname ? fname : "(null)");
@@ -725,7 +737,7 @@ static Thing *CreateLogicalDeviceThing(Thing *parent, const SDL_AudioDeviceID wh
static void DeviceThing_ondrag(Thing *thing, int button, float x, float y)
{
if ((button == SDL_BUTTON_MIDDLE) && (thing->what == THING_LOGDEV_CAPTURE)) { /* drag out a new stream. This is a UX mess. :/ */
if ((button == SDL_BUTTON_MIDDLE) && (thing->what == THING_LOGDEV_RECORDING)) { /* drag out a new stream. This is a UX mess. :/ */
dragging_thing = CreateStreamThing(&thing->data.logdev.spec, NULL, 0, NULL, x, y);
if (dragging_thing) {
dragging_thing->data.stream.next_level_update = SDL_GetTicks() + 100;
@@ -733,7 +745,7 @@ static void DeviceThing_ondrag(Thing *thing, int button, float x, float y)
dragging_thing->line_connected_to = thing;
}
} else if (button == SDL_BUTTON_RIGHT) { /* drag out a new logical device. */
const SDL_AudioDeviceID which = ((thing->what == THING_LOGDEV) || (thing->what == THING_LOGDEV_CAPTURE)) ? thing->data.logdev.devid : thing->data.physdev.devid;
const SDL_AudioDeviceID which = ((thing->what == THING_LOGDEV) || (thing->what == THING_LOGDEV_RECORDING)) ? thing->data.logdev.devid : thing->data.physdev.devid;
const SDL_AudioDeviceID devid = SDL_OpenAudioDevice(which, NULL);
dragging_thing = devid ? CreateLogicalDeviceThing(thing, devid, x - (thing->rect.w / 2), y - (thing->rect.h / 2)) : NULL;
}
@@ -745,7 +757,7 @@ static void SetLogicalDeviceTitlebar(Thing *thing)
int frames = 0;
SDL_GetAudioDeviceFormat(thing->data.logdev.devid, spec, &frames);
SDL_free(thing->titlebar);
SDL_asprintf(&thing->titlebar, "Logical device #%u (%s, %s, %s, %uHz, %d frames)", (unsigned int) thing->data.logdev.devid, thing->data.logdev.iscapture ? "CAPTURE" : "OUTPUT", AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
SDL_asprintf(&thing->titlebar, "Logical device #%u (%s, %s, %s, %uHz, %d frames)", (unsigned int) thing->data.logdev.devid, thing->data.logdev.recording ? "RECORDING" : "PLAYBACK", AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
}
static void LogicalDeviceThing_ondrop(Thing *thing, int button, float x, float y)
@@ -889,15 +901,15 @@ static void LogicalDeviceThing_ondraw(Thing *thing, SDL_Renderer *renderer)
static Thing *CreateLogicalDeviceThing(Thing *parent, const SDL_AudioDeviceID which, const float x, const float y)
{
static const ThingType can_be_dropped_onto[] = { THING_TRASHCAN, THING_NULL };
Thing *physthing = ((parent->what == THING_LOGDEV) || (parent->what == THING_LOGDEV_CAPTURE)) ? parent->data.logdev.physdev : parent;
const SDL_bool iscapture = physthing->data.physdev.iscapture;
Thing *physthing = ((parent->what == THING_LOGDEV) || (parent->what == THING_LOGDEV_RECORDING)) ? parent->data.logdev.physdev : parent;
const SDL_bool recording = physthing->data.physdev.recording;
Thing *thing;
SDL_Log("Adding logical audio device %u", (unsigned int) which);
thing = CreateThing(iscapture ? THING_LOGDEV_CAPTURE : THING_LOGDEV, x, y, 5, -1, -1, logdev_texture, NULL);
thing = CreateThing(recording ? THING_LOGDEV_RECORDING : THING_LOGDEV, x, y, 5, -1, -1, logdev_texture, NULL);
if (thing) {
thing->data.logdev.devid = which;
thing->data.logdev.iscapture = iscapture;
thing->data.logdev.recording = recording;
thing->data.logdev.physdev = physthing;
thing->data.logdev.visualizer = SDL_CreateTexture(state->renderers[0], SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, VISUALIZER_WIDTH, VISUALIZER_HEIGHT);
thing->data.logdev.postmix_lock = SDL_CreateMutex();
@@ -922,12 +934,12 @@ static void SetPhysicalDeviceTitlebar(Thing *thing)
SDL_AudioSpec *spec = &thing->data.physdev.spec;
SDL_GetAudioDeviceFormat(thing->data.physdev.devid, spec, &frames);
SDL_free(thing->titlebar);
if (thing->data.physdev.devid == SDL_AUDIO_DEVICE_DEFAULT_CAPTURE) {
SDL_asprintf(&thing->titlebar, "Default system device (CAPTURE, %s, %s, %uHz, %d frames)", AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
} else if (thing->data.physdev.devid == SDL_AUDIO_DEVICE_DEFAULT_OUTPUT) {
SDL_asprintf(&thing->titlebar, "Default system device (OUTPUT, %s, %s, %uHz, %d frames)", AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
if (thing->data.physdev.devid == SDL_AUDIO_DEVICE_DEFAULT_RECORDING) {
SDL_asprintf(&thing->titlebar, "Default system device (RECORDING, %s, %s, %uHz, %d frames)", AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
} else if (thing->data.physdev.devid == SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK) {
SDL_asprintf(&thing->titlebar, "Default system device (PLAYBACK, %s, %s, %uHz, %d frames)", AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
} else {
SDL_asprintf(&thing->titlebar, "Physical device #%u (%s, \"%s\", %s, %s, %uHz, %d frames)", (unsigned int) thing->data.physdev.devid, thing->data.physdev.iscapture ? "CAPTURE" : "OUTPUT", thing->data.physdev.name, AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
SDL_asprintf(&thing->titlebar, "Physical device #%u (%s, \"%s\", %s, %s, %uHz, %d frames)", (unsigned int) thing->data.physdev.devid, thing->data.physdev.recording ? "RECORDING" : "PLAYBACK", thing->data.physdev.name, AudioFmtToString(spec->format), AudioChansToStr(spec->channels), (unsigned int) spec->freq, frames);
}
}
@@ -956,7 +968,7 @@ static void PhysicalDeviceThing_ontick(Thing *thing, Uint64 now)
}
static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL_bool iscapture)
static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL_bool recording)
{
static const ThingType can_be_dropped_onto[] = { THING_TRASHCAN, THING_NULL };
static float next_physdev_x = 0;
@@ -969,10 +981,10 @@ static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL
}
SDL_Log("Adding physical audio device %u", (unsigned int) which);
thing = CreateThing(iscapture ? THING_PHYSDEV_CAPTURE : THING_PHYSDEV, next_physdev_x, 170, 5, -1, -1, physdev_texture, NULL);
thing = CreateThing(recording ? THING_PHYSDEV_RECORDING : THING_PHYSDEV, next_physdev_x, 170, 5, -1, -1, physdev_texture, NULL);
if (thing) {
thing->data.physdev.devid = which;
thing->data.physdev.iscapture = iscapture;
thing->data.physdev.recording = recording;
thing->data.physdev.name = SDL_strdup(SDL_GetAudioDeviceName(which));
thing->ondrag = DeviceThing_ondrag;
thing->ondrop = PhysicalDeviceThing_ondrop;
@@ -982,7 +994,7 @@ static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL
SetPhysicalDeviceTitlebar(thing);
if (SDL_GetTicks() <= (app_ready_ticks + 2000)) { /* assume this is the initial batch if it happens in the first two seconds. */
RepositionRowOfThings(THING_PHYSDEV, 10.0f); /* don't rearrange them after the initial add. */
RepositionRowOfThings(THING_PHYSDEV_CAPTURE, 170.0f); /* don't rearrange them after the initial add. */
RepositionRowOfThings(THING_PHYSDEV_RECORDING, 170.0f); /* don't rearrange them after the initial add. */
next_physdev_x = 0.0f;
} else {
next_physdev_x += physdev_texture->w * 1.5f;
@@ -999,9 +1011,9 @@ static Thing *CreateTrashcanThing(void)
return CreateThing(THING_TRASHCAN, winw - trashcan_texture->w, winh - trashcan_texture->h, 10, -1, -1, trashcan_texture, "Drag things here to remove them.");
}
static Thing *CreateDefaultPhysicalDevice(const SDL_bool iscapture)
static Thing *CreateDefaultPhysicalDevice(const SDL_bool recording)
{
return CreatePhysicalDeviceThing(iscapture ? SDL_AUDIO_DEVICE_DEFAULT_CAPTURE : SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, iscapture);
return CreatePhysicalDeviceThing(recording ? SDL_AUDIO_DEVICE_DEFAULT_RECORDING : SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, recording);
}
static void TickThings(void)
@@ -1188,7 +1200,7 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
break;
case SDL_EVENT_AUDIO_DEVICE_ADDED:
CreatePhysicalDeviceThing(event->adevice.which, event->adevice.iscapture);
CreatePhysicalDeviceThing(event->adevice.which, event->adevice.recording);
break;
case SDL_EVENT_AUDIO_DEVICE_REMOVED: {
@@ -1197,10 +1209,10 @@ int SDL_AppEvent(void *appstate, const SDL_Event *event)
SDL_Log("Removing audio device %u", (unsigned int) which);
for (i = things; i; i = next) {
next = i->next;
if (((i->what == THING_PHYSDEV) || (i->what == THING_PHYSDEV_CAPTURE)) && (i->data.physdev.devid == which)) {
if (((i->what == THING_PHYSDEV) || (i->what == THING_PHYSDEV_RECORDING)) && (i->data.physdev.devid == which)) {
TrashThing(i);
next = things; /* in case we mangled the list. */
} else if (((i->what == THING_LOGDEV) || (i->what == THING_LOGDEV_CAPTURE)) && (i->data.logdev.devid == which)) {
} else if (((i->what == THING_LOGDEV) || (i->what == THING_LOGDEV_RECORDING)) && (i->data.logdev.devid == which)) {
TrashThing(i);
next = things; /* in case we mangled the list. */
}

View File

@@ -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 ? "capture" : "output";
}
static void iteration(void)
@@ -70,16 +70,16 @@ static void iteration(void)
}
} 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;
const SDL_bool recording = e.adevice.recording ? SDL_TRUE : SDL_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());
@@ -94,7 +94,7 @@ static void iteration(void)
}
} 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. */
}
}

View File

@@ -14,13 +14,13 @@
#include <SDL3/SDL_test.h>
static void
print_devices(SDL_bool iscapture)
print_devices(SDL_bool recording)
{
SDL_AudioSpec spec;
const char *typestr = ((iscapture) ? "capture" : "output");
const char *typestr = (recording ? "recording" : "playback");
int n = 0;
int frames;
SDL_AudioDeviceID *devices = iscapture ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
if (!devices) {
SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError());
@@ -94,20 +94,20 @@ int main(int argc, char **argv)
print_devices(SDL_FALSE);
print_devices(SDL_TRUE);
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, &frames) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default output): %s\n", SDL_GetError());
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &frames) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default playback): %s\n", SDL_GetError());
} else {
SDL_Log("Default Output Device:\n");
SDL_Log("Default Playback Device:\n");
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
SDL_Log("Buffer Size: %d frames\n", frames);
}
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_CAPTURE, &spec, &frames) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default capture): %s\n", SDL_GetError());
if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &spec, &frames) < 0) {
SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default recording): %s\n", SDL_GetError());
} else {
SDL_Log("Default Capture Device:\n");
SDL_Log("Default Recording Device:\n");
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);

View File

@@ -27,7 +27,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
SDL_AudioSpec outspec;
SDL_AudioSpec inspec;
SDL_AudioDeviceID device;
SDL_AudioDeviceID want_device = SDL_AUDIO_DEVICE_DEFAULT_CAPTURE;
SDL_AudioDeviceID want_device = SDL_AUDIO_DEVICE_DEFAULT_RECORDING;
const char *devname = NULL;
int i;
@@ -69,7 +69,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
return SDL_APP_SUCCESS;
}
if (SDL_CreateWindowAndRenderer("testaudiocapture", 320, 240, 0, &window, &renderer) < 0) {
if (SDL_CreateWindowAndRenderer("testaudiorecording", 320, 240, 0, &window, &renderer) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window and renderer: %s\n", SDL_GetError());
return SDL_APP_SUCCESS;
}
@@ -79,28 +79,28 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
devices = SDL_GetAudioCaptureDevices(NULL);
devices = SDL_GetAudioRecordingDevices(NULL);
for (i = 0; devices[i] != 0; i++) {
const char *name = SDL_GetAudioDeviceName(devices[i]);
SDL_Log(" Capture device #%d: '%s'\n", i, name);
SDL_Log(" Recording device #%d: '%s'\n", i, name);
if (devname && (SDL_strcmp(devname, name) == 0)) {
want_device = devices[i];
}
}
if (devname && (want_device == SDL_AUDIO_DEVICE_DEFAULT_CAPTURE)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Didn't see a capture device named '%s', using the system default instead.\n", devname);
if (devname && (want_device == SDL_AUDIO_DEVICE_DEFAULT_RECORDING)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Didn't see a recording device named '%s', using the system default instead.\n", devname);
devname = NULL;
}
/* DirectSound can fail in some instances if you open the same hardware
for both capture and output and didn't open the output end first,
for both recording and output and didn't open the output end first,
according to the docs, so if you're doing something like this, always
open your capture devices second in case you land in those bizarre
open your recording devices second in case you land in those bizarre
circumstances. */
SDL_Log("Opening default playback device...\n");
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, NULL);
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError());
return SDL_APP_FAILURE;
@@ -116,24 +116,24 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
return SDL_APP_FAILURE;
}
SDL_Log("Opening capture device %s%s%s...\n",
SDL_Log("Opening recording device %s%s%s...\n",
devname ? "'" : "",
devname ? devname : "[[default]]",
devname ? "'" : "");
device = SDL_OpenAudioDevice(want_device, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for recording: %s!\n", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &inspec, NULL);
stream_in = SDL_CreateAudioStream(&inspec, &inspec);
if (!stream_in) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for recording: %s!\n", SDL_GetError());
return SDL_APP_FAILURE;
} else if (SDL_BindAudioStream(device, stream_in) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for capture: %s!\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for recording: %s!\n", SDL_GetError());
return SDL_APP_FAILURE;
}
@@ -178,7 +178,7 @@ int SDL_AppIterate(void *appstate)
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Feed any new data we captured to the output stream. It'll play when we unpause the device. */
/* Feed any new data we recorded to the output stream. It'll play when we unpause the device. */
while (SDL_GetAudioStreamAvailable(stream_in) > 0) {
Uint8 buf[1024];
const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf));

View File

@@ -200,11 +200,11 @@ static int audio_initOpenCloseQuitAudio(void *arg)
/* Call Open (maybe multiple times) */
for (k = 0; k <= j; k++) {
result = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
result = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired);
if (k == 0) {
g_audio_id = result;
}
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d), call %d", j, k + 1);
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, desired_spec_%d), call %d", j, k + 1);
SDLTest_AssertCheck(result > 0, "Verify return value; expected: > 0, got: %d", result);
}
@@ -290,9 +290,9 @@ static int audio_pauseUnpauseAudio(void *arg)
}
/* Call Open */
g_audio_id = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &desired);
g_audio_id = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &desired);
result = g_audio_id;
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, desired_spec_%d)", j);
SDLTest_AssertPass("Call to SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, desired_spec_%d)", j);
SDLTest_AssertCheck(result > 0, "Verify return value; expected > 0 got: %d", result);
#if 0 /* !!! FIXME: maybe update this? */
@@ -356,7 +356,7 @@ static int audio_pauseUnpauseAudio(void *arg)
}
/**
* Enumerate and name available audio devices (output and capture).
* Enumerate and name available audio devices (playback and recording).
*
* \sa SDL_GetNumAudioDevices
* \sa SDL_GetAudioDeviceName
@@ -368,12 +368,12 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
const char *name;
SDL_AudioDeviceID *devices = NULL;
/* Iterate over types: t=0 output device, t=1 input/capture device */
/* Iterate over types: t=0 playback device, t=1 recording device */
for (t = 0; t < 2; t++) {
/* Get number of devices. */
devices = (t) ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
SDLTest_AssertPass("Call to SDL_GetAudio%sDevices(%i)", (t) ? "Capture" : "Output", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "capture" : "output", n);
devices = (t) ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
SDLTest_AssertPass("Call to SDL_GetAudio%sDevices(%i)", (t) ? "Recording" : "Playback", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "recording" : "playback", n);
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
/* List devices. */
@@ -1369,7 +1369,7 @@ cleanup:
/* Audio test cases */
static const SDLTest_TestCaseReference audioTest1 = {
audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED
audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (playback and recording)", TEST_ENABLED
};
static const SDLTest_TestCaseReference audioTest2 = {

View File

@@ -1171,7 +1171,7 @@ static AVCodecContext *OpenAudioStream(AVFormatContext *ic, int stream, const AV
}
SDL_AudioSpec spec = { SDL_AUDIO_F32, codecpar->ch_layout.nb_channels, codecpar->sample_rate };
audio = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &spec, NULL, NULL);
audio = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);
if (audio) {
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(audio));
} else {

View File

@@ -180,9 +180,9 @@ int main(int argc, char **argv)
filename = GetResourceFilename(filename, "sample.wav");
devices = SDL_GetAudioOutputDevices(&devcount);
devices = SDL_GetAudioPlaybackDevices(&devcount);
if (!devices) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio playback devices!");
} else {
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == -1) {

View File

@@ -178,9 +178,9 @@ int main(int argc, char *argv[])
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
devices = SDL_GetAudioOutputDevices(&devcount);
devices = SDL_GetAudioPlaybackDevices(&devcount);
if (!devices) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioOutputDevices() failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioPlaybackDevices() failed: %s\n", SDL_GetError());
devcount = 0;
}