Skip to content

Commit 15514ad

Browse files
committed
nRF52: Smooth transition between tracks
- When calling getADC or feedDAC functions, only enable the I2S interface, then load the buffers, then start the I2S interface instead of Enabling & Starting off the beginning - Now users can call disableDAC() and then start feeding the DAC again, and it should provide a smoother transition
1 parent f08291b commit 15514ad

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/NRF52840/AutoAnalogAudio.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@ void AutoAnalog::getADC(uint32_t samples){
258258

259259
if(useI2S == 2 || useI2S == 3){
260260

261+
262+
bool started = false;
261263
if(NRF_I2S->ENABLE == 0){
262264
NRF_I2S->ENABLE = 1;
263-
NRF_I2S->TASKS_START = 1;
265+
started = true;
266+
}else{
267+
while(NRF_I2S->EVENTS_RXPTRUPD == 0){}
264268
}
265-
266-
while(NRF_I2S->EVENTS_RXPTRUPD == 0){}
267-
268269
uint8_t divider = 2;
269270
if(adcBitsPerSample == 24){
270271
if( NRF_I2S->CONFIG.SWIDTH != I2S_CONFIG_SWIDTH_SWIDTH_24BIT << I2S_CONFIG_SWIDTH_SWIDTH_Pos){
@@ -304,8 +305,12 @@ void AutoAnalog::getADC(uint32_t samples){
304305
if(useI2S == 2 || useI2S == 3){
305306
NRF_I2S->RXTXD.MAXCNT = samples / divider;
306307
}
307-
NRF_I2S->EVENTS_RXPTRUPD = 0;
308-
308+
309+
NRF_I2S->EVENTS_RXPTRUPD = 0;
310+
if(started){
311+
NRF_I2S->TASKS_START = 1;
312+
}
313+
309314
}else{
310315
while(!adcReady){__WFE();};
311316
aSize = samples;
@@ -321,12 +326,14 @@ void AutoAnalog::feedDAC(uint8_t dacChannel, uint32_t samples, bool startInterru
321326

322327
if(useI2S == 1 || useI2S == 3){
323328

329+
bool started = false;
324330
if(NRF_I2S->ENABLE == 0){
325331
NRF_I2S->ENABLE = 1;
326-
NRF_I2S->TASKS_START = 1;
332+
started = true;
333+
}else{
334+
while(NRF_I2S->EVENTS_TXPTRUPD == 0){}
327335
}
328336

329-
while(NRF_I2S->EVENTS_TXPTRUPD == 0){}
330337
if(dacBitsPerSample == 8){
331338
if(whichBuf){
332339
for(uint32_t i=0; i< samples; i++){
@@ -375,7 +382,11 @@ void AutoAnalog::feedDAC(uint8_t dacChannel, uint32_t samples, bool startInterru
375382

376383
NRF_I2S->RXTXD.MAXCNT = samples / divider;
377384
NRF_I2S->EVENTS_TXPTRUPD = 0;
378-
385+
386+
if(started){
387+
NRF_I2S->TASKS_START = 1;
388+
}
389+
379390
}else{
380391
uint32_t timer = millis() + 1000;
381392
while(NRF_PWM0->EVENTS_SEQEND[0] == 0){

0 commit comments

Comments
 (0)