[Gambas-devel] gb.sdl.sound channel volume bug

Kevin Fishburne kevinfishburne at ...590...
Sun May 12 07:28:48 CEST 2013

On 05/11/2013 02:38 PM, Benoît Minisini wrote:
> Le 04/05/2013 09:11, Kevin Fishburne a écrit :
>> When setting the Volume property (type float according to the
>> documentation) of a channel, the assignable values are of a lower
>> resolution than advertised resulting in audibly abrupt changes in
>> amplitude. Here's an example:
>> ' Audio effects.
>> Public Struct Audio_Effect  ' Structure containing one effect's data.
>>      Current As Single   ' Current amplitude.
>>      Target As Single    ' Target amplitude.
>>      Velocity As Single  ' Speed at which current amplitude is moving
>> toward target amplitude.
>>      Scale As Single     ' Audible amplitude coefficient.
>>      Chan As Channel     ' Default channel to play on.
>>      Name As String      ' Name of sample.
>>      Sample As Sound     ' Sample data (file).
>> End Struct
>> Public Environment[16] As Struct Audio_Effect ' Environmental effects.
>> ' Start wind effect.
>> Environment[7].Sample = New Sound(Render.BasePath & "/sound/Wind.wav")
>> Environment[7].Name = "Wind"
>> Environment[7].Chan = Environment[7].Sample.Play(-1)
>> Environment[7].Chan.Volume = 0
>> Environment[7].Chan.Volume = 0.01
>> Print Environment[7].Chan.Volume
>> 0
>> Environment[7].Chan.Volume = 0.02
>> Print Environment[7].Chan.Volume
>> 0.01333477219943
>> This has been plaguing me for a while but I just now zeroed in on what
>> was actually happening. I've noticed that when performing a calculation
>> if you use the wrong datatype in the wrong place it can cause overflows
>> or otherwise invalidate the equation. Maybe something like this is
>> responsible?
> The Gambas channel volume is actually different from the SDL channel volume.
> The SDL channel volume is a linear integer between 0 and 128, whereas
> the Gambas channel volume is that value converted to a logarithmic scale
> between 0.0 and 1.0.
> The logarithmic scale was chosen because it fits the way the human ear
> works: if you double the Gambas volume, the sound will be twice louder.
> Consequently, the resolution is far lower than you can expect. And the
> effect of moving the SDL volume from 1 to 2 makes the sound 69% louder,
> whereas moving it from 127 to 128 makes it 1% louder only. So you get
> abrupt changes!
> If you need changing the volume, note that you can use the fade optional
> arguments of the Play and Stop methods.
> Regards,
Interesting, thanks for the explanation. Turns out two things were 
confounding me. First the low resolution of the SDL Volume property 
(especially noticeable at the lowest ranges) and second my program 
updating the audio at only ten frames per second. Combining these 
resulted in audio "popping in" when going from zero to whatever at a 
brisk speed.

What I think I'll do is continue to update the target amplitudes at 
10fps but update the current amplitudes at a faster rate (once per frame 

Out of curiousity, is OpenAL Soft worth a damn? It sounds pretty cool 
from what I've read here: http://kcat.strangesoft.net/openal.html.

Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...590...
phone: (770) 853-6271

More information about the Devel mailing list