Wiki Page Content

Differences between revisions 24 and 25
Revision 24 as of 2013-08-08 04:42:23
Size: 3225
Editor: RyanGordon
Comment: Example code
Revision 25 as of 2015-01-02 21:21:14
Size: 3225
Comment: Added missing ().
Deletions are marked like this. Additions are marked like this.
Line 21: Line 21:
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Line 23: Line 23:
Unspecified bits are always zero, but may be used in later versions of SDL. There are macros to query the specified bits.  Unspecified bits are always zero, but may be used in later versions of SDL. There are macros to query the specified bits.
Line 75: Line 75:
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. 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_AudioFormat

An enumeration of audio formats.

Values

Bit Meanings

These are what the 16 bits in SDL_AudioFormat currently mean:

 +----------------------sample is signed if set
 |
 |        +----------sample is bigendian if set
 |        |
 |        |           +--sample is float if set
 |        |           |
 |        |           |  +--sample bit size---+
 |        |           |  |                    |
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.

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

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

Code Examples

extern SDL_AudioFormat fmt;
if (SDL_AUDIO_ISFLOAT(fmt)) {
    printf("floating point data\n");
} else {
    printf("integer data\n");
}
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.


CategoryEnum, CategoryAudio

None: SDL_AudioFormat (last edited 2015-01-02 21:21:14 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit