Skip to content

Commit f86fbbe

Browse files
fixup! added audioio to espressif
1 parent e1a40a7 commit f86fbbe

File tree

4 files changed

+102
-51
lines changed

4 files changed

+102
-51
lines changed

locale/circuitpython.pot

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ msgstr ""
218218
#: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c
219219
#: shared-bindings/bitmapfilter/__init__.c shared-bindings/canio/CAN.c
220220
#: shared-bindings/digitalio/Pull.c shared-bindings/supervisor/__init__.c
221-
#: shared-module/synthio/Synthesizer.c
221+
#: shared-module/synthio/Biquad.c shared-module/synthio/Synthesizer.c
222222
msgid "%q must be of type %q or %q, not %q"
223223
msgstr ""
224224

@@ -734,6 +734,10 @@ msgstr ""
734734
msgid "Can only alarm on two low pins from deep sleep."
735735
msgstr ""
736736

737+
#: ports/espressif/common-hal/audioio/AudioOut.c
738+
msgid "Can't construct AudioOut because continuous channel already open"
739+
msgstr ""
740+
737741
#: ports/espressif/common-hal/_bleio/Characteristic.c
738742
#: ports/nordic/common-hal/_bleio/Characteristic.c
739743
msgid "Can't set CCCD on local Characteristic"
@@ -853,6 +857,10 @@ msgstr ""
853857
msgid "DAC already in use"
854858
msgstr ""
855859

860+
#: ports/espressif/common-hal/audioio/AudioOut.c
861+
msgid "DAC not supported"
862+
msgstr ""
863+
856864
#: ports/atmel-samd/common-hal/paralleldisplaybus/ParallelBus.c
857865
#: ports/nordic/common-hal/paralleldisplaybus/ParallelBus.c
858866
msgid "Data 0 pin must be byte aligned"
@@ -992,15 +1000,43 @@ msgstr ""
9921000
msgid "Failed to connect: timeout"
9931001
msgstr ""
9941002

1003+
#: ports/espressif/common-hal/audioio/AudioOut.c
1004+
msgid "Failed to create continuous channels: invalid arg"
1005+
msgstr ""
1006+
1007+
#: ports/espressif/common-hal/audioio/AudioOut.c
1008+
msgid "Failed to create continuous channels: invalid state"
1009+
msgstr ""
1010+
1011+
#: ports/espressif/common-hal/audioio/AudioOut.c
1012+
msgid "Failed to create continuous channels: no mem"
1013+
msgstr ""
1014+
1015+
#: ports/espressif/common-hal/audioio/AudioOut.c
1016+
msgid "Failed to create continuous channels: not found"
1017+
msgstr ""
1018+
1019+
#: ports/espressif/common-hal/audioio/AudioOut.c
1020+
msgid "Failed to enable continuous"
1021+
msgstr ""
1022+
9951023
#: shared-module/audiomp3/MP3Decoder.c
9961024
msgid "Failed to parse MP3 file"
9971025
msgstr ""
9981026

1027+
#: ports/espressif/common-hal/audioio/AudioOut.c
1028+
msgid "Failed to register continuous events callback"
1029+
msgstr ""
1030+
9991031
#: ports/nordic/sd_mutex.c
10001032
#, c-format
10011033
msgid "Failed to release mutex, err 0x%04x"
10021034
msgstr ""
10031035

1036+
#: ports/espressif/common-hal/audioio/AudioOut.c
1037+
msgid "Failed to start async audio"
1038+
msgstr ""
1039+
10041040
#: supervisor/shared/safe_mode.c
10051041
msgid "Failed to write internal flash."
10061042
msgstr ""
@@ -2384,6 +2420,10 @@ msgstr ""
23842420
msgid "addresses is empty"
23852421
msgstr ""
23862422

2423+
#: ports/espressif/common-hal/audioio/AudioOut.c
2424+
msgid "already playing"
2425+
msgstr ""
2426+
23872427
#: py/compile.c
23882428
msgid "annotation must be an identifier"
23892429
msgstr ""
@@ -2462,6 +2502,10 @@ msgstr ""
24622502
msgid "attributes not supported"
24632503
msgstr ""
24642504

