SDL_OpenAudio函数:
用此函数来打开音响设备。
int SDL_OpenAudio(SDL_AudioSpec* desired,
SDL_AudioSpec* obtained)
例子:
SDL_AudioSpec want, have;
SDL_memset(&want, 0, sizeof(want)); /* or SDL_zero(want) */
want.freq = 48000;
want.format = AUDIO_F32;
want.channels = 2;
want.samples = 4096;
want.callback = MyAudioCallback; /* you wrote this function elsewhere. */
if (SDL_OpenAudio(&want, &have) < 0) {
SDL_Log("Failed to open audio: %s", SDL_GetError());
} else {
if (have.format != want.format) {
SDL_Log("We didn't get Float32 audio format.");
}
SDL_PauseAudio(0); /* start audio playing. */
SDL_Delay(5000); /* let the audio callback play some sound for 5 seconds. */
SDL_CloseAudio();
}
蔡军生