I'd like to create a mid-side EQ in python (allows you to edit the mid and side channels separately). Any idea of how to extract the mid and side channels from an audio file?
Asked
Active
Viewed 232 times
0
-
I'm not an audio expert, so not sure what you mean manipulating a multi-channel audio file (e.g. 6 channels .wav file, etc) or manipulating frequencies on standard mono or stereo audio files. Having a quick look this looks like a step in the right direction: https://stackoverflow.com/questions/65229296/how-to-do-histogram-equalization-based-on-audio-frequency. Hopefully librosa can handle multiple audio channels as well, otherwise I remember [using pyaudio/numpy in the past](https://stackoverflow.com/questions/30293137/pyaudio-mixing-multiple-tracks-and-channels). (librosa/numpy might suffice) – George Profenza Feb 27 '22 at 23:18
1 Answers
0
Here is a function I found in: https://github.com/sergree/matchering/
import wave
import numpy as np
def lr_to_ms(array: np.ndarray) -> (np.ndarray, np.ndarray):
array = np.copy(array)
array[:, 0] += array[:, 1]
array[:, 0] *= 0.5
mid = np.copy(array[:, 0])
array[:, 0] -= array[:, 1]
side = np.copy(array[:, 0])
return mid, side
wav_obj = wave.open('sound.wav', 'rb')
sampFreq = wav_obj.getframerate()
data = wav_obj.readframes(-1)
stereo_signal = np.frombuffer(data, np.int16)
stereo_signal.shape = -1, 2
left_signal, right_signal = stereo_signal[0], stereo_signal[1]
mid_signal, side_signal = lr_to_ms(np.array(stereo_signal, dtype=float))
The resulting mid and side signals are cast as float, you will need to change the datatype back to int16

Will Mott
- 1
- 1