I'm trying to use my RPi4 as a real-time audio processing device to detect when a certain acoustic frequency is present in an environment. The pi performs real-time fft on an audio stream from a USB microphone. Developing the code on the raspberry pi using a monitor, I was encouraged because it seemed to work well. But I noticed that when I take the pi off my desk and try and deploy it headless in the real world, I get a lot of background noise and frequencies, so much so that I cannot detect the frequency of interest among the noise. Basically, as soon as I disconnect the monitor's HDMI cable from the pi, many background frequencies instantly appear on my frequency graph: (I was able to see these graphs using VNC viewer while the pi was headless)
As soon as I reattach the monitor to the pi, the frequencies die down to nothing. I notice that when the monitor is connected, the audio input channel changes also:
In my fft code I account for this change by automatically adopting the new input channel for the USB audio, so I am certain that the background noise is not caused by accidentally switching to a new microphone with more background noise when I remove the HDMI connection. In other words, the same mic on a different input channel now has much more background noise. What is causing this, and how can I correct for it? Is it a problem with the input channel and can I force the pi to use the same input channel while running headless? Thanks.