Skip to content
Permalink
Browse files

audio: Added SDL_AudioStream. Non-power-of-two resampling now works!

  • Loading branch information
icculus committed Jan 6, 2017
1 parent f12ab8f commit 30178a9b24edea5f8593615c7aeda5a6784ebf05

File 2 of 4 in 30178a9

@@ -54,4 +54,44 @@ void SDL_Upsample_Multiple(SDL_AudioCVT *cvt, const int channels);
void SDL_Downsample_Arbitrary(SDL_AudioCVT *cvt, const int channels);
void SDL_Downsample_Multiple(SDL_AudioCVT *cvt, const int channels);


/* SDL_AudioStream is a new audio conversion interface. It
might eventually become a public API.
The benefits vs SDL_AudioCVT:
- it can handle resampling data in chunks without generating
artifacts, when it doesn't have the complete buffer available.
- it can handle incoming data in any variable size.
- You push data as you have it, and pull it when you need it
(Note that currently this converts as data is put into the stream, so
you need to push more than a handful of bytes if you want decent
resampling. This can be changed later.)
*/

/* this is opaque to the outside world. */
typedef struct SDL_AudioStream SDL_AudioStream;

/* create a new stream */
SDL_AudioStream *SDL_NewAudioStream(const SDL_AudioFormat src_format,
const Uint8 src_channels,
const int src_rate,
const SDL_AudioFormat dst_format,
const Uint8 dst_channels,
const int dst_rate);

/* add data to be converted/resampled to the stream */
int SDL_AudioStreamPut(SDL_AudioStream *stream, const void *buf, const Uint32 len);

/* get converted/resampled data from the stream */
int SDL_AudioStreamGet(SDL_AudioStream *stream, Uint32 len, void *buf, const Uint32 buflen);

/* clear any pending data in the stream without converting it. */
void SDL_AudioStreamClear(SDL_AudioStream *stream);

/* number of converted/resampled bytes available */
int SDL_AudioStreamAvailable(SDL_AudioStream *stream);

/* dispose of a stream */
void SDL_FreeAudioStream(SDL_AudioStream *stream);

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 30178a9

Please sign in to comment.