@@ -54,6 +54,16 @@ static uint32_t i2s_slc_queue[SLC_BUF_CNT-1];
54
54
static uint8_t i2s_slc_queue_len ;
55
55
static uint32_t * i2s_slc_buf_pntr [SLC_BUF_CNT ]; //Pointer to the I2S DMA buffer data
56
56
static struct slc_queue_item i2s_slc_items [SLC_BUF_CNT ]; //I2S DMA buffer descriptors
57
+ static uint32_t * i2s_curr_slc_buf = NULL ;//current buffer for writing
58
+ static int i2s_curr_slc_buf_pos = 0 ; //position in the current buffer
59
+
60
+ bool ICACHE_FLASH_ATTR i2s_is_full (){
61
+ return (i2s_curr_slc_buf_pos == SLC_BUF_LEN || i2s_curr_slc_buf == NULL ) && (i2s_slc_queue_len == 0 );
62
+ }
63
+
64
+ bool ICACHE_FLASH_ATTR i2s_is_empty (){
65
+ return (i2s_slc_queue_len >= SLC_BUF_CNT - 1 );
66
+ }
57
67
58
68
uint32_t ICACHE_FLASH_ATTR i2s_slc_queue_next_item (){ //pop the top off the queue
59
69
uint8_t i ;
@@ -73,7 +83,7 @@ void ICACHE_FLASH_ATTR i2s_slc_isr(void) {
73
83
if (slc_intr_status & SLCIRXEOF ) {
74
84
ETS_SLC_INTR_DISABLE ();
75
85
struct slc_queue_item * finished_item = (struct slc_queue_item * )SLCRXEDA ;
76
-
86
+ memset (( void * ) finished_item -> buf_ptr , 0x00 , SLC_BUF_LEN * 4 ); //zero the buffer so it is mute in case of underflow
77
87
if (i2s_slc_queue_len >= SLC_BUF_CNT - 1 ) { //All buffers are empty. This means we have an underflow
78
88
i2s_slc_queue_next_item (); //free space for finished_item
79
89
}
@@ -142,8 +152,6 @@ void ICACHE_FLASH_ATTR i2s_slc_end(){
142
152
//at least the current sample rate. You can also call it quicker: it will suspend the calling
143
153
//thread if the buffer is full and resume when there's room again.
144
154
145
- static uint32_t * i2s_curr_slc_buf = NULL ;
146
- static int i2s_curr_slc_buf_pos = 0 ;
147
155
bool ICACHE_FLASH_ATTR i2s_write_sample (uint32_t sample ) {
148
156
if (i2s_curr_slc_buf_pos == SLC_BUF_LEN || i2s_curr_slc_buf == NULL ) {
149
157
if (i2s_slc_queue_len == 0 ){
@@ -165,6 +173,20 @@ bool ICACHE_FLASH_ATTR i2s_write_sample(uint32_t sample) {
165
173
return true;
166
174
}
167
175
176
+ bool ICACHE_FLASH_ATTR i2s_write_sample_nb (uint32_t sample ) {
177
+ if (i2s_curr_slc_buf_pos == SLC_BUF_LEN || i2s_curr_slc_buf == NULL ) {
178
+ if (i2s_slc_queue_len == 0 ){
179
+ return false;
180
+ }
181
+ ETS_SLC_INTR_DISABLE ();
182
+ i2s_curr_slc_buf = (uint32_t * )i2s_slc_queue_next_item ();
183
+ ETS_SLC_INTR_ENABLE ();
184
+ i2s_curr_slc_buf_pos = 0 ;
185
+ }
186
+ i2s_curr_slc_buf [i2s_curr_slc_buf_pos ++ ]= sample ;
187
+ return true;
188
+ }
189
+
168
190
bool ICACHE_FLASH_ATTR i2s_write_lr (int16_t left , int16_t right ){
169
191
int sample = right & 0xFFFF ;
170
192
sample = sample << 16 ;
0 commit comments