From 375e374d35cce51d9c3ce75e8e389984c0eb917a Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 29 Oct 2020 20:55:08 +0200 Subject: [PATCH] Add audio module to micropython. --- src/micropython | 2 +- src/omv/boards/PORTENTA/omv_boardconfig.h | 3 +++ src/omv/py/py_audio.c | 3 +-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/micropython b/src/micropython index 4a596fbac..ceab4082f 160000 --- a/src/micropython +++ b/src/micropython @@ -1 +1 @@ -Subproject commit 4a596fbacbb473b3801f127ab93bcb23cc801aba +Subproject commit ceab4082f6640a2e79ecdc372d61c7a07e233131 diff --git a/src/omv/boards/PORTENTA/omv_boardconfig.h b/src/omv/boards/PORTENTA/omv_boardconfig.h index 37bf005ee..130e3a2c4 100644 --- a/src/omv/boards/PORTENTA/omv_boardconfig.h +++ b/src/omv/boards/PORTENTA/omv_boardconfig.h @@ -270,7 +270,9 @@ // SAI4 #define AUDIO_SAI (SAI4_Block_A) +// SCKx frequency = SAI_KER_CK / MCKDIV / 2 #define AUDIO_SAI_MCKDIV (12) +#define AUDIO_SAI_FREQKHZ (2048U) // 2048KHz #define AUDIO_SAI_CK_PORT (GPIOE) #define AUDIO_SAI_CK_PIN (GPIO_PIN_2) @@ -293,6 +295,7 @@ // Set SAI1 clock source in system ex: Sai1ClockSelection = RCC_SAI1CLKSOURCE_PLL; // #define AUDIO_SAI (SAI1_Block_A) // #define AUDIO_SAI_MCKDIV (12) +// #define AUDIO_SAI_FREQKHZ (2048U) // 2048KHz // // #define AUDIO_SAI_CK_PORT (GPIOE) // #define AUDIO_SAI_CK_PIN (GPIO_PIN_2) diff --git a/src/omv/py/py_audio.c b/src/omv/py/py_audio.c index ac7c22196..7fd78066a 100644 --- a/src/omv/py/py_audio.c +++ b/src/omv/py/py_audio.c @@ -19,7 +19,6 @@ #if MICROPY_PY_AUDIO -#define PDM_SAMPLE_FREQ (2048U)//KHz #define RAISE_OS_EXCEPTION(msg) nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, msg)) #define SAI_MIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) @@ -223,7 +222,7 @@ static mp_obj_t py_audio_read_pcm(uint n_args, const mp_obj_t *args, mp_map_t *k size_t typesize = mp_binary_get_size('@', pcmbuf.typecode, NULL); uint32_t n_samples = pcmbuf.len / typesize; int16_t *output_buffer = (int16_t *) pcmbuf.buf; - uint32_t decimation_factor = PDM_SAMPLE_FREQ/frequency; + uint32_t decimation_factor = AUDIO_SAI_FREQKHZ/frequency; uint32_t output_samples = ((PDM_BUFFER_SIZE / 2) * 8) / (decimation_factor * n_channels); // Half transfer if (typesize != 2) {