用到的数据结构和函数
1. SDL_Init
int SDLCALL SDL_Init(Uint32 flags)
初始化SDL,播放音频时flags为SDL_INIT_AUDIO | SDL_INIT_TIMER;
2. SDL_AudioSpec
类型 | 字段 | 备注 |
---|---|---|
int | freq | 音频采样率 |
SDL_AudioFormat | format | audio data format |
Uint8 | channels | 声道数 |
Uint8 | silence | audio buffer silence value (calculated) |
Uint16 | samples | audio buffer size in samples (power of 2) |
Uint32 | size | audio buffer size in bytes (calculated) |
SDL_AudioCallback | callback | 数据回调函数 |
void* | userdata | a pointer that is passed to callback (otherwise ignored by SDL) |
其中回调函数的格式如下所示:
void (SDLCALL * SDL_AudioCallback) (void *userdata, Uint8 * stream, int len);
其中userdata为SDL_OpenAudio参数desired中的值;stream为填充缓冲器的地址;len为缓冲区长度;
3. SDL_OpenAudio