Audio Processing with Rsp4

Thread Starter

Khisraw

Joined Nov 14, 2020
56
Hi,
I am working on an audio processing project using Rsp4. It involves using two mics both connected via USB ports.
The program works however there is far too much noise that you can barely hear. It mic2 it like a machine is ON. I am new to audio processing so I assume I need to do some filtering but I am not sure if this much noise is normal. My codes are below.

Any tips or guidance is most welcome.


Code:
import pyaudio

import sys
import time

from gpiozero import LED, Button
import time

chunk = 4096
FRAMES_PER_BUFFER = 3200
FORMAT = pyaudio.paInt16
MIC1 = 1
MIC2 = 2
RATE = 44100



led = LED(17)
button = Button(27)

p = pyaudio.PyAudio()

stream1 = p.open(format = FORMAT,
channels = MIC1,
rate = RATE,
input = True,
output = True,
frames_per_buffer = FRAMES_PER_BUFFER)

stream2 = p.open(format = FORMAT,
channels = MIC1,
rate = RATE,
input = True,
output = True,
frames_per_buffer = FRAMES_PER_BUFFER)


player = p.open(format = FORMAT,
channels = MIC1,
rate = RATE,
input = True,
output = True,
frames_per_buffer = FRAMES_PER_BUFFER
)
player2 = p.open(format = FORMAT,
channels = MIC2,
rate = RATE,
input = True,
output = True,
frames_per_buffer = FRAMES_PER_BUFFER
)
#stream started
started = False
while True:
if button.is_pressed:
if not started:
stream2.stop_stream()
stream1.start_stream()
started = True


frames = []
data = stream1.read(FRAMES_PER_BUFFER)
frames.append(data)
player.write(data,FRAMES_PER_BUFFER)
print('MIC1 is running')


else:
if started:

stream1.stop_stream()
started = False
stream2.start_stream()

frames2 = []
data2 = stream2.read(FRAMES_PER_BUFFER)
frames2.append(data2)
player2.write(data2,FRAMES_PER_BUFFER)
print('MIC2 is running')
 
Last edited by a moderator:

Audioguru again

Joined Oct 21, 2019
6,673
You said there is too much noise. Please describe the noise:
1) Low frequency hum.
2) High frequency hiss.
3) Mid frequency tones or high frequency beeping.
4) Acoustical feedback howling because the mic hears a speaker and a sound goes around and around.
5) Cars racing down the street with their mufflers removed.
6) Nearby airport.
7) Nearby kids school or playground.
 

Papabravo

Joined Feb 24, 2006
21,159
Rule #1: you must have an analog front end filter before you attempt to do ANY digital processing.

The reason for this is that depending on the frequency content of the input, high frequencies will be mapped into the range of frequencies determined by your sampling rate.
 

Thread Starter

Khisraw

Joined Nov 14, 2020
56
Rule #1: you must have an analog front end filter before you attempt to do ANY digital processing.

The reason for this is that depending on the frequency content of the input, high frequencies will be mapped into the range of frequencies determined by your sampling rate.
Thanks for the response but I am using off an shelf Mic module. It is out of a box solution so would I still need an analog filter?
 

Papabravo

Joined Feb 24, 2006
21,159
Thanks for the response but I am using off an shelf Mic module. It is out of a box solution so would I still need an analog filter?
That's a good question. A Mic module might have an analog filter which would be great, but you need to verify that. The fact remains that if your input from the Mic module contains higher frequency components than you expect it will cause problems in the digital processing because those frequencies will show up as lower frequencies in the processed data. This is also dependent on the sampling rate that you pick. The minimum sampling rate should be twice the highest frequency that you expect in the input.

For example, if the highest frequency you expect is 12 kHz, then your sampling frequency should be at least 24 kHz.
 
Top