88#include "freertos/FreeRTOS.h"
99#include "esp_log.h"
1010
11+ #include "device/i2s.h"
1112#include "driver/i2s.h"
1213
1314/* render callback for the libmad synth */
1415void render_sample_block (short * sample_buff_ch0 , short * sample_buff_ch1 , int num_samples , unsigned int num_channels )
1516{
1617 // pointer to left / right sample position
17- char * ptr_l = (char * ) sample_buff_ch0 ;
18- char * ptr_r = (char * ) sample_buff_ch1 ;
18+ char * ptr_l = (char * )sample_buff_ch0 ;
19+ char * ptr_r = (char * )sample_buff_ch1 ;
1920 uint8_t stride = sizeof (short );
2021
2122 if (num_channels == 1 ) {
2223 ptr_r = ptr_l ;
2324 }
2425
25- int bytes_pushed = 0 ;
26+ size_t bytes_written = 0 ;
2627 TickType_t max_wait = 20 / portTICK_PERIOD_MS ; // portMAX_DELAY = bad idea
2728 for (int i = 0 ; i < num_samples ; i ++ ) {
2829 /* low - high / low - high */
2930 const char samp32 [4 ] = {ptr_l [0 ], ptr_l [1 ], ptr_r [0 ], ptr_r [1 ]};
30- bytes_pushed = i2s_push_sample (0 , (const char * ) & samp32 , max_wait );
31+ i2s_write (0 , (const char * ) & samp32 , sizeof ( samp32 ), & bytes_written , max_wait );
3132
3233 // DMA buffer full - retry
33- if (bytes_pushed == 0 ) {
34+ if (bytes_written == 0 ) {
3435 i -- ;
3536 } else {
3637 ptr_r += stride ;
@@ -42,9 +43,5 @@ void render_sample_block(short *sample_buff_ch0, short *sample_buff_ch1, int num
4243/* Called by the NXP modifications of libmad. Sets the needed output sample rate. */
4344void set_dac_sample_rate (int rate )
4445{
45- static int dac_sample_rate = 44100 ;
46- if (rate != dac_sample_rate ) {
47- i2s_set_sample_rates (0 , rate );
48- dac_sample_rate = rate ;
49- }
46+ i2s0_set_sample_rate (rate );
5047}
0 commit comments