[SDL] Audio Ouput with SDl
Ryan C. Gordon
icculus at clutteredmind.org
Thu Aug 15 08:58:01 PDT 2002
> I am not a very experienced programmer so could you please keep all
> instructions simple. I have attached my code to this email if somebody
> could look at it and tell me how to fix it I would really appreciate it.
Without looking at the rest of your code:
void fill_audio(void *udata, Uint8 *stream, int len)
/* Only play if we have data left */
if ( audio_len == 0 )
/* Mix as much data as possible */
len = ( len > audio_len ? audio_len : len );
//SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
audio_pos += len;
audio_len -= len;
...you aren't doing anything in the audio callback.
You need to write (len) bytes to the buffer pointed to by (stream) every
time this function is called.
Also, don't mix against (stream) with SDL_MixAudio, since (I think) the
data in the stream is undefined until you put something there. Use
memcpy() instead. Write silence to the rest of the stream if you don't
have enough data for it.
(This is like the fourth time I've answer this question in two days...does
someone have a good tutorial on SDL audio coding?)
More information about the SDL