Wiki Page Content

Differences between revisions 15 and 16
Revision 15 as of 2011-12-05 22:58:14
Size: 3083
Editor: SheenaSmith
Comment: some sans-Sam editing
Revision 16 as of 2013-08-08 01:54:06
Size: 3445
Editor: RyanGordon
Comment: Rewritten
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
||<tablewidth="100%" style="color: #FF0000;" :> DRAFT||
Line 25: Line 24:
You can add your code example here // Change 1024 stereo sample frames at 48000Hz from Float32 to Int16.
SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_F32, 2, 48000, AUDIO_S16, 2, 48000);
SDL_assert(cvt.needed); // obviously, this one is always needed.
cvt.len = 1024 * 2 * 4; // 1024 stereo float32 sample frames.
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
// read your float32 data into cvt.buf here.
SDL_ConvertAudio(cvt);
// cvt.buf has cvt.len_cvt bytes of converted data now.
Line 29: Line 36:
*<<BR>>The [[SDL_AudioCVT]] is used to convert audio data between different formats. An [[SDL_AudioCVT]] structure is created with the [[SDL_BuildAudioCVT]]() function, while the actual conversion is done by the [[SDL_ConvertAudio]]() function. The [[SDL_AudioCVT]] structure is used to convert audio data between different formats. An [[SDL_AudioCVT]] structure is initialized with the [[SDL_BuildAudioCVT]]() function, while the actual conversion is done by the [[SDL_ConvertAudio]]() function, once the application has set up appropriately-sized buffers between these two function calls.
Line 31: Line 38:
Many of the fields in the [[SDL_AudioCVT]] structure should be considered private and their function will not be discussed here.

<<Anchor(buf)>>'''buf''' points to the audio data that will be used in the conversion. It is both the source and the destination, which means the converted audio data overwrites the original data. It also means that the converted data may be larger than the original data (if you were converting from 8-bit to 16-bit, for instance), so you must ensure '''buf''' is large enough. See '''len_mult''' below for more info.
<<Anchor(buf)>>'''buf''' points to the audio data that will be used in the conversion. It is both the source and the destination, which means the converted audio data overwrites the original data. It also means that the converted data may be larger than the original data (if you were converting from 8-bit to 16-bit, for instance), so you must ensure '''buf''' is large enough for any stage of the conversion, regardless of the final converted data's size. See '''len_mult''' below for more info.
Line 37: Line 42:
<<Anchor(len_mult)>>'''len_mult''' ^is the length multiplier for determining the size of the converted data.^ As explained above, the audio buffer needs to be big enough to store the converted data, which may be bigger than the original audio data. The ^size^ ,,length,, of '''buf''' should be '''len'''*'''len_mult'''. <<Anchor(len_mult)>>'''len_mult''' is the length multiplier for determining the size of the converted data. The audio buffer may need to be larger than either the original data or the converted data.. The allocated size of '''buf''' should be '''len'''*'''len_mult'''.
Line 39: Line 44:
<<Anchor(len_ratio)>>'''len_ratio''' ^is the length ratio of the converted data to the original data.^ When you have finished converting your audio data, you need to know how much of your audio buffer is valid. '''len'''*'''len_ratio''' is the size of the converted audio data in bytes. This is very similar to '''len_mult''', however when the convert^ed^ audio data is shorter than the original, '''len_mult''' would be 1. '''len_ratio''', on the other hand, would be a fractional number between 0 and 1. <<BR>>* <<Anchor(len_ratio)>>'''len_ratio''' is the length ratio of the converted data to the original data. When you have finished converting your audio data, you need to know how much of your audio buffer is valid. '''len'''*'''len_ratio''' is the size of the converted audio data in bytes. This is very similar to '''len_mult''', however when the converted audio data is shorter than the original, '''len_mult''' would be 1. '''len_ratio''', on the other hand, would be a fractional number between 0 and 1.

SDL_AudioCVT

A structure that contains audio data conversion information.

Data Fields

int

needed

set to 1 if conversion possible

SDL_AudioFormat

src_format

source audio format

SDL_AudioFormat

dst_format

target audio format

double

rate_incr

rate conversion increment

Uint8*

buf

the buffer to hold entire audio data; see Remarks for details

int

len

length of original audio buffer; see Remarks for details

int

len_cvt

length of converted audio buffer

int

len_mult

buf must be len*len_mult big; see Remarks for details

double

len_ratio

given len, final size is len*len_ratio; see Remarks for details

SDL_AudioFilter[10]

filters

filter list (internal use)

int

filter_index

current audio conversion function (internal use)

Code Examples

// Change 1024 stereo sample frames at 48000Hz from Float32 to Int16.
SDL_AudioCVT cvt;
SDL_BuildAudioCVT(&cvt, AUDIO_F32, 2, 48000, AUDIO_S16, 2, 48000);
SDL_assert(cvt.needed); // obviously, this one is always needed.
cvt.len = 1024 * 2 * 4;  // 1024 stereo float32 sample frames.
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
// read your float32 data into cvt.buf here.
SDL_ConvertAudio(cvt);
// cvt.buf has cvt.len_cvt bytes of converted data now.

Remarks

The SDL_AudioCVT structure is used to convert audio data between different formats. An SDL_AudioCVT structure is initialized with the SDL_BuildAudioCVT() function, while the actual conversion is done by the SDL_ConvertAudio() function, once the application has set up appropriately-sized buffers between these two function calls.

buf points to the audio data that will be used in the conversion. It is both the source and the destination, which means the converted audio data overwrites the original data. It also means that the converted data may be larger than the original data (if you were converting from 8-bit to 16-bit, for instance), so you must ensure buf is large enough for any stage of the conversion, regardless of the final converted data's size. See len_mult below for more info.

len is the length of the original audio data in bytes.

len_mult is the length multiplier for determining the size of the converted data. The audio buffer may need to be larger than either the original data or the converted data.. The allocated size of buf should be len*len_mult.

len_ratio is the length ratio of the converted data to the original data. When you have finished converting your audio data, you need to know how much of your audio buffer is valid. len*len_ratio is the size of the converted audio data in bytes. This is very similar to len_mult, however when the converted audio data is shorter than the original, len_mult would be 1. len_ratio, on the other hand, would be a fractional number between 0 and 1.


CategoryStruct, CategoryAudio

None: SDL_AudioCVT (last edited 2015-01-02 21:38:51 by PhilippWiesemann)

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