Skip to content

Commit

Permalink
nRF52: Smooth transition between tracks
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
TMRh20 committed Nov 2, 2024
1 parent f08291b commit 15514ad
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/NRF52840/AutoAnalogAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,14 @@ void AutoAnalog::getADC(uint32_t samples){

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


bool started = false;
if(NRF_I2S->ENABLE == 0){
NRF_I2S->ENABLE = 1;
NRF_I2S->TASKS_START = 1;
started = true;
}else{
while(NRF_I2S->EVENTS_RXPTRUPD == 0){}
}

while(NRF_I2S->EVENTS_RXPTRUPD == 0){}

uint8_t divider = 2;
if(adcBitsPerSample == 24){
if( NRF_I2S->CONFIG.SWIDTH != I2S_CONFIG_SWIDTH_SWIDTH_24BIT << I2S_CONFIG_SWIDTH_SWIDTH_Pos){
Expand Down Expand Up @@ -304,8 +305,12 @@ void AutoAnalog::getADC(uint32_t samples){
if(useI2S == 2 || useI2S == 3){
NRF_I2S->RXTXD.MAXCNT = samples / divider;
}
NRF_I2S->EVENTS_RXPTRUPD = 0;


NRF_I2S->EVENTS_RXPTRUPD = 0;
if(started){
NRF_I2S->TASKS_START = 1;
}

}else{
while(!adcReady){__WFE();};
aSize = samples;
Expand All @@ -321,12 +326,14 @@ void AutoAnalog::feedDAC(uint8_t dacChannel, uint32_t samples, bool startInterru

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

bool started = false;
if(NRF_I2S->ENABLE == 0){
NRF_I2S->ENABLE = 1;
NRF_I2S->TASKS_START = 1;
started = true;
}else{
while(NRF_I2S->EVENTS_TXPTRUPD == 0){}
}

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

NRF_I2S->RXTXD.MAXCNT = samples / divider;
NRF_I2S->EVENTS_TXPTRUPD = 0;


if(started){
NRF_I2S->TASKS_START = 1;
}

}else{
uint32_t timer = millis() + 1000;
while(NRF_PWM0->EVENTS_SEQEND[0] == 0){
Expand Down

0 comments on commit 15514ad

Please sign in to comment.