SDL_AudioFormat

An enumeration of audio formats.
音频格式的枚举值。

Values 值

Bit Meanings 位释意

These are what the 16 bits in SDL_AudioFormat currently mean:
以下是 SDL_AudioFormat 中16位值的意义:

  1. +----------------------sample is signed if set(有符号)
  2. |
  3. | +----------sample is bigendian if set(大端存储)
  4. | |
  5. | | +--sample is float if set(浮点数)
  6. | | |
  7. | | | +--sample bit size---+(采样的位大小)
  8. | | | | |
  9. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

Unspecified bits are always zero, but may be used in later versions of SDL. There are macros to query the specified bits.
没有用到的位总是 0, 但在 SDL 未来的版本中可能会用到。

Audio Format Macros 音频格式宏

SDL_AUDIO_MASK_BITSIZE(0xFF)
SDL_AUDIO_MASK_DATATYPE(1<<8)
SDL_AUDIO_MASK_ENDIAN(1<<12)
SDL_AUDIO_MASK_SIGNED(1<<15)
SDL_AUDIO_BITSIZE(x)(x & SDL_AUDIO_MASK_BITSIZE)
SDL_AUDIO_ISFLOAT(x)(x & SDL_AUDIO_MASK_DATATYPE)
SDL_AUDIO_ISBIGENDIAN(x)(x & SDL_AUDIO_MASK_ENDIAN)
SDL_AUDIO_ISSIGNED(x)(x & SDL_AUDIO_MASK_SIGNED)
SDL_AUDIO_ISINT(x)(!SDL_AUDIO_ISFLOAT(x))
SDL_AUDIO_ISLITTLEENDIAN(x)(!SDL_AUDIO_ISBIGENDIAN(x))
SDL_AUDIO_ISUNSIGNED(x)(!SDL_AUDIO_ISSIGNED(x))

Audio Format Values 音频格式值

8-bit support 8位支持
AUDIO_S8signed 8-bit samples 有符号8位采样
AUDIO_U8unsigned 8-bit samples 无符号8位采样
16-bit support 16位支持
AUDIO_S16LSBsigned 16-bit samples in little-endian byte order 小端有符号16位
AUDIO_S16MSBsigned 16-bit samples in big-endian byte order 大端有符号16位
AUDIO_S16SYSsigned 16-bit samples in native byte order 本机字节顺序有符号16位
AUDIO_S16AUDIO_S16LSB
AUDIO_U16LSBunsigned 16-bit samples in little-endian byte order 小端无符号16位
AUDIO_U16MSBunsigned 16-bit samples in big-endian byte order 大端无符号16位
AUDIO_U16SYSunsigned 16-bit samples in native byte order 本机字节顺序无符号16位
AUDIO_U16AUDIO_U16LSB
32-bit support (new to SDL 2.0) 32位支持(SDL2新增)
AUDIO_S32LSB32-bit integer samples in little-endian byte order 小端32位整型
AUDIO_S32MSB32-bit integer samples in big-endian byte order 大端32位整型
AUDIO_S32SYS32-bit integer samples in native byte order 本机字节顺序32位整型
AUDIO_S32AUDIO_S32LSB
float support (new to SDL 2.0) 浮点支持(SDL2新增)
AUDIO_F32LSB32-bit floating point samples in little-endian byte order 小端32位浮点
AUDIO_F32MSB32-bit floating point samples in big-endian byte order 大端32位浮点
AUDIO_F32SYS32-bit floating point samples in native byte order 本机字节顺序32位浮点
AUDIO_F32AUDIO_F32LSB

Code Examples

  1. extern SDL_AudioFormat fmt;
  2. if (SDL_AUDIO_ISFLOAT(fmt)) {
  3. printf("floating point data\n");
  4. } else {
  5. printf("integer data\n");
  6. }
  7. printf("%d bits per sample\n", (int) SDL_AUDIO_BITSIZE(fmt));

Remarks 注释

Be careful about assuming details of a data format. If you only check SDL_AUDIO_ISFLOAT(), you might be surprised to find a later version of SDL adds Float64 support when you expected there to be only 32-bit data, for example.
对数据格式的详细信息要小心判断。例如你只检查 SDL_AUDIO_ISFLOAT(), 你可能会发现 SDL 在后来的版本中已经支持了64位浮点数而不是只有32位的数据。

Related Structures 相关结构体

SDL_AudioCVT
SDL_AudioSpec

Related Functions 相关函数

SDL_BuildAudioCVT
SDL_MixAudioFormat


@lxfly2000