0
$\begingroup$

I have an audio file that I want to use as background noise. I also have other audio files that are to serve as foreground sounds and are to be placed at certain times. How can I ensure that there is no clipping when I overlay the audio files and how can I define an SNR between the foreground noise and the background noise?

$\endgroup$
1
  • $\begingroup$ The background should not be changed segmentwise. It should stay constant. $\endgroup$
    – Son Goku
    Commented Aug 5 at 12:15

1 Answer 1

0
$\begingroup$

Let's say your foreground sound is $x[n]$ and the noise signal is $y[n]$. First you need to determine of each signal.

$$P_x = <x^2[n]>, P_y = <y^2[n]> \tag{1} $$

Depending on your exact definition of SNR or the specific requirements of your application you may have to apply a frequency weighting first.

You add the signals with a specific SNR by creating a weighted sum

$$z[n] = x[n] + g\cdot y[n] \tag{2} $$

The SNR is given by the ratio of the two powers, i.e.

$$SNR = 10 \log_{10}(\frac{P_x}{g^2Py}) \tag{3} $$

Given a desired SNR you can determine g as

$$g = \sqrt{\frac{P_x}{P_y}10^{-SNR/10}} \tag{4} $$

The easiest way to avoid clipping is to scale the entire expression so that the worst case sum can't clip and so we get the final answer

$$z_{noclip}[n] = \frac{1}{1+g}x[n] + \frac{g}{1+g}y[n] \tag{5}$$

There are smarter ways of managing clipping but this is simple and safe.

$\endgroup$
2
  • $\begingroup$ Hallo Hilmar, thank you for your answer. I would like to a have a constant P_x, because i don´t want to change my original noise-sound and i would like to have several SNRs. I am not sure if the equation you gave me is able to handle this. so x should be constant. y[n] can be scaled $\endgroup$
    – Son Goku
    Commented Aug 6 at 8:21
  • $\begingroup$ I think that I found a library in Python that solves my problem: scaper.readthedocs.io/en/latest/tutorial.html $\endgroup$
    – Son Goku
    Commented Aug 6 at 12:52

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.