2505+
#: ports/espressif/common-hal/audioio/AudioOut.c
2506+
msgid "audio format not supported"
2507+
msgstr ""
2508+
24652509
#: extmod/ulab/code/ulab_tools.c
24662510
msgid "axis is out of bounds"
24672511
msgstr ""
@@ -2592,7 +2636,7 @@ msgstr ""
25922636
msgid "can't cancel self"
25932637
msgstr ""
25942638

2595-
#: shared-module/adafruit_pixelbuf/PixelBuf.c
2639+
#: py/obj.c shared-module/adafruit_pixelbuf/PixelBuf.c
25962640
msgid "can't convert %q to %q"
25972641
msgstr ""
25982642

ports/espressif/common-hal/audioio/AudioOut.c

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void audioout_convert_s16s_u8s(
192192
*out_buffer_size = in_buffer_size / 2;
193193
}
194194

195-
#define CONV_MATCH(bps,sign,ichans,ochans) ( (bps&0xf) | ((sign&0x1)<<4) | ((ichans&0x3)<<5) | ((ochans&0x3)<<7) )
195+
#define CONV_MATCH(bps, sign, ichans, ochans) ((bps & 0xf) | ((sign & 0x1) << 4) | ((ichans & 0x3) << 5) | ((ochans & 0x3) << 7))
196196

