Skip to content

Commit

Permalink
Chnages ito support audio-refactor.
Browse files Browse the repository at this point in the history
Not yet tested.
  • Loading branch information
finneyj committed Nov 26, 2024
1 parent ea1d2e1 commit 8345d46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion inc/MicroBitAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace codal
public:
static MicroBitAudio *instance; // Primary instance of MicroBitAudio, on demand activated.
Mixer2 mixer; // Multi channel audio mixer
NRF52ADCChannel *mic; // Microphone ADC Channel from uBit.IO
NRF52ADCChannel *mic; // Microphone ADC Channel from uBit.IO
StreamNormalizer *processor; // Stream Normaliser instance
StreamSplitter *splitter; // Stream Splitter instance (8bit normalized output)
StreamSplitter *rawSplitter; // Stream Splitter instance (raw input)
Expand Down Expand Up @@ -184,6 +184,8 @@ namespace codal
* Puts the component in (or out of) sleep (low power) mode.
*/
virtual int setSleep(bool doSleep) override;

virtual void periodicCallback();
};
}

Expand Down
12 changes: 12 additions & 0 deletions source/MicroBitAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR
if (MicroBitAudio::instance == NULL)
MicroBitAudio::instance = this;

// Request a periodic callback
status |= DEVICE_COMPONENT_STATUS_SYSTEM_TICK;

synth.allowEmptyBuffers(true);

mic = adc.getChannel(microphone, false);
Expand Down Expand Up @@ -85,6 +88,15 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR
splitter = new StreamSplitter(processor->output, DEVICE_ID_SPLITTER);
}

void MicroBitAudio::periodicCallback()
{
if (mic->isEnabled() && !micEnabled)
activateMic();

if (!mic->isEnabled() && micEnabled)
deactivateMic();
}

void MicroBitAudio::activateMic(){
runmic.setDigitalValue(1);
runmic.setHighDrive(true);
Expand Down

0 comments on commit 8345d46

Please sign in to comment.