ajout effets audio
This commit is contained in:
1 parent
f8a79b08bf
commit
44a43828f1
14 files changed
+541
-6
No files matched your search
+16
-5
@@ -25,6 +25,7 @@
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "stm32h7s78_discovery_audio.h"
|
||||
#include "audio_effects.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
@@ -186,6 +187,8 @@ int main(void)
|
||||
fifo_write_idx = FIFO_SIZE / 2;
|
||||
fifo_read_idx = 0;
|
||||
|
||||
AudioEffects_Init();
|
||||
|
||||
sDmaConfig.Address = (uint32_t)adf_buf;
|
||||
sDmaConfig.DataLength = AUDIO_SAMPLES * sizeof(int32_t); /* OCTETS */
|
||||
sDmaConfig.MsbOnly = DISABLE; /* 32-bit/sample ; ENABLE si buffer int16 */
|
||||
@@ -768,11 +771,17 @@ static void MX_GPIO_Init(void)
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
static inline int16_t adf_sample_to_pcm16(int32_t raw)
|
||||
static inline float adf_sample_to_float(int32_t raw)
|
||||
{
|
||||
int32_t v = raw >> 8; // 24 bits -> 16 bits (comme le fait le BSP)
|
||||
if (v > 32767) v = 32767;
|
||||
if (v < -32768) v = -32768;
|
||||
int32_t v = raw >> 8; // 24 bits -> valeur signee sur 24 bits
|
||||
return (float)v / 8388608.0f; // normalisation en [-1.0, 1.0]
|
||||
}
|
||||
|
||||
static inline int16_t float_to_pcm16(float x)
|
||||
{
|
||||
float v = x * 32767.0f;
|
||||
if (v > 32767.0f) v = 32767.0f;
|
||||
if (v < -32768.0f) v = -32768.0f;
|
||||
return (int16_t)v;
|
||||
}
|
||||
|
||||
@@ -782,7 +791,9 @@ static void push_to_fifo(int32_t raw)
|
||||
{
|
||||
return; // FIFO pleine : on jette l'échantillon plutôt que d'écraser du non-lu
|
||||
}
|
||||
int16_t s = adf_sample_to_pcm16(raw);
|
||||
float sample = adf_sample_to_float(raw);
|
||||
sample = AudioEffects_Process(sample);
|
||||
int16_t s = float_to_pcm16(sample);
|
||||
uint32_t idx = fifo_write_idx & (FIFO_SIZE - 1);
|
||||
audio_fifo[idx * 2] = s;
|
||||
audio_fifo[idx * 2 + 1] = s;
|
||||
|
||||
Reference in new issue
Block a user