2

I want to modulate a wave file frame-by-frame using Python. The wave file is composed of brown noise, so pseudo-random noise. The idea would be:

  1. Open the file
  2. Mmodulate it with a 40Hz modulation frequency
  3. Save the new file

I saw that there were some solutions to modulate wave volume, however I did not see solutions frame-by-frame. I tried myself, but I am confused by the wave format. How can you make the difference between the frequency and the volume? How do you load a wave file to modify its volume without impacting the tone/noise?

If you want a brown noise file to test it, you can find something here.

alex
  • 6,818
  • 9
  • 52
  • 103
Pyxel
  • 107
  • 11
  • Possible duplicate of [Change the volume of a wav file in python](https://stackoverflow.com/questions/13329617/change-the-volume-of-a-wav-file-in-python) – Maximilian Peters Mar 27 '18 at 16:47
  • @MaximilianPeters I don't think it is a duplicate. I already saw the post you're referring to, and the guy was trying to modify the volume for the complete file, and not frame by frame. Except if I missed something, that is not what I want. – Pyxel Mar 27 '18 at 20:58
  • You are right, retracted my close vote. – Maximilian Peters Mar 27 '18 at 23:20

1 Answers1

1

I don't fully understand what you are referring to by frame-by-frame. But modulating it by 40 Hz would could possibly refer to either Amplitude or Frequency modulation.

Applying a simple Amplitude Modulation would look like -

from scipy.io import wavfile
import numpy as np


F_MOD = 40  # Hz

# 1. Load wave file.
fs, x = wavfile.read('/home/audiocheck.net_brownnoise.wav') 

# 2. Applying 40 Hz amplitude modulation.
t = np.arange(0, len(x)/fs, 1/fs)
modulator = np.sin(2 * np.pi * F_MOD * t)
y = x * modulator 

# 3. Save wave file. 
wavfile.write('audiocheck.net_brownnoise_modulated.wav', fs, y)