Skip to content

Stuck reading Led_dB #6

Open
Open
@jnrivra

Description

@jnrivra

Hello there! Thank you so much for this project, its amaizing!

I've been trying to incorporate the code to a multisensor I'm creating but when the ESP reads
Serial.printf("%.1f\n", Leq_dB);
Serial.println("dB");

it gets stucks reading forever and won't go back to the loop (see attached picture)

any thoughts?

extra:
what does ("%.1f\n", Leq_dB); means?
I tried reading a Serial.print(Leq_dB); but i get an error

my code is:

void readNoise()
{

// Create FreeRTOS queue
samples_queue = xQueueCreate(8, sizeof(sum_queue_t));

// Create the I2S reader FreeRTOS task
// NOTE: Current version of ESP-IDF will pin the task
// automatically to the first core it happens to run on
// (due to using the hardware FPU instructions).
// For manual control see: xTaskCreatePinnedToCore
xTaskCreate(mic_i2s_reader_task, "Mic I2S Reader", I2S_TASK_STACK, NULL, I2S_TASK_PRI, NULL);

sum_queue_t q;
uint32_t Leq_samples = 0;
double Leq_sum_sqr = 0;
double Leq_dB = 0;

// Read sum of samaples, calculated by 'i2s_reader_task'
while (xQueueReceive(samples_queue, &q, portMAX_DELAY)) {

// Calculate dB values relative to MIC_REF_AMPL and adjust for microphone reference
double short_RMS = sqrt(double(q.sum_sqr_SPL) / SAMPLES_SHORT);
double short_SPL_dB = MIC_OFFSET_DB + MIC_REF_DB + 20 * log10(short_RMS / MIC_REF_AMPL);

// In case of acoustic overload or below noise floor measurement, report infinty Leq value
if (short_SPL_dB > MIC_OVERLOAD_DB) {
  Leq_sum_sqr = INFINITY;
} else if (isnan(short_SPL_dB) || (short_SPL_dB < MIC_NOISE_DB)) {
  Leq_sum_sqr = -INFINITY;
}

// Accumulate Leq sum
Leq_sum_sqr += q.sum_sqr_weighted;
Leq_samples += SAMPLES_SHORT;

// When we gather enough samples, calculate new Leq value
if (Leq_samples >= SAMPLE_RATE * LEQ_PERIOD) {
  double Leq_RMS = sqrt(Leq_sum_sqr / Leq_samples);
  Leq_dB = MIC_OFFSET_DB + MIC_REF_DB + 20 * log10(Leq_RMS / MIC_REF_AMPL);
  Leq_sum_sqr = 0;
  Leq_samples = 0;
  
  // Serial output, customize (or remove) as needed

 noise = ("%.1f\n", Leq_dB);
  Serial.print("Decibeles: ");  
  Serial.printf("%.1f\n", Leq_dB);
  Serial.println("dB");


  // Debug only
  //Serial.printf("%u processing ticks\n", q.proc_ticks);
}
}    

}

thanks!!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions