How can I reduce or remove the noise created by changing the 'volume' of a sample from 16bit PCM

StackOverflow https://stackoverflow.com/questions/10402362

  •  04-06-2021
  •  | 
  •  

Question

I'm currently working on a small project where I'm loading 16bit wave files with a sample rate of 44100Hz. In normal playback the audio seems fine but as soon as I start to play with things like amplitude size to change the volume it starts giving a little bit of static noise.

What I'm doing is getting a sample from the buffer in the case of this 16bit type a short, converting this to a float in the range of -1 to 1 to start doing mixing and other effects. In this I also change the volume, when I just multiply it by 1 giving the same output its fine but as soon as I start to change the volume I hear the static noise. It happens when going over 1.0 as well as going below 1.0. And it gets worse the bigger or smaller the scale.

Anyone an idea how to reduce or remove the noise ?

Était-ce utile?

La solution 2

I found the flaw, I was abstracting different bit data types by going to their data using char*, I did not cast the usage of it to the correct datatype pointer. This means bytes were cut off when giving it data. This created the noise and volume changing bugs amongst others.

A flaw of my implementation and me not thinking about this when working with the audio data. A tip for anyone doing the same kind of thing, keep a good eye when modifying data, check which type your data is when using abstractions.

Many thanks to the guys trying to help me, the links were really interesting and it did learn me more things about audio programming.

Autres conseils

"Static", otherwise known as "clicks and pops" are the result of discontinuities in the output signal. Here is a perfect example of a discontinuity:

http://en.wikipedia.org/wiki/File:Discontinuity_jump.eps.png

If you send a buffer of audio to the system to play back, and then for the next buffer you multiply every sample by 1.1, you can create a discontinuity. For example, consider a buffer that contains a sine wave with values from [-0.5, 0.5]. You send a piece of this wave to the output device, and the last sample happens to be 0.5.

Now on your next buffer you try to adjust the volume by multiplying by 1.1. The first sample of the new buffer will be close to 0.5 (since the previous sample was 0.5). Multiply that by 1.1 and you get 0.55.

A change from one sample to the next of 0.05 will probably sound like a click or a pop. If you create enough of these, it will sound like static.

The solution is to "ramp" your volume change over the buffer. For example, if you want to apply a gain of 1.1 to a buffer of 100 samples, and the previous gain was 1.0, then you would loop over all 100 samples starting with gain 1 and smoothly increase the gain until you reach the last sample, at which point your gain should be 1.1.

If you want an example of this code look at juce::AudioSampleBuffer::applyGainRamp:

http://www.rawmaterialsoftware.com/api/classAudioSampleBuffer.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top