@@ -25,11 +25,12 @@ static mp_obj_t adc_mic_read(void) {
2525 .adc_channel_list = ((uint8_t []){ADC_CHANNEL_0 }),
2626 .adc_channel_num = 1 ,
2727 .sample_rate_hz = 16000 ,
28- //.atten = ADC_ATTEN_DB_2_5,
29- .atten = ADC_ATTEN_DB_11 ,
28+ //.atten = ADC_ATTEN_DB_0, // values always 16380
29+ //.atten = ADC_ATTEN_DB_2_5, // values always 16380
30+ .atten = ADC_ATTEN_DB_6 , // values around 12500 +/- 320 (silence) or 4000 (loud talk)
31+ //.atten = ADC_ATTEN_DB_11, // values around -1130 +/- 160 (silence)
3032 };
31- ADC_MIC_DEBUG_PRINT ("Config created for channel %d, sample rate %d, atten %d\n" ,
32- ADC_CHANNEL_0 , 16000 , cfg .atten );
33+ ADC_MIC_DEBUG_PRINT ("Config created for channel %d, sample rate %d, atten %d\n" , ADC_CHANNEL_0 , 16000 , cfg .atten );
3334
3435 // ────────────────────────────────────────────────
3536 // Initialization (same as before)
@@ -65,10 +66,10 @@ static mp_obj_t adc_mic_read(void) {
6566 // ────────────────────────────────────────────────
6667 // Small reusable buffer + tracking variables
6768 // ────────────────────────────────────────────────
68- const size_t chunk_samples = 512 ;
69+ const size_t chunk_samples = 10240 ;
6970 const size_t buf_size = chunk_samples * sizeof (int16_t );
70- // int16_t *audio_buffer = heap_caps_malloc(buf_size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
71- int16_t * audio_buffer = heap_caps_malloc_prefer (buf_size , MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM , MALLOC_CAP_DEFAULT );
71+ int16_t * audio_buffer = heap_caps_malloc (buf_size , MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT );
72+ // int16_t *audio_buffer = heap_caps_thread.start_new_thread(testit, ())_malloc_prefer (buf_size, MALLOC_CAP_DEFAULT | MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT);
7273 if (audio_buffer == NULL ) {
7374 esp_codec_dev_close (dev );
7475 esp_codec_dev_delete (dev );
@@ -77,7 +78,7 @@ static mp_obj_t adc_mic_read(void) {
7778 }
7879
7980 // How many chunks to read (adjust as needed)
80- const int N = 1 ; // e.g. 50 × 512 = ~1.5 seconds @ 16 kHz
81+ const int N = 5 ; // e.g. 5 × 10240 = ~3.2 seconds @ 16 kHz
8182
8283 int16_t global_min = 32767 ;
8384 int16_t global_max = -32768 ;
@@ -111,7 +112,8 @@ static mp_obj_t adc_mic_read(void) {
111112 if (chunk < 3 ) {
112113 ADC_MIC_DEBUG_PRINT ("Chunk %d first 16 samples:\n" , chunk );
113114 for (size_t i = 0 ; i < 16 ; i ++ ) {
114- ADC_MIC_DEBUG_PRINT ("%6d " , audio_buffer [i ]);
115+ int16_t sample = audio_buffer [i ];
116+ ADC_MIC_DEBUG_PRINT ("%6d (0x%04X)" , sample , (uint16_t )sample );
115117 if ((i + 1 ) % 8 == 0 ) ADC_MIC_DEBUG_PRINT ("\n" );
116118 }
117119 ADC_MIC_DEBUG_PRINT ("\n" );
0 commit comments