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