FFmpeg SDL_AudioSpec 详解
来源:互联网 发布:淘宝为什么没有比价了 编辑:程序博客网 时间:2024/06/08 08:18
http://wiki.libsdl.org/SDL_AudioSpec
SDL_AudioSpec
A structure that contains the audio output format. It also contains a callback that is called when the audio device needs more data.
Contents
- SDL_AudioSpec
- Data Fields
- Code Examples
- Remarks
- Related Functions
Data Fields
int
freq
DSP frequency (samples per second); see Remarks for details
SDL_AudioFormat
format
audio data format; see Remarks for details
Uint8
channels
number of separate sound channels: see Remarks for details
Uint8
silence
audio buffer silence value (calculated)
Uint16
samples
audio buffer size in samples (power of 2); see Remarks for details
Uint32
size
audio buffer size in bytes (calculated)
SDL_AudioCallback
callback
the function to call when the audio device needs more data; see Remarks for details
void*
userdata
a pointer that is passed to callback (otherwise ignored by SDL)
Code Examples
SDL_AudioSpec want, have;SDL_AudioDeviceID dev;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.dev = SDL_OpenAudioDevice(NULL, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE);
Remarks
This structure is used by SDL_OpenAudioDevice() and SDL_LoadWAV(). While all fields are used by SDL_OpenAudioDevice(), onlyfreq, format, channels, and samples are used by SDL_LoadWAV().
freq specifies the number of sample frames sent to the sound device per second. Common values are 11025, 22050, 44100 and 48000. Larger values produce cleaner audio, in much the same way that larger resolutions produce cleaner graphics.
format specifies the size and type of each sample element and may be one of the following:
8-bit support
AUDIO_S8
signed 8-bit samples
AUDIO_U8
unsigned 8-bit samples
16-bit support
AUDIO_S16LSB
signed 16-bit samples in little-endian byte order
AUDIO_S16MSB
signed 16-bit samples in big-endian byte order
AUDIO_S16SYS
signed 16-bit samples in native byte order
AUDIO_S16
AUDIO_S16LSB
AUDIO_U16LSB
unsigned 16-bit samples in little-endian byte order
AUDIO_U16MSB
unsigned 16-bit samples in big-endian byte order
AUDIO_U16SYS
unsigned 16-bit samples in native byte order
AUDIO_U16
AUDIO_U16LSB
32-bit support (new to SDL 2.0)
AUDIO_S32LSB
32-bit integer samples in little-endian byte order
AUDIO_S32MSB
32-bit integer samples in big-endian byte order
AUDIO_S32SYS
32-bit integer samples in native byte order
AUDIO_S32
AUDIO_S32LSB
float support (new to SDL 2.0)
AUDIO_F32LSB
32-bit floating point samples in little-endian byte order
AUDIO_F32MSB
32-bit floating point samples in big-endian byte order
AUDIO_F32SYS
32-bit floating point samples in native byte order
AUDIO_F32
AUDIO_F32LSB
See SDL_AudioFormat for more info.
channels specifies the number of output channels. As of SDL 2.0, supported values are 1 (mono), 2 (stereo), 4 (quad), and 6 (5.1).
samples specifies a unit of audio data. When used with SDL_OpenAudioDevice() this refers to the size of the audio buffer in sample frames. A sample frame is a chunk of audio data of the size specified in format multiplied by the number of channels. When theSDL_AudioSpec is used with SDL_LoadWAV() samples is set to 4096. This field's value must be a power of two.
The values silence and size are calculated by SDL_OpenAudioDevice().
Channel data is interleaved. Stereo samples are stored in left/right ordering. Quad is stored in front-left/front-right/rear-left/rear-right order. 5.1 is stored in front-left/front-right/center/low-freq/rear-left/rear-right ordering ("low-freq" is the ".1" speaker).
The function prototype for callback is:
void SDL_AudioCallback(void* userdata, Uint8* stream, int len)
- where its parameters are:
userdata
an application-specific parameter saved in the SDL_AudioSpec structure's userdata field
stream
a pointer to the audio data buffer filled in by SDL_AudioCallback()
len
the length of that buffer in bytes
Once the callback returns, the buffer will no longer be valid. Stereo samples are stored in a LRLRLR ordering.
The callback must completely initialize the buffer; as of SDL 2.0, this buffer is not initialized before the callback is called. If there is nothing to play, the callback should fill the buffer with silence.
With SDL >= 2.0.4 you can choose to avoid callbacks and use SDL_QueueAudio() instead, if you like. Just open your audio device with a NULL callback.
Related Functions
SDL_LoadWAV
SDL_LoadWAV_RW
SDL_OpenAudioDevice
CategoryStruct, CategoryAudio
- FFmpeg SDL_AudioSpec 详解
- SDL_AudioSpec结构体
- ffmpeg详解
- ffmpeg详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- FFMPEG详解
- ffmpeg 详解
- ffmpeg详解
- ffmpeg 详解
- (四)项目结构介绍
- Reactor
- Java命名规范
- hdoj1010 Tempter of the Bone(迷宫问题dfs,奇偶剪枝)
- python数据挖掘包Sklearn
- FFmpeg SDL_AudioSpec 详解
- 照片处理文章
- U盘装系统
- Kotlin是什么
- 第十五天1
- 用xml.dom解析xml文件
- 2017-05-18知识分享
- [译] Perceptual Losses for Real-Time Style Transfer and Super-Resolution(Stanford University)
- RecyclerView的特简单使用--狸菇凉_