Skip to content

Commit 8345d46

Browse files
committed
Chnages ito support audio-refactor.
Not yet tested.
1 parent ea1d2e1 commit 8345d46

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

inc/MicroBitAudio.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace codal
5555
public:
5656
static MicroBitAudio *instance; // Primary instance of MicroBitAudio, on demand activated.
5757
Mixer2 mixer; // Multi channel audio mixer
58-
NRF52ADCChannel *mic; // Microphone ADC Channel from uBit.IO
58+
NRF52ADCChannel *mic; // Microphone ADC Channel from uBit.IO
5959
StreamNormalizer *processor; // Stream Normaliser instance
6060
StreamSplitter *splitter; // Stream Splitter instance (8bit normalized output)
6161
StreamSplitter *rawSplitter; // Stream Splitter instance (raw input)
@@ -184,6 +184,8 @@ namespace codal
184184
* Puts the component in (or out of) sleep (low power) mode.
185185
*/
186186
virtual int setSleep(bool doSleep) override;
187+
188+
virtual void periodicCallback();
187189
};
188190
}
189191

source/MicroBitAudio.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR
5555
if (MicroBitAudio::instance == NULL)
5656
MicroBitAudio::instance = this;
5757

58+
// Request a periodic callback
59+
status |= DEVICE_COMPONENT_STATUS_SYSTEM_TICK;
60+
5861
synth.allowEmptyBuffers(true);
5962

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

91+
void MicroBitAudio::periodicCallback()
92+
{
93+
if (mic->isEnabled() && !micEnabled)
94+
activateMic();
95+
96+
if (!mic->isEnabled() && micEnabled)
97+
deactivateMic();
98+
}
99+
88100
void MicroBitAudio::activateMic(){
89101
runmic.setDigitalValue(1);
90102
runmic.setHighDrive(true);

0 commit comments

Comments
 (0)