- 操作系统:Angstrom Linux 2012.12,内核 3.8.13 在 BeagleBone Black Rev A5B 上运行。
- SDL:libsdl 1.2.0,sdl-config 1.2.15
我正在尝试使用 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
司机应该在所有情况下工作。