Skip to content

Commit

Permalink
Added new disable() call, and fixed some formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVidler committed May 3, 2022
1 parent 1c4f5cf commit 98d7dc9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
10 changes: 5 additions & 5 deletions inc/MicroBitAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ namespace codal
*/
static void requestActivation();

/**
* Called periodically to maintain the periperhal timout timers
*/
void periodicCallback();

/**
* Catch events from the splitter
* @param MicroBitEvent
Expand Down Expand Up @@ -125,6 +120,11 @@ namespace codal
*/
int enable();

/**
* Shut down the audio pipeline
*/
int disable();

/**
* Get the current volume.
* @return The output volume, in the range 0..255.
Expand Down
28 changes: 20 additions & 8 deletions source/MicroBitAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR

if (mic == NULL){
mic = adc.getChannel(microphone, false);
adc.setSamplePeriod( 1e6 / 22000 );
mic->setGain(7,0);
}

Expand Down Expand Up @@ -112,7 +113,8 @@ void MicroBitAudio::activateMic(){
void MicroBitAudio::deactivateMic(){
runmic.setDigitalValue(0);
runmic.setHighDrive(false);
adc.releaseChannel(microphone);
mic->disable(); // Just disable the mic channel, releasing it makes it gone forever!
//adc.releaseChannel(microphone);
}

/**
Expand All @@ -137,21 +139,31 @@ int MicroBitAudio::enable()
{
if (pwm == NULL)
{
pwm = new NRF52PWM(NRF_PWM1, mixer, 44100);
pwm->setDecoderMode(PWM_DECODER_LOAD_Common);
pwm = new NRF52PWM( NRF_PWM1, mixer, 44100 );
pwm->setDecoderMode( PWM_DECODER_LOAD_Common );

mixer.setSampleRange(pwm->getSampleRange());
mixer.setOrMask(0x8000);
mixer.setSampleRange( pwm->getSampleRange() );
mixer.setOrMask( 0x8000 );

setSpeakerEnabled(speakerEnabled);
setPinEnabled(pinEnabled);
setSpeakerEnabled( speakerEnabled );
setPinEnabled( pinEnabled );

if ( soundExpressionChannel == NULL)
if ( soundExpressionChannel == NULL )
soundExpressionChannel = mixer.addChannel(synth);
}
return DEVICE_OK;
}

int MicroBitAudio::disable()
{
setSpeakerEnabled( false );
setPinEnabled( false );

pwm->disable();

return DEVICE_OK;
}

/**
* Demand request from a component to enable the default instance of this audio pipeline
*/
Expand Down

0 comments on commit 98d7dc9

Please sign in to comment.