5656#ifdef ML_SYNTH_INLINE_DECLARATION
5757
5858void setup_i2s (void );
59- bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen );
60- bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen , uint8_t stream_id );
6159bool i2s_write_stereo_samples_buff (const float * fl_sample , const float * fr_sample , const int buffLen );
62- bool i2s_write_stereo_samples_buff (const float * fl_sample , const float * fr_sample , const int buffLen , uint8_t stream_id );
60+ bool i2s_write_stereo_samples_buff (uint8_t stream_id , const float * fl_sample , const float * fr_sample , const int buffLen , uint8_t codec_num );
61+ bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen );
62+ bool i2s_write_stereo_samples_i16 (uint8_t stream_id , const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen );
6363void i2s_read_stereo_samples_buff (float * fl_sample , float * fr_sample , const int buffLen );
6464void i2s_read_stereo_samples_buff (int16_t * fl_sample , int16_t * fr_sample , const int buffLen );
65- void i2s_read_stereo_samples_buff (int16_t * fl_sample , int16_t * fr_sample , const int buffLen , uint8_t stream_id );
65+ void i2s_read_stereo_samples_buff (uint8_t stream_id , float * fl_sample , float * fr_sample , const int buffLen );
66+ void i2s_read_stereo_samples_i16 (uint8_t stream_id , int16_t * fl_sample , int16_t * fr_sample , const int buffLen );
6667
6768#endif /* ML_SYNTH_INLINE_DECLARATION */
6869
@@ -146,11 +147,13 @@ union sampleTUNT
146147//#define I2S_NODAC
147148
148149
149- #ifndef DUAL_CODEC_ENABLED
150- const i2s_port_t i2s_port_number [] = {I2S_NUM_0 };
151- #else
152- const i2s_port_t i2s_port_number [] = {I2S_NUM_0 , I2S_NUM_1 };
150+ const i2s_port_t i2s_port_number [] =
151+ {
152+ I2S_NUM_0 ,
153+ #ifdef DUAL_CODEC_ENABLED
154+ I2S_NUM_1 ,
153155#endif
156+ };
154157
155158/*
156159 * please refer to https://www.hackster.io/janost/audio-hacking-on-the-esp8266-fa9464#toc-a-simple-909-drum-synth-0
@@ -195,7 +198,7 @@ bool i2s_write_sample_24ch2(uint8_t *sample)
195198
196199#endif
197200
198- bool i2s_write_stereo_samples (const float * fl_sample , const float * fr_sample , uint8_t stream_id )
201+ bool i2s_write_stereo_samples (uint8_t stream_id , const float * fl_sample , const float * fr_sample )
199202{
200203 static union sampleTUNT sampleDataU ;
201204
@@ -221,11 +224,11 @@ bool i2s_write_stereo_samples(const float *fl_sample, const float *fr_sample, ui
221224
222225bool i2s_write_stereo_samples (const float * fl_sample , const float * fr_sample )
223226{
224- return i2s_write_stereo_samples (fl_sample , fr_sample , 0 );
227+ return i2s_write_stereo_samples (0 , fl_sample , fr_sample );
225228};
226229
227230#ifdef SAMPLE_SIZE_16BIT
228- bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample , uint8_t stream_id )
231+ bool i2s_write_stereo_samples_i16 (uint8_t stream_id , const int16_t * fl_sample , const int16_t * fr_sample )
229232{
230233 size_t bytes_written = 0 ;
231234
@@ -252,15 +255,15 @@ bool i2s_write_stereo_samples_i16(const int16_t *fl_sample, const int16_t *fr_sa
252255
253256bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample )
254257{
255- return i2s_write_stereo_samples_i16 (fl_sample , fr_sample , 0 );
258+ return i2s_write_stereo_samples_i16 (0 , fl_sample , fr_sample );
256259}
257260#endif
258261
259262#ifdef SAMPLE_SIZE_16BIT
260- bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen , uint8_t stream_id )
263+ bool i2s_write_stereo_samples_i16 (uint8_t stream_id , const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen )
261264{
262265 size_t bytes_written = 0 ;
263-
266+ i2s_port_t target_port = i2s_port_number [ stream_id ];
264267 static union sampleTUNT sampleDataU [SAMPLE_BUFFER_SIZE ];
265268
266269#ifdef OUTPUT_SAW_TEST
@@ -280,7 +283,7 @@ bool i2s_write_stereo_samples_i16(const int16_t *fl_sample, const int16_t *fr_sa
280283#ifdef CYCLE_MODULE_ENABLED
281284 calcCycleCountPre ();
282285#endif
283- i2s_write (i2s_port_number [ stream_id ] , (const char * )& sampleDataU [0 ].sample , 2 * BYTES_PER_SAMPLE * buffLen , & bytes_written , portMAX_DELAY );
286+ i2s_write (target_port , (const char * )& sampleDataU [0 ].sample , 2 * BYTES_PER_SAMPLE * buffLen , & bytes_written , portMAX_DELAY );
284287#ifdef CYCLE_MODULE_ENABLED
285288 calcCycleCount ();
286289#endif
@@ -297,12 +300,12 @@ bool i2s_write_stereo_samples_i16(const int16_t *fl_sample, const int16_t *fr_sa
297300
298301bool i2s_write_stereo_samples_i16 (const int16_t * fl_sample , const int16_t * fr_sample , const int buffLen )
299302{
300- return i2s_write_stereo_samples_i16 (fl_sample , fr_sample , buffLen , 0 );
303+ return i2s_write_stereo_samples_i16 (0 , fl_sample , fr_sample , buffLen );
301304}
302305#endif
303306
304307#ifdef SAMPLE_BUFFER_SIZE
305- bool i2s_write_stereo_samples_buff (const float * fl_sample , const float * fr_sample , const int buffLen , uint8_t stream_id )
308+ bool i2s_write_stereo_samples_buff (uint8_t stream_id , const float * fl_sample , const float * fr_sample , const int buffLen )
306309{
307310 static union sampleTUNT sampleDataU [SAMPLE_BUFFER_SIZE ];
308311
@@ -353,8 +356,8 @@ bool i2s_write_stereo_samples_buff(const float *fl_sample, const float *fr_sampl
353356#ifdef OUTPUT_SAW_TEST
354357 for (int n = 0 ; n < buffLen ; n ++ )
355358 {
356- sampleDataU [n ].ch [1 ] = sampleDataI16SawTest [0 + stream_id * 2 ][ n ];
357- sampleDataU [n ].ch [0 ] = sampleDataI16SawTest [1 + stream_id * 2 ][ n ];
359+ sampleDataU [n ].ch [1 ] = sampleDataI16SawTest [n ];
360+ sampleDataU [n ].ch [0 ] = sampleDataI16SawTest [n ];
358361 }
359362#endif
360363
@@ -380,11 +383,11 @@ bool i2s_write_stereo_samples_buff(const float *fl_sample, const float *fr_sampl
380383
381384bool i2s_write_stereo_samples_buff (const float * fl_sample , const float * fr_sample , const int buffLen )
382385{
383- return i2s_write_stereo_samples_buff (fl_sample , fr_sample , buffLen , 0 );
386+ return i2s_write_stereo_samples_buff (0 , fl_sample , fr_sample , buffLen );
384387}
385388#endif /* #ifdef SAMPLE_BUFFER_SIZE */
386389
387- void i2s_read_stereo_samples (float * fl_sample , float * fr_sample , uint8_t stream_id )
390+ void i2s_read_stereo_samples (uint8_t stream_id , float * fl_sample , float * fr_sample )
388391{
389392 static size_t bytes_read = 0 ;
390393
@@ -402,11 +405,11 @@ void i2s_read_stereo_samples(float *fl_sample, float *fr_sample, uint8_t stream_
402405
403406void i2s_read_stereo_samples (float * fl_sample , float * fr_sample )
404407{
405- i2s_read_stereo_samples (fl_sample , fr_sample , 0 );
408+ i2s_read_stereo_samples (0 , fl_sample , fr_sample );
406409}
407410
408411#ifdef SAMPLE_BUFFER_SIZE
409- void i2s_read_stereo_samples_buff (int16_t * fl_sample , int16_t * fr_sample , const int buffLen , uint8_t stream_id )
412+ void i2s_read_stereo_samples_buff (uint8_t stream_id , int16_t * fl_sample , int16_t * fr_sample , const int buffLen )
410413{
411414#ifdef I2S_DIN_PIN
412415 static size_t bytes_read = 0 ;
@@ -429,10 +432,10 @@ void i2s_read_stereo_samples_buff(int16_t *fl_sample, int16_t *fr_sample, const
429432
430433void i2s_read_stereo_samples_buff (int16_t * fl_sample , int16_t * fr_sample , const int buffLen )
431434{
432- i2s_read_stereo_samples_buff (fl_sample , fr_sample , buffLen , 0 );
435+ i2s_read_stereo_samples_buff (0 , fl_sample , fr_sample , buffLen );
433436}
434437
435- void i2s_read_stereo_samples_buff (float * fl_sample , float * fr_sample , const int buffLen , uint8_t stream_id )
438+ void i2s_read_stereo_samples_buff (uint8_t stream_id , float * fl_sample , float * fr_sample , const int buffLen )
436439{
437440#ifdef I2S_DIN_PIN
438441 static size_t bytes_read = 0 ;
@@ -457,7 +460,7 @@ void i2s_read_stereo_samples_buff(float *fl_sample, float *fr_sample, const int
457460
458461void i2s_read_stereo_samples_buff (float * fl_sample , float * fr_sample , const int buffLen )
459462{
460- i2s_read_stereo_samples_buff (fl_sample , fr_sample , buffLen , 0 );
463+ i2s_read_stereo_samples_buff (0 , fl_sample , fr_sample , buffLen );
461464}
462465
463466#endif /* #ifdef SAMPLE_BUFFER_SIZE */
@@ -684,43 +687,8 @@ i2s_pin_config_t pins[] =
684687 },
685688#endif /* (defined I2S_BCLK_PIN_SECONDARY) && (defined I2S_WCLK_PIN_SECONDARY) && (defined I2S_DOUT_PIN_SECONDARY) */
686689#endif /* DUAL_CODEC_ENABLED */
687-
688- #endif /* (defined I2S_BCLK_PIN) && (defined I2S_WCLK_PIN) && (defined I2S_DOUT_PIN) */
689-
690- #ifdef DUAL_CODEC_ENABLED
691- #if (defined I2S_DOUT_PIN_SECONDARY ) || (defined I2S_DIN_PIN_SECONDARY )
692- /* Secondary I2S pin configuration for dual codec setup */
693-
694- {
695- #ifdef I2S_MCLK_PIN_SECONDARY
696- .mck_io_num = I2S_MCLK_PIN_SECONDARY ,
697- #else
698- .mck_io_num = I2S_PIN_NO_CHANGE ,
699- #endif
700- #ifdef I2S_BCLK_PIN_SECONDARY
701- .bck_io_num = I2S_BCLK_PIN_SECONDARY ,
702- #else
703- .bck_io_num = I2S_PIN_NO_CHANGE ,
704- #endif
705- #ifdef I2S_WCLK_PIN_SECONDARY
706- .ws_io_num = I2S_WCLK_PIN_SECONDARY ,
707- #else
708- .ws_io_num = I2S_PIN_NO_CHANGE ,
709- #endif
710- #ifdef I2S_DOUT_PIN_SECONDARY
711- .data_out_num = I2S_DOUT_PIN_SECONDARY ,
712- #else
713- .data_out_num = I2S_PIN_NO_CHANGE ,
714- #endif
715- #ifdef I2S_DIN_PIN_SECONDARY
716- .data_in_num = I2S_DIN_PIN_SECONDARY ,
717- #else
718- .data_in_num = I2S_PIN_NO_CHANGE ,
719- #endif
720- },
721- #endif /* (defined I2S_BCLK_PIN_SECONDARY) && (defined I2S_WCLK_PIN_SECONDARY) && (defined I2S_DOUT_PIN_SECONDARY) */
722- #endif /* DUAL_CODEC_ENABLED */
723690};
691+ #endif /* (defined I2S_BCLK_PIN) && (defined I2S_WCLK_PIN) && (defined I2S_DOUT_PIN) */
724692
725693#endif
726694
0 commit comments