我正在尝试使用SDL在BeagleBone Black上编写音源。但是,除非我使用dummy
驱动程序,否则SDL音频似乎不起作用。我正在使用以下代码来尝试诊断SDL_AudioOpen问题:
#include <SDL/SDL.h>
#include <SDL/SDL_audio.h>
#include <iostream>
void audio_callback (void*, Uint8*, int) { }
void ReportError (const char *where, int status) {
std::cerr << "SDL Error: " << where << " (" << status << ") "
<< SDL_GetError () << std::endl;
exit (1);
}
void ReportEnv (const char *var) {
const char *driver = getenv (var);
if (NULL == driver)
std::cerr << var << " is null" << std::endl;
else
std::cerr << var << ": " << driver << std::endl;
}
int main (int argc, char **argv)
{ ReportEnv ("SDL_AUDIODRIVER");
int ret = SDL_Init (SDL_INIT_AUDIO);
if (0 != ret)
ReportError ("SDL_Init", ret);
SDL_AudioSpec ds, obtained;
ds . freq = 44100;
ds . format = AUDIO_S16;
ds . channels = 1;
ds . samples = 1024;
ds . callback = audio_callback;
ds . userdata = NULL;
ret = SDL_OpenAudio (&ds, &obtained);
if (0 != ret)
ReportError ("SDL_OpenAudio", ret);
std::cout << "Success" << std::endl;
return 0;
}
我得到以下结果:
% SDL_AUDIODRIVER=dummy ./simple
SDL_AUDIODRIVER: dummy
Success
% SDL_AUDIODRIVER=alsa ./simple
SDL_AUDIODRIVER: alsa
SDL Error: SDL_OpenAudio (-1) No available audio device
% SDL_AUDIODRIVER=disk ./simple
SDL_AUDIODRIVER: disk
SDL Error: SDL_OpenAudio (-1) No available audio device
%
aplay
有效,因此似乎ALSA至少部分配置正确。
我错过了什么?似乎disk
驱动程序应该在所有情况下都可以工作。