image/svg+xml image/svg+xml Create Your Own VST Plugins, Part 5: Create A Volume Control | Denise

Create Your Own VST Plugins, Part 5: Create An Audio Volume Control

– Guest blog by Audio Dev Academy

It just works, right?

Let’s take a detailed look at the inner workings of a basic audio volume control. Being a music producer, changing volume is probably so intuitive to you that you take it for granted. “It just works” right? Definitely not. Even an audio effect as simple as a volume slider needs to be implemented with care to sound natural and smooth. Let’s see how to go about this, building upon our knowledge from Blog 04 – Dealing with digital waveforms.

Volume scaling in percentage

The most naive implementation of a volume control, is to just scale the digital waveform up and down according to a percentage. Remember, in the digital realm a waveform is just a list of values between 1.0 and -1.0 that give you the amplitude of the waveform over time. So, scaling the waveform down to 50%, reduces its amplitude to half, and scaling the waveform down to 0% gives you complete silence. Now, while this naive implementation will indeed change the volume of your waveform, moving the slider from 100% to 0% will not bring the volume down gradually. Instead, moving the slider down halfway will only cause a very small volume drop, while moving it down further all the way will cause a very large volume drop. For most music producers this non-gradual volume transition doesn’t sound very natural. Moreover, moving this naive slider a set distance will have a weaker or stronger effect depending on where the slider is positioned, making it hard to work with in practice. Instead, we need a volume slider that changes the volume gradually, and in a consistent manner independent of its position.

Linear vs. logarithmic

Humans do not perceive volume in a ‘linear’ way, meaning that naively scaling the amplitude of a waveform does not produce a gradual volume change to our ears. Instead, we perceive volume in a ‘logarithmic’ way, meaning that we perceive the same volume change if the same scaling factor is applied. For example, when you move the slider from 100% to 50% you scale down the waveform amplitude by half, which produces a certain volume drop. Now, to reproduce the same volume drop, you need to bring the slider down from 50% to 25%, again scaling the waveform down by half. Then from 25% to 12.5% and so on. Therefore, to create a volume slider that produces a gradual volume change like this, you can’t do linear scaling with percentage. Instead you need to use logarithmic scaling. For the purpose of audio, logarithmic scaling is usually done with ‘decibels’. 

Volume scaling in decibels

A value in decibels expresses a scaling factor, using the prefix ‘dB’. Most volume sliders using decibel, go down from 0dB to say -96dB. This negative range can be a little confusing at first, but keeping in mind these three simple rules will make things easy:

  • A value of 0dB translates to no volume change at all
  • Every 6dB drop, scales the volume down by about half
  • Every 6dB boost, scales the volume up by about two

Hand on volume knob

A volume slider in decibel, that goes down from 0dB to -96dB, produces the same volume change when moving the slider a set distance, independent of its position. This does produce a gradual volume change, making its usage much more intuitive for music producers. Because of this, the decibel scale is used a lot in music, and converting between the amplitude of a waveform, and its volume in decibels, is done very frequently when coding audio plugins. I’ll tell you how to do that soon.

Audio Dev Academy is an exciting online environment for like-minded programmers, musicians and audio engineers who want to learn how to code audio plug-ins and virtual instruments – to be launched in 2019. In preparation for the launch, Audio Dev Academy will publish a series of blogs and ebooks about programming and the inner workings of audio plug-ins and virtual instruments. If you want to know more, find Audio Dev Academy on Facebook.


July 3, 2019 by JD Young