Skip to content

Commit e7ee773

Browse files
Implement test signals for Audio_OutputMono
1 parent 9915b7c commit e7ee773

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ML_SynthTools",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"keywords": "ML_SynthTools, Synthesizer, Filter, Audio, ESP32, ESP32S2, ESP32S3, STM32, RP2040",
55
"description": "Synthesizer Tools; contains waveform generators etc.",
66
"repository":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ML SynthTools
2-
version=2.0.2
2+
version=2.0.3
33
author=Marcel Licence <[email protected]>
44
maintainer=Marcel Licence <[email protected]>
55
sentence=Synthesizer Tools

src/audio_module.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ I2S i2s(OUTPUT);
142142
#ifdef OUTPUT_SAW_TEST
143143
static float saw_left[SAMPLE_BUFFER_SIZE];
144144
static float saw_right[SAMPLE_BUFFER_SIZE];
145+
static int32_t saw_i32[SAMPLE_BUFFER_SIZE];
145146
#endif
146147
#ifdef OUTPUT_SINE_TEST
147148
static float sin_left[SAMPLE_BUFFER_SIZE];
148149
static float sin_right[SAMPLE_BUFFER_SIZE];
150+
static int32_t sine_i32[SAMPLE_BUFFER_SIZE];
149151
#endif
150152

151153
void Audio_Setup(void)
@@ -161,10 +163,12 @@ void Audio_Setup(void)
161163
*/
162164
for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++)
163165
{
164-
saw_left[i] = ((float)i * 2.0f) / ((float)SAMPLE_BUFFER_SIZE);
165-
saw_right[i] = ((float)i * 2.0f) / ((float)SAMPLE_BUFFER_SIZE);
166-
saw_left[i] -= 1.0f;
167-
saw_right[i] -= 1.0f;
166+
float saw = ((float)i * 2.0f) / ((float)SAMPLE_BUFFER_SIZE);
167+
saw -= 1.0f;
168+
saw_left[i] = saw;
169+
saw_right[i] = saw;
170+
saw *= 1073741824;
171+
saw_i32[i] = saw;
168172
}
169173
#endif
170174
#ifdef OUTPUT_SINE_TEST
@@ -176,8 +180,11 @@ void Audio_Setup(void)
176180
float w = i;
177181
w *= 1.0f / ((float)SAMPLE_BUFFER_SIZE);
178182
w *= 2.0f * M_PI;
179-
sin_left[i] = sin(w);
183+
float sine = sin(w);
184+
sin_left[i] = sine;
180185
sin_right[i] = sin(w * 2.0f);
186+
sine *= 1073741824;
187+
sine_i32[i] = sine;
181188
}
182189
#endif
183190

@@ -226,8 +233,12 @@ void Audio_Setup(void)
226233
while (1); // do nothing
227234
}
228235
#else /* #ifndef RP2350_USE_I2S_ML_LIB */
229-
rp2350_i2s_init(26, 27);
230-
Serial.printf("rp2350_i2s_init\n\tclock_pin_base: 26\n\tdata_pin: 27\n");
236+
{
237+
int data_pin = 26;
238+
int clock_pin_base = 27;
239+
rp2350_i2s_init(data_pin, clock_pin_base);
240+
Serial.printf("rp2350_i2s_init\n\tdata_pin: %d\n\tclock_pin_base: %d\n\twclk_pin: %d\n", data_pin, clock_pin_base, clock_pin_base + 1);
241+
}
231242
#endif /* #endif RP2350_USE_I2S_ML_LIB */
232243
#endif
233244

@@ -384,6 +395,13 @@ void Audio_PrintStats()
384395

385396
void Audio_OutputMono(const int32_t *samples)
386397
{
398+
#ifdef OUTPUT_SAW_TEST
399+
samples = saw_i32;
400+
#endif
401+
#ifdef OUTPUT_SINE_TEST
402+
samples = sine_i32;
403+
#endif
404+
387405
#ifdef ESP8266
388406
for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++)
389407
{
@@ -409,7 +427,7 @@ void Audio_OutputMono(const int32_t *samples)
409427
int16_t mono_u16[SAMPLE_BUFFER_SIZE];
410428
for (int n = 0; n < SAMPLE_BUFFER_SIZE; n++)
411429
{
412-
mono_u16[n] = samples[n] >> 8;
430+
mono_u16[n] = samples[n] >> 16;
413431
}
414432
rp2350_i2s_write_stereo_samples_buff(mono_u16, mono_u16, SAMPLE_BUFFER_SIZE);
415433
#endif /* #endif RP2350_USE_I2S_ML_LIB */
@@ -536,7 +554,9 @@ void Audio_OutputMono(const int32_t *samples)
536554

537555
for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++)
538556
{
539-
uint16_t val = (samples[i] + 0x8000) >> 5; /* 21 with 32 bit input */
557+
int32_t val32 = samples[i];
558+
val32 >>= 16;
559+
uint16_t val = (val32 + 0x8000) >> 5; /* 21 with 32 bit input */
540560
val += 361;
541561

542562
audioBuff[i].left = val;

0 commit comments

Comments
 (0)