197197
static audioout_sample_convert_func_t audioout_get_samples_convert_func(
198198
size_t in_bits_per_sample,
@@ -201,36 +201,36 @@ static audioout_sample_convert_func_t audioout_get_samples_convert_func(
201201
int out_channels) {
202202

203203
switch CONV_MATCH(in_bits_per_sample, in_signed, in_channels, out_channels) {
204-
case CONV_MATCH(8,false,1,1):
205-
case CONV_MATCH(8,false,2,2):
204+
case CONV_MATCH(8, false, 1, 1):
205+
case CONV_MATCH(8, false, 2, 2):
206206
return audioout_convert_noop;
207-
case CONV_MATCH(8,false,2,1):
207+
case CONV_MATCH(8, false, 2, 1):
208208
return audioout_convert_u8s_u8m;
209-
case CONV_MATCH(8,false,1,2):
209+
case CONV_MATCH(8, false, 1, 2):
210210
return audioout_convert_u8m_u8s;
211-
case CONV_MATCH(8,true,1,1):
211+
case CONV_MATCH(8, true, 1, 1):
212212
return audioout_convert_s8m_u8m;
213-
case CONV_MATCH(8,true,2,1):
213+
case CONV_MATCH(8, true, 2, 1):
214214
return audioout_convert_s8s_u8m;
215-
case CONV_MATCH(8,true,1,2):
215+
case CONV_MATCH(8, true, 1, 2):
216216
return audioout_convert_s8m_u8s;
217-
case CONV_MATCH(8,true,2,2):
217+
case CONV_MATCH(8, true, 2, 2):
218218
return audioout_convert_s8s_u8s;
219-
case CONV_MATCH(16,false,1,1):
219+
case CONV_MATCH(16, false, 1, 1):
220220
return audioout_convert_u16m_u8m;
221-
case CONV_MATCH(16,false,1,2):
221+
case CONV_MATCH(16, false, 1, 2):
222222
return audioout_convert_u16m_u8s;
223-
case CONV_MATCH(16,false,2,1):
223+
case CONV_MATCH(16, false, 2, 1):
224224
return audioout_convert_u16s_u8m;
225-
case CONV_MATCH(16,false,2,2):
225+
case CONV_MATCH(16, false, 2, 2):
226226
return audioout_convert_u16s_u8s;
227-
case CONV_MATCH(16,true,1,1):
227+
case CONV_MATCH(16, true, 1, 1):
228228
return audioout_convert_s16m_u8m;
229-
case CONV_MATCH(16,true,1,2):
229+
case CONV_MATCH(16, true, 1, 2):
230230
return audioout_convert_s16m_u8s;
231-
case CONV_MATCH(16,true,2,1):
231+
case CONV_MATCH(16, true, 2, 1):
232232
return audioout_convert_s16s_u8m;
233-
case CONV_MATCH(16,true,2,2):
233+
case CONV_MATCH(16, true, 2, 2):
234234
return audioout_convert_s16s_u8s;
235235
default:
236236
mp_raise_RuntimeError(MP_ERROR_TEXT("audio format not supported"));
@@ -247,7 +247,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) {
247247
uint8_t dma_buf_idx = self->get_buffer_index;
248248

249249
if (dma_buf_idx == self->put_buffer_index) {
250-
return false;
250+
return false;
251251
}
252252

253253
self->get_buffer_index = INCREMENT_BUF_IDX(dma_buf_idx);
@@ -267,7 +267,7 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) {
267267
if (self->sample_buffer != NULL && self->sample_buffer_size > 0) {
268268
sample_buf = self->sample_buffer;
269269
sample_buf_size = self->sample_buffer_size;
270-
get_buffer_result = self->sample_buffer_result;
270+
get_buffer_result = self->sample_buffer_result;
271271
} else {
272272
get_buffer_result = audiosample_get_buffer(self->sample,
273273
single_channel_output,
@@ -320,7 +320,9 @@ static bool audioout_fill_buffer(audioio_audioout_obj_t *self) {
320320
}
321321

322322
static void audioout_fill_buffers(audioio_audioout_obj_t *self) {
323-
while (audioout_fill_buffer(self));
323+
while (audioout_fill_buffer(self)) {
324+
;
325+
}
324326
}
325327

326328
static void audioout_buf_callback_fun(void *user_data) {
@@ -357,11 +359,11 @@ static void audioout_init(audioio_audioout_obj_t *self) {
357359
dac_continuous_config_t cfg = {
358360
.chan_mask = self->channel_mask,
359361
.desc_num = NUM_DMA_BUFFERS,
360-
.buf_size = DMA_BUFFER_SIZE,
362+
.buf_size = DMA_BUFFER_SIZE,
361363
.freq_hz = self->freq_hz,
362364
.offset = 0,
363365
.clk_src = DAC_DIGI_CLK_SRC_APLL,
364-
.chan_mode = self->channel_mode,
366+
.chan_mode = self->channel_mode,
365367
};
366368

367369
esp_err_t ret;
@@ -381,7 +383,7 @@ static void audioout_init(audioio_audioout_obj_t *self) {
381383

382384
dac_event_callbacks_t callbacks = {
383385
.on_convert_done = handle_convert_done,
384-
.on_stop = NULL,
386+
.on_stop = NULL,
385387
};
386388

387389
ret = dac_continuous_register_event_callback(self->handle, &callbacks, (void *)self);
@@ -411,29 +413,29 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self,
411413
* if different pins are supplied for left and right then use true stereo.
412414
* if the same pin is supplied for left and right then use dual mono.
413415
*/
414-
if ( (left_channel_pin == &pin_CHANNEL_0 &&
415-
right_channel_pin == &pin_CHANNEL_1) ||
416-
(left_channel_pin == &pin_CHANNEL_1 &&
417-
right_channel_pin == &pin_CHANNEL_0) ) {
416+
if ((left_channel_pin == &pin_CHANNEL_0 &&
417+
right_channel_pin == &pin_CHANNEL_1) ||
418+
(left_channel_pin == &pin_CHANNEL_1 &&
419+
right_channel_pin == &pin_CHANNEL_0)) {
418420
self->channel_mask = DAC_CHANNEL_MASK_ALL;
419-
self->num_channels = 2;
420-
self->channel_mode = DAC_CHANNEL_MODE_ALTER;
421-
} else if ( (left_channel_pin == &pin_CHANNEL_0 ||
422-
left_channel_pin == &pin_CHANNEL_1) &&
423-
right_channel_pin == left_channel_pin ) {
421+
self->num_channels = 2;
422+
self->channel_mode = DAC_CHANNEL_MODE_ALTER;
423+
} else if ((left_channel_pin == &pin_CHANNEL_0 ||
424+
left_channel_pin == &pin_CHANNEL_1) &&
425+
right_channel_pin == left_channel_pin) {
424426
self->channel_mask = DAC_CHANNEL_MASK_ALL;
425427
self->num_channels = 1;
426-
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
428+
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
427429
} else if (left_channel_pin == &pin_CHANNEL_0 &&
428430
right_channel_pin == NULL) {
429-
self->channel_mask = DAC_CHANNEL_MASK_CH0;
431+
self->channel_mask = DAC_CHANNEL_MASK_CH0;
430432
self->num_channels = 1;
431-
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
433+
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
432434
} else if (left_channel_pin == &pin_CHANNEL_1 &&
433435
right_channel_pin == NULL) {
434-
self->channel_mask = DAC_CHANNEL_MASK_CH1;
436+
self->channel_mask = DAC_CHANNEL_MASK_CH1;
435437
self->num_channels = 1;
436-
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
438+
self->channel_mode = DAC_CHANNEL_MODE_SIMUL;
437439
} else {
438440
raise_ValueError_invalid_pin();
439441
}
@@ -553,7 +555,7 @@ void common_hal_audioio_audioout_stop(audioio_audioout_obj_t *self) {
553555
}
554556

555557
bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t *self) {
556-
return self->playing && !self->paused;
558+
return self->playing && !self->paused;
557559
}
558560

559561
#else
@@ -566,20 +568,25 @@ bool common_hal_audioio_audioout_deinited(audioio_audioout_obj_t *self) {
566568
return true;
567569
}
568570

569-
void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) {}
571+
void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) {
572+
}
570573

571574
void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self,
572-
mp_obj_t sample, bool loop) {}
575+
mp_obj_t sample, bool loop) {
576+
}
573577

574-
void common_hal_audioio_audioout_pause(audioio_audioout_obj_t *self) {}
578+
void common_hal_audioio_audioout_pause(audioio_audioout_obj_t *self) {
579+
}
575580

576-
void common_hal_audioio_audioout_resume(audioio_audioout_obj_t *self) {}
581+
void common_hal_audioio_audioout_resume(audioio_audioout_obj_t *self) {
582+
}
577583

578584
bool common_hal_audioio_audioout_get_paused(audioio_audioout_obj_t *self) {
579585
return false;
580586
}
581587

582-
void common_hal_audioio_audioout_stop(audioio_audioout_obj_t *self) {}
588+
void common_hal_audioio_audioout_stop(audioio_audioout_obj_t *self) {
589+
}
583590

584591
bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t *self) {
585592
return false;

ports/espressif/common-hal/audioio/AudioOut.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#define DEFAULT_SAMPLE_RATE 32000
1818

19-
typedef void(*audioout_sample_convert_func_t)(void *in_buffer, size_t in_buffer_size, uint8_t *out_buffer, uint32_t *out_buffer_size);
19+
typedef void (*audioout_sample_convert_func_t)(void *in_buffer, size_t in_buffer_size, uint8_t *out_buffer, uint32_t *out_buffer_size);
2020

2121
typedef struct {
2222
uint8_t *ptr;
@@ -39,7 +39,7 @@ typedef struct {
3939
audioio_get_buffer_result_t sample_buffer_result;
4040
uint8_t get_buffer_index;
4141
uint8_t put_buffer_index;
42-
buf_info_t dma_buffers[NUM_DMA_BUFFERS+1];
42+
buf_info_t dma_buffers[NUM_DMA_BUFFERS + 1];
4343
background_callback_t callback;
4444
uint8_t scratch_buffer[DMA_BUFFER_SIZE];
4545
audioout_sample_convert_func_t samples_convert;

shared-module/audiocore/__init__.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void audiosample_convert_u8s_u8m(uint8_t *buffer_out, const uint8_t *buffer_in,
112112
for (; nframes--;) {
113113
uint8_t sample = *buffer_in++ + 0x80;
114114
*buffer_out++ = sample;
115-
buffer_in++;
115+
buffer_in++;
116116
}
117117
}
118118

@@ -127,7 +127,7 @@ void audiosample_convert_s8s_u8m(uint8_t *buffer_out, const int8_t *buffer_in, s
127127
for (; nframes--;) {
128128
uint8_t sample = *buffer_in++ + 0x80;
129129
*buffer_out++ = sample;
130-
buffer_in++;
130+
buffer_in++;
131131
}
132132
}
133133

@@ -142,7 +142,7 @@ void audiosample_convert_u16s_u8m(uint8_t *buffer_out, const uint16_t *buffer_in
142142
for (; nframes--;) {
143143
uint8_t sample = (*buffer_in++) >> 8;
144144
*buffer_out++ = sample;
145-
buffer_in++;
145+
buffer_in++;
146146
}
147147
}
148148

@@ -157,7 +157,7 @@ void audiosample_convert_s16s_u8m(uint8_t *buffer_out, const int16_t *buffer_in,
157157
for (; nframes--;) {
158158
uint8_t sample = (*buffer_in++ + 0x8000) >> 8;
159159
*buffer_out++ = sample;
160-
buffer_in++;
160+
buffer_in++;
161161
}
162162
}
163163

0 commit comments

Comments
 (0)