flothesof / pyqtgraph-spectrographer

A pyqtgraph based spectrogram app using pyaudio.
MIT License
34 stars 7 forks source link

What changes are needed for 32Bit Audio? #4

Open S4WRXTTCS opened 4 years ago

S4WRXTTCS commented 4 years ago

I verified that this program works great on a Jetson Nano with a USB Microphone that has 16bit depth. But, I'm having issues getting it to work with an I2S MEMS Microphone (SPH0645LM4H) that has a bit depth of 24bits (where you use 32bits transfers).

I successfully tested recording wave files with pyaudio with this microphone as long as I use pyaudio.paInt32 as the sample format. But, I can't figure out everything I need to change to get it work with the pyqtgraph-spectrographer.

I tried changing lines 21, and 33 of the microphone.py file, but then I didn't get anything on the waveform or FFT plot.

flothesof commented 4 years ago

Hi there. I think changing lines 21 and 33 should in principle be sufficient. To check whether the data that gets recorded is correct, you could run microphone.py as a standalone (with changed lines) and look at the output, which should be a matplotlib plot of the recorded data (if name == 'main' part in microphone.py). Does that help?

flothesof commented 4 years ago

I can confirm changing the two lines works for me when I run main.py image

S4WRXTTCS commented 4 years ago

On my Jetson Nano if I use the USB attached Microphone (shows up on input_device_index 11 on the pyaudio interface) everything works with the default 16bit settings. On that device if I change both of those lines to their 32bit equivalent then the waveform view has all kinds of vertical lines through it, and the FFT plot is way up.

For now I'm going to shelve trying to get it to work with the 32bit audio, and just try to get the I2S Microphone to work with this app. If I use the I2S Microphone (shows up on input_device_index 1) with the default 16bit values then it ALMOST works. I say almost because under the waveform window the amplitude line is slightly under 0 (like -2) where the USB Microphone is exactly at 0. When its sitting below 0 the FFT plot is window is blank , and the waterfall doesn't travel. If I purposely create a lot of noise then the FFT plot shows something, but only for that brief time.

I've attached some recording comparisons between the two sources. Where output1.wav is the I2S Microphone, and output11.wav is the USB attached Microphone. The recording is of a 2Khz tone that turns on a little after the recording starts. The Test6.py is a simply python app to record the audio (with the same settings that I use in your app).

I2S(dev1)vsUSB(dev11).zip