0
$\begingroup$

I have a sound wave in a computer, represented as a series of values (samples). Each sample is in the range roughly between -30000 and 30000.

Say I want to decrease the loudness of the entire wave by a certain value. How can I achieve that?

It sounds trivial but for some reason I can't get it to work. Is it anything more than moving each sample closer to 0 by a certain value? (E.g., the decrease value is 100, so the sample -25000 becomes -24900, etc.). Am I missing something?

Also, what about samples that their distance from 0 is less than the decrease value?

$\endgroup$
1
  • $\begingroup$ I might not be understanding the question, but when you say each sample is in the range between -30000 and 30000, what quantity is that range? Is that some index assigned to a particular sample? Is that the sample frequency? Amplitude? $\endgroup$
    – Involute
    Mar 28, 2015 at 0:19

1 Answer 1

2
$\begingroup$

Multiply your values my some number less than 1.0. That will "move all the values closer to zero". But remember that the human hearing system is logarithmic, not linear. And "volume" is a psycho-physical phenomenon that is hard to quantify, and varies from person to person.

Reducing your values by a factor of two will not reduce the perceived volume by a factor of two. Rule of thumb: it takes a reduction of 6 - 10 dB in intensity to reduce perceived volume by a factor of two. 6 dB is a factor of 4, 10 dB is a factor of 10. Let's take the high end: 10 dB. To reduce the loudness by a factor of 2, you might have to multiply your values by 0.1. To reduce the loudness by a factor of 4, you might have to multiply by 0.01.

If you are not aware of these things, you might not be reducing your values nearly enough. Experiment my multiplying your values by factors in the 0.1 - 0.2 ballpark. Don't be afraid to to use much smaller values.

update after comment

Eliminating distortion: It depends on the system you use to realize your sound wave (your audio system), the nature of the sound wave (does it have a lot of sharp peaks) and your tolerance for distortion. Eliminating all distortion is impossible, as no reproduction system is perfect. You can eliminate clipping/saturation by reducing total volume, but if there is any small peak at all your volume might be very very low. Allowing a small, inaudible amount of distortion would help. Sometimes dynamic compression is used to reduce audible distortion while keeping the volume reasonably high.

Harmonic distortion occurs before the primary effects of clipping are audible. Can you tolerate that?

Reproduction systems always change the amplitude and phase of each frequency component. That's an unavoidable distortion. If you think you want to avoid that, you are sunk.

The fact that you have a digitized version of the waveform is a distortion.

We really need more context. What are you trying to do?

$\endgroup$
2
  • $\begingroup$ I see. Let me expand the question further. What I'm trying to do is after generating a sound wave (more accurately a series of connected waves), eliminate any potential distortion when this is played after writing to a file. So I find the loudest sample, and if it exceeds a certain amplitude, I decrease the whole wave. The question is: what would be a good way to decide the factor of decrease, based on the loudest sample? $\endgroup$
    – Aviv Cohn
    Mar 28, 2015 at 9:59
  • $\begingroup$ Also, would you take a different approach to keeping the whole wave under a certain volume? $\endgroup$
    – Aviv Cohn
    Mar 28, 2015 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.