[sdlsound] Volume control with SDL_sound

Ryan C. Gordon icculus at icculus.org
Thu Feb 8 07:28:38 EST 2007

> Is there a way to control volume level with the
> SDL_sound library?  I would like my jukebox
> application to be able to increase and decrease volume
> via buttons on the front of the jukebox.  The
> SDL_sound code I'm currently using works great as far
> as playing the files, but I don't see anything in the
> documentation for volume control.

SDL_sound only decodes audio files, it doesn't do any mixing at this 
time...whatever ends up doing the actual playback of the audio usually 
has a way to change the volume.

If you're just feeding an SDL audio callback directly with data you 
decoded through SDL_sound, you can look at playsound/playsound.c in the 
SDL_sound sources...the memcpy_with_volume() function handles this by 
modulating each sample before copying it to the output buffer that SDL 
will then send to the audio device.


More information about the sdlsound mailing list