fix reporting to match time elapsed

main
Clyne 3 weeks ago
parent cc0a8af700
commit 88ea3cc0ef
Signed by: clyne
GPG Key ID: 7BA5A2980566A649

@ -34,11 +34,12 @@ typedef struct {
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define SAMPLE_COUNT (512) // Sample count per half-transfer
#define MIC_OFFSET_DB ( 0.f) // Linear offset
#define MIC_SENSITIVITY (-26.f) // dBFS value expected at MIC_REF_DB
#define MIC_REF_DB ( 94.f) // dB where sensitivity is specified
#define MIC_BITS (18)
#define SAMPLE_COUNT (256) // Sample count per half-transfer
#define SAMPLES_PER_REPORT (48000) // Report every second given our 48 kHz rate
#define MIC_OFFSET_DB ( 0.f) // Linear offset
#define MIC_SENSITIVITY (-26.f) // dBFS value expected at MIC_REF_DB
#define MIC_REF_DB ( 94.f) // dB where sensitivity is specified
#define MIC_BITS (18)
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@ -58,7 +59,7 @@ UART_HandleTypeDef huart2;
static const uint8_t I2S_Frame_Buffer[8] = {
0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
};
static uint8_t I2S_Receive_Buffer[SAMPLE_COUNT * sizeof(sample_t)];
static uint8_t I2S_Receive_Buffer[SAMPLE_COUNT * 2 * sizeof(sample_t)];
float ln10;
float MIC_REF_AMPL;
@ -547,16 +548,16 @@ void SPI_DMAHalfTransmitReceiveCplt(DMA_HandleTypeDef *hdma)
float f = process(qfp_int2float(sample[i].value / 4));
DB_Sum_Squares = qfp_fadd(DB_Sum_Squares, qfp_fmul(f, f));
}
DB_Count += SAMPLE_COUNT / 8;
DB_Count += SAMPLE_COUNT * 2; // Pretend we sampled the entire I2S buffer
if (DB_Count > 48000 / 4) {
if (DB_Count > SAMPLES_PER_REPORT) {
float rms = qfp_fsqrt(qfp_fdiv(DB_Sum_Squares, qfp_uint2float(DB_Count)));
float db = qfp_fadd(MIC_OFFSET_DB + MIC_REF_DB, qfp_fmul(20.f,
qfp_flog10(qfp_fdiv(rms, MIC_REF_AMPL))));
DB_Sum_Squares = 0.f;
DB_Count = 0;
printf("%d\r\n", qfp_float2int(db));
printf("%d dB\r\n", qfp_float2int(db));
}
}
/* USER CODE END 4 */

Loading…
Cancel
Save