Add audio module to micropython.

This commit is contained in:
iabdalkader 2020-10-29 20:55:08 +02:00
parent a8b4fae755
commit 375e374d35
3 changed files with 5 additions and 3 deletions

@ -1 +1 @@
Subproject commit 4a596fbacbb473b3801f127ab93bcb23cc801aba
Subproject commit ceab4082f6640a2e79ecdc372d61c7a07e233131

View File

@ -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)

View File

@ -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) {