espressif / esp-adf

Espressif Audio Development Framework
Other
1.5k stars 670 forks source link

Noise peaks in repeated recording (AUD-5065) #1117

Open cypamigon opened 7 months ago

cypamigon commented 7 months ago

Environment

Problem Description

When running consecutive recording task of AUX IN into an SDCard, some of them have a strange noise (~1/25 of the records)

The noisy measurements looks like this :

recordNoisy

As you can see there is some peaks in the record. They seem to appear mostly when the real samples values should be near '0'. Indeed, on the picture below the noise peaks are more present when the samples are mostly near zeros :

recordNoisy2

I've looked at the samples values at different stage of the pipeline and they seem to be already corrupted at the first element (i2s_stream_reader) input. To achieve this, I'm reading data in the input buffer and I'm logging the sample value if she is above 32000 or under -32000 (data are on 16 bits). Here is the code implemented to achieved it in i2s_read() (in file i2s.c) :

        //DEBUG
        my_data_ptr = (int16_t *) p_i2s[i2s_num]->rx->curr_ptr;
        bytes_can_read = p_i2s[i2s_num]->rx->buf_size - p_i2s[i2s_num]->rx->rw_pos;
        for(int i=0; i<bytes_can_read/2; i++)
        {
            if(*my_data_ptr > 32000 || *my_data_ptr < -32000 )
            {
                ESP_LOGI(TAG,"---------------------------------- DATA VALUE : %d ----------------------------------", *my_data_ptr);
            }
            my_data_ptr++;
        }
        //END DEBUG

Expected Behavior

We should observe consistancy in audio quality between repeated records.

Actual Behavior

Some of the records are noisy (~1/25 of the records)

Steps to Reproduce

  1. Import the example pipeline_recording_to_sdcard.
  2. Change main.c with the code provided below.
  3. Build and flash the project.
  4. Open a terminal to view logs.
  5. Once all records are done, mount the SDCard on your computer and check for noisy one.

Code to Reproduce This Issue

Here is the main.c.

cypamigon commented 7 months ago

Here is an additionnal screenshot on a sine wave recorded at 48 kHz :

recordNoisy3

It clearly confirm a correlation between the distorted samples and their normal value : when samples should be at 0, they are alternatively set at almost full range and min range. This appears only in one channel. Here are the normalized sample values for the period of a sine wave (I have highlighted aberrant values):

0.38852 0.38791 0.38861 0.38959 0.38782 0.38971 0.38553 0.38895 0.38220 0.38654 0.37665 0.38312 0.37106 0.37775 0.36340 0.37198 0.35519 0.36435 0.34515 0.35623 0.33463 0.34601 0.32266 0.33582 0.30978 0.32361 0.29562 0.31055 0.28064 0.29626 0.26489 0.28137 0.24841 0.26569 0.23035 0.24902 0.21231 0.23096 0.19290 0.21295 0.17380 0.19333 0.15332 0.17419 0.13281 0.15378 0.11157 0.13315 0.09024 0.11182 0.06821 0.09045 0.04620 0.06839 0.02457 0.04630 0.00211 0.02460 0.97922 0.00208 -0.04245 -0.02081 -0.06393 -0.04254 -0.08624 -0.06412 -0.10733 -0.08655 -0.12836 -0.10773 -0.14896 -0.12869 -0.16962 -0.14929 -0.18848 -0.17010 -0.20853 -0.18900 -0.22586 -0.20901 -0.24435 -0.22665 -0.26056 -0.24500 -0.27621 -0.26123 -0.29117 -0.27698 -0.30511 -0.29196 -0.31793 -0.30603 -0.32974 -0.31891 -0.34085 -0.33063 -0.35016 -0.34183 -0.35840 -0.35104 -0.36566 -0.35925 -0.37170 -0.36676 -0.37631 -0.37271 -0.38010 -0.37744 -0.38187 -0.38110 -0.38293 -0.38300 -0.38312 -0.38403 -0.38092 -0.38425 -0.37823 -0.38187 -0.37411 -0.37943 -0.36871 -0.37518 -0.36237 -0.36978 -0.35376 -0.36353 -0.34534 -0.35477 -0.33450 -0.34622 -0.32394 -0.33551 -0.31140 -0.32489 -0.29779 -0.31232 -0.28348 -0.29855 -0.26788 -0.28421 -0.25162 -0.26862 -0.23502 -0.25226 -0.21713 -0.23569 -0.19824 -0.21771 -0.17886 -0.19885 -0.15900 -0.17944 -0.13937 -0.15942 -0.11993 -0.13983 -0.09702 -0.12030 -0.07462 -0.09735 -0.05334 -0.07468 -0.03076 -0.05347 -0.00854 -0.03082 -0.98633 -0.00851 0.03543 0.01358 0.05780 0.03552 0.07959 0.05783 0.10147 0.07977 0.12228 0.10153 0.14319 0.12253 0.16452 0.14355 0.18381 0.16495 0.20316 0.18417 0.22198 0.20358 0.23956 0.22253 0.25638 0.24020 0.27255 0.25711 0.28909 0.27325 0.30319 0.28986 0.31668 0.30411 0.32886 0.31741 0.34015 0.32965 0.35059 0.34109 0.35944 0.35135 0.36786 0.36041 0.37427 0.36871 0.37921 0.37524 0.38351 0.38025 0.38657 0.38458 0.38818 0.38766

cypamigon commented 6 months ago

Tried with lastest esp-adf and esp-idf and I'm still facing the same issue. Some help would be highly appreciated.