Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ML_SynthTools",
"version": "2.0.12",
"version": "2.0.14",
"keywords": "ML_SynthTools, Synthesizer, Filter, Audio, ESP32, ESP32S2, ESP32S3, STM32, RP2040",
"description": "Synthesizer Tools; contains waveform generators etc.",
"repository":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ML SynthTools
version=2.0.12
version=2.0.14
author=Marcel Licence <[email protected]>
maintainer=Marcel Licence <[email protected]>
sentence=Synthesizer Tools
Expand Down
53 changes: 39 additions & 14 deletions src/audio_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@
#include <ml_types.h>


typedef enum
{
AUDIO_PORT_0 = 0,
AUDIO_PORT_1 = 1,
// Add more outputs as needed
} AudioPortId;


void Audio_Setup(void);
void Audio_Output(const float *left, const float *right);
void Audio_OutputMono(const int32_t *samples);
void Audio_Output(const int32_t *samples);
void Audio_Output(const int16_t *samples);
void Audio_Output(const Q1_14 *samples);
void Audio_Output(const int16_t *left, const int16_t *right);
void Audio_Output(AudioPortId audio_port, const int16_t *left, const int16_t *right);
void Audio_Output(const Q1_14 *left, const Q1_14 *right);
void Audio_Input(float *left, float *right);
void Audio_Input(Q1_14 *left, Q1_14 *right);
Expand Down Expand Up @@ -156,9 +165,8 @@ static float saw_right[SAMPLE_BUFFER_SIZE];
static int32_t saw_i32[SAMPLE_BUFFER_SIZE];
#endif
#ifdef OUTPUT_SINE_TEST
static float sin_left[SAMPLE_BUFFER_SIZE];
static float sin_right[SAMPLE_BUFFER_SIZE];
static int32_t sine_i32[SAMPLE_BUFFER_SIZE];
static float sin[4][SAMPLE_BUFFER_SIZE];
static int32_t sine_i32[4][SAMPLE_BUFFER_SIZE];
#endif

void Audio_Setup(void)
Expand Down Expand Up @@ -192,22 +200,29 @@ void Audio_Setup(void)
w *= 1.0f / ((float)SAMPLE_BUFFER_SIZE);
w *= 2.0f * M_PI;
float sine = sin(w);
sin_left[i] = sine;
sin_right[i] = sin(w * 2.0f);
sine *= 1073741824;
sine_i32[i] = sine;
for (int n = 0; n < 4; n++)
{
sine = sin(n * w * 2.0f);
sin[n][i] = sine;
sine *= 1073741824;
sine_i32[n][i] = sine;
}
}
#endif

#ifdef ESP32_AUDIO_KIT
#ifdef ES8388_ENABLED
ES8388_Setup();
ES8388_SetIn2OoutVOL(0, 0);
ES8388_Setup(ES8388_ID0);
ES8388_SetIn2OoutVOL(ES8388_ID0, 0.0f);
#else
ac101_setup();
#endif
#endif

#if defined(DUAL_CODEC_ENABLED) && defined(ES8388_ENABLED)
ES8388_Setup(ES8388_ID1);
ES8388_SetIn2OoutVOL(ES8388_ID1, 0.0f);
#endif

#ifdef WM8978_ENABLED
WM8978_Setup();
Expand Down Expand Up @@ -638,7 +653,7 @@ void Audio_Output(const Q1_14 *left, const Q1_14 *right)
}

#ifndef ARDUINO_SEEED_XIAO_M0
void Audio_Output(const int16_t *left, const int16_t *right)
void Audio_Output(AudioPortId audio_port, const int16_t *left, const int16_t *right)
{
#ifdef ESP8266
for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++)
Expand Down Expand Up @@ -703,7 +718,7 @@ void Audio_Output(const int16_t *left, const int16_t *right)
}
}
#else
i2s_write_stereo_samples_i16(left, right, SAMPLE_BUFFER_SIZE);
i2s_write_stereo_samples_i16((uint8_t)audio_port, left, right, SAMPLE_BUFFER_SIZE);
#endif
#endif /* ESP32 */

Expand Down Expand Up @@ -830,6 +845,11 @@ void Audio_Output(const int16_t *left, const int16_t *right)
#endif
#endif /* PICO_AUDIO_I2S */
}

void Audio_Output(const int16_t *left, const int16_t *right)
{
Audio_Output(AUDIO_PORT_0, left, right);
}
#endif

#if (defined ESP32) || (defined TEENSYDUINO) || (defined ARDUINO_DAISY_SEED) || (defined ARDUINO_GENERIC_F407VGTX) || (defined ARDUINO_DISCO_F407VG) || (defined ARDUINO_BLACK_F407VE) || (defined ARDUINO_ARCH_RP2040) || (((defined ARDUINO_RASPBERRY_PI_PICO) || (defined ARDUINO_GENERIC_RP2040)) && (defined RP2040_AUDIO_PWM))
Expand All @@ -844,9 +864,14 @@ void Audio_Input(Q1_14 *left, Q1_14 *right)
i2s_read_stereo_samples_buff((int16_t *)left, (int16_t *)right, SAMPLE_BUFFER_SIZE);
}

void Audio_Input(AudioPortId audio_port, int16_t *left, int16_t *right)
{
i2s_read_stereo_samples_buff((uint8_t)audio_port, left, right, SAMPLE_BUFFER_SIZE);
}

void Audio_Input(int16_t *left, int16_t *right)
{
i2s_read_stereo_samples_buff(left, right, SAMPLE_BUFFER_SIZE);
Audio_Input(AUDIO_PORT_0, left, right);
}
#else
void Audio_Input(float *left __attribute__((__unused__)), float *right __attribute__((__unused__)))
Expand All @@ -862,8 +887,8 @@ void Audio_Output(const float *left, const float *right)
right = saw_right;
#endif
#ifdef OUTPUT_SINE_TEST
left = sin_left;
right = sin_right;
left = sin[0];
right = sin[1];
#endif

#ifdef ESP32
Expand Down
Loading
Loading