mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-06 06:34:35 +00:00
audio: Replace SDL_CreateAndBindAudioStream with SDL_OpenAudioDeviceStream.
This is meant to offer a simplified API for people that are either migrating directly from SDL2 with minimal effort or just want to make noise without any of the fancy new API features. Users of this API can just deal with a single SDL_AudioStream as their only object/handle into the audio subsystem. They are still allowed to open multiple devices (or open the same device multiple times), but cannot change stream bindings on logical devices opened through this function. Destroying the single audio stream will also close the logical device behind the scenes.
This commit is contained in:
parent
bd088c2f99
commit
1e775e0eef
13 changed files with 164 additions and 137 deletions
|
|
@ -193,7 +193,6 @@ int main(int argc, char *argv[])
|
|||
char *devname = SDL_GetAudioDeviceName(devices[i]);
|
||||
int j;
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioDeviceID dev;
|
||||
|
||||
SDL_Log("Testing audio device: %s\n", devname);
|
||||
SDL_free(devname);
|
||||
|
|
@ -208,24 +207,16 @@ int main(int argc, char *argv[])
|
|||
spec.freq = SAMPLE_RATE_HZ;
|
||||
spec.format = SDL_AUDIO_S16SYS;
|
||||
|
||||
dev = SDL_OpenAudioDevice(devices[i], &spec);
|
||||
if (dev == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenAudioDevice() failed: %s\n", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
|
||||
stream = SDL_CreateAndBindAudioStream(dev, &spec);
|
||||
if (stream == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateAndBindAudioStream() failed: %s\n", SDL_GetError());
|
||||
SDL_CloseAudioDevice(dev);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* These are used by the fill_buffer callback */
|
||||
total_channels = spec.channels;
|
||||
active_channel = 0;
|
||||
|
||||
SDL_SetAudioStreamGetCallback(stream, fill_buffer, NULL);
|
||||
stream = SDL_OpenAudioDeviceStream(devices[i], &spec, fill_buffer, NULL);
|
||||
if (stream == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenAudioDeviceStream() failed: %s\n", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
SDL_ResumeAudioDevice(SDL_GetAudioStreamBinding(stream));
|
||||
|
||||
for (j = 0; j < total_channels; j++) {
|
||||
const int sine_freq = is_lfe_channel(j, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
|
||||
|
|
@ -240,7 +231,6 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
SDL_CloseAudioDevice(dev);
|
||||
SDL_DestroyAudioStream(stream);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue