@@ -112,20 +112,7 @@ static void i2s_buffer_fill(audiobusio_i2sout_obj_t* self) {
112
112
self -> next_buffer = !self -> next_buffer ;
113
113
size_t bytesleft = self -> buffer_length ;
114
114
115
- if (self -> paused || self -> stopping ) {
116
- if (self -> stopping ) {
117
- NRF_I2S -> TASKS_STOP = 1 ;
118
- self -> playing = false;
119
- }
120
- stopping : ;
121
- uint32_t * bp = (uint32_t * )buffer ;
122
- uint32_t * be = (uint32_t * )(buffer + bytesleft );
123
- for (; bp != be ; )
124
- * bp ++ = self -> hold_value ;
125
- return ;
126
- }
127
-
128
- while (bytesleft ) {
115
+ while (!self -> paused && !self -> stopping && bytesleft ) {
129
116
if (self -> sample_data == self -> sample_end ) {
130
117
uint32_t sample_buffer_length ;
131
118
audioio_get_buffer_result_t get_buffer_result =
@@ -137,12 +124,12 @@ stopping: ;
137
124
audiosample_reset_buffer (self -> sample , false, 0 );
138
125
} else {
139
126
self -> stopping = true;
140
- goto stopping ;
127
+ break ;
141
128
}
142
129
}
143
130
if (get_buffer_result == GET_BUFFER_ERROR || sample_buffer_length == 0 ) {
144
131
self -> stopping = true;
145
- goto stopping ;
132
+ break ;
146
133
}
147
134
}
148
135
uint16_t bytecount = MIN (bytesleft , (size_t )(self -> sample_end - self -> sample_data ));
@@ -180,6 +167,21 @@ stopping: ;
180
167
// For 8-bit stereo and 16-bit mono, 2 copies of the final sample are required
181
168
self -> hold_value = 0x00010001 * * (uint16_t * )(buffer - 2 );
182
169
}
170
+
171
+ // Emulate pausing and stopping by filling the DMA buffer with copies of
172
+ // the last sample. This includes the case where this iteration of
173
+ // i2s_buffer_fill exhausted a non-looping sample.
174
+ if (self -> paused || self -> stopping ) {
175
+ if (self -> stopping ) {
176
+ NRF_I2S -> TASKS_STOP = 1 ;
177
+ self -> playing = false;
178
+ }
179
+ uint32_t * bp = (uint32_t * )buffer ;
180
+ uint32_t * be = (uint32_t * )(buffer + bytesleft );
181
+ for (; bp != be ; )
182
+ * bp ++ = self -> hold_value ;
183
+ return ;
184
+ }
183
185
}
184
186
185
187
void common_hal_audiobusio_i2sout_construct (audiobusio_i2sout_obj_t * self ,
0 commit comments