Skip to content

Realtime Analysis

Haotian-Shi-cyber edited this page Apr 19, 2022 · 6 revisions

Audio Input

The I2S mic would constantly read the audio data into pi, it is designed to have low-latency audio data. The hardware buffer on the sound card stories recorded samples. When the buffer is sufficiently full, it generates an interrupt. The kernel sound driver then uses direct memory access (DMA) to transfer samples to an application buffer in memory.

The driver program needs to be running in an endless loop to read the data. Since the highest frequency of the standard open string is 329.63Hz, we make the driver read 1024 samples to make sure it is enough to use FFT calculation. In that way, based on Nyquist theory the largest frequency that can be detected in our case 4kHz, but we also use low pass filter to filter out <1kHz which fits the frequencies range of standard tuning.

Our sample rate is 8000Hz, therefore Our driver completes sampling every 128ms((1024/8000)*1000 = 128ms), Average computation time for a 1024-sample FFT is less than 2ms, The time of IIR real-time filtering is extremely small and can be ignored. Therefore, For a sampling delay of 128ms, a data processing delay of less than 3ms is within the tolerable range of a real-time system

Mouse click

While the mouse could click the button on the Qt button, when it is clicked, the standard tuning pitch is changed for a specific string. this event is running in the main thread, it will not be influenced or be influenced by the data process thread.

Frequency spectrum display

When reading data into a buffer, the FFT happened and the results outputs to Qt to display the spectrum. The frequency spectrum has been low passed to avoid potential harmonics.

Our UI is refreshed at a fixed frequency of 25Hz. If this refresh rate is greater than 10Hz, the human eye will think that the spectrogram is displayed continuously Because the human eye has a visual delay of 100ms theoretically.

Performance

When the user hits the guitar string, The frequency of the maximum amplitude in the current data will be detected and the difference with the actual frequency will be calculated in real-time and displayed on the interface.

Similarly, the difference value display is refreshed at a frequency of 25Hz, which is greater than the visual delay of the human eye by 10Hz, so the display of the difference value is real-time

Clone this wiki locally