SDL audio streaming callback function never triggered
I'm attempting to stream audio for my C++ application which uses SDL through the mingw32 environment. From my understanding it's a fairly simple affair:
extern "C" void audioStep(void* unused, Uint8* stream, int len);
void initAudio()
{
SDL_AudioSpec* fmt;
fmt = (SDL_AudioSpec*)malloc(sizeof(SDL_AudioSpec));
fmt->freq = 22050;
fmt->format = AUDIO_S16;
fmt->channels = 1;
fmt->samples = 8192;
fmt->callback = audioStep;
fmt->userdata = NULL;
SDL_AudioSpec obFmt;
if (SDL_OpenAudio(fmt, &obFmt) < 0)
{
fprintf(stderr, "Unable to open audio: %sn", SDL_GetError());
getchar();
exit(1);
}
SDL_PauseAudio(0);
}
.
.
.
extern "C" void audioStep(void* unused, Uint8* stream, int len)
{
// Do stuff.
}
The issue I'm experiencing is that audioStep
never seems to be called. Before initAudio
is run SDL_Init
is called with SDL_INIT_EVERYTHING
. Then graphics are fully initialized ( SDL_SetVideoMode
and such) and then the audio system is initialized with the code above.
Is it possible somehow I compiled SDL without audio support? (Is there a way to check if audio is enabled or if it's using some sort of null audio device?)
I have working code in SDL.NET, so maybe this will help. I found that I had to have a Video window opened:
SdlDotNet.Graphics.Video.SetVideoMode(1, 1);
SdlDotNet.Audio.Mixer.OpenAudio(stream);
// BUG: close (or hide) it
SdlDotNet.Graphics.Video.Close();
Otherwise, it would not initialize correctly.
Why @audioStep@ should be called if you never Play a Sound? There's nothing to do.
Using SDL Sound
链接地址: http://www.djcxy.com/p/33856.html上一篇: 播放流后,音频队列无法录制音频
下一篇: SDL音频流回调功能从未触发