This project has moved. For the latest updates, please go here.

How to increase volume of an audio file?

Nov 20, 2012 at 6:55 PM

I have a bunch of audio files that are super quiet. I would like to increase the volume on these files. I was planning on using the AudioFileReader.Volume member to increase the volume and then save the file back. Below is what I have so far:

using(AudioFileReader soft = new AudioFileReader(softAudio))
    Console.WriteLine("Current soft audio at: " + soft.Volume);

The issue is that the files volume is already at 1.0f which is the max.

Am I going at this the right way for what I want to do? Is it possible to increase the volume further if NAudio already thinks it's at max?

Nov 20, 2012 at 9:35 PM
Edited Nov 20, 2012 at 9:37 PM

the reader volume is not telling you how loud the audio is, 1.0 simply means that every sample will be left at an unchanged volume. If you set volume to 2.0, then every sample value will be doubled, (effectively a 3dB increase).

The trouble comes when you come to write them back to a file, because the samples will clip if they are outside the range +/- 1.0. The simplest approach is to hard-limit after boosting the volume. This will clip the very loudest parts of your audio file, but if they are very low level in the first place, you might be able to get a good boost without ever clipping.

The proper solution is to use dynamic range compression, which can be tricky to get your head round at first, as you need to select appropriate attack/release/threshold/ratio and make-up gain parameters for your audio. However, this is one of the most effective ways of getting a good audio level. NAudio does contain a very simple compressor, but it has not yet been reworked into the ISampleProvider interface, something I hope to do for the next version.