Skip to content

Commit

Permalink
Testing the recording framework shim
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVidler committed May 9, 2022
1 parent e71f0bd commit 78d1fa9
Show file tree
Hide file tree
Showing 6 changed files with 13,446 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
pxt_modules
37 changes: 37 additions & 0 deletions codal-audio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "pxt.h"
#include "MicroBit.h"
#include "StreamRecording.h"

using namespace pxt;

namespace codalAudio {

static StreamRecording * recording = NULL;

void checkEnv() {
if( recording == NULL ) {
recording = new StreamRecording( *uBit.audio.splitter );

MixerChannel * channel = uBit.audio.mixer.addChannel( *recording, CHANNEL_FREQ );

// By connecting to the mic channel, we activate it automatically, so shut it down again.
uBit.audio.deactivateMic();
uBit.audio.mic->disable();

channel->setVolume( 100.0 );
uBit.audio.mixer.setVolume( 1000 );
uBit.audio.setSpeakerEnabled( true );
}
}

//%
void record() {
codalAudio::checkEnv();
recording->record();
}

void stop() {
codalAudio::checkEnv();
recording->stop();
}
}
35 changes: 16 additions & 19 deletions codal-audio.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
enum WaitOpts {
Foreground,
Background
}

enum AudioEvent {
//% block="Starts Playing"
StartedPlaying,
Expand All @@ -14,13 +9,13 @@ enum AudioEvent {
StoppedRecording
}

enum SampleRateScope {
enum AudioSampleRateScope {
Everything,
Playback,
Recording
}

enum GainEnum {
enum AudioGainEnum {
Low,
Medium,
High
Expand All @@ -37,7 +32,8 @@ namespace codalAudio {
*
* @param sync If true, block until we run out of memory!
*/
//% block="​Start recording"
//% block="start recording"
//% shim=codalAudio::record
export function record() : void {
/* Dummy function */
}
Expand All @@ -47,10 +43,10 @@ namespace codalAudio {
*
* @param hz The sample rate, in Hz
*/
//% block="Set sample rate to %hz Hz || for %scope"
//% block="set sample rate to %hz Hz || for %scope"
//% expandableArgumentMode="enabled"
//% hz.defl=11000
export function setSampleRate( hz?: number, scope?: SampleRateScope ) : void {
export function setSampleRate( hz?: number, scope?: AudioSampleRateScope ) : void {
/* Dummy function */
}

Expand All @@ -59,9 +55,9 @@ namespace codalAudio {
*
* @param gain The gain to use.
*/
//% block="Set microphone gain to %gain"
//% block="set microphone gain to %gain"
//% gain.defl=Medium
export function setMicrophoneGain( gain?: GainEnum ) : void {
export function setMicrophoneGain( gain?: AudioGainEnum ) : void {
/* Dummy function */
}

Expand All @@ -70,43 +66,44 @@ namespace codalAudio {
*
* @param sync If true, block until complete
*/
//% block="​Start playback"
//% block="​start playback"
export function play() : void {
/* Dummy function */
}

/**
* Play and recorded audio
*/
//% block="Stop"
//% block="stop"
//% shim=codalAudio::stop
export function stop() : void {
/* Dummy function */
}

/**
* Play and recorded audio
*/
//% block="Erase recording"
//% block="erase recording"
export function erase() : void {
/* Dummy function */
}

//% block="Audio is playing"
//% block="audio is playing"
export function audioIsPlaying() : boolean {
return false;
}

//% block="Audio is recording"
//% block="audio is recording"
export function audioIsRecording() : boolean {
return false;
}

//% block="Audio is stopped"
//% block="audio is stopped"
export function audioIsStopped() : boolean {
return false;
}

//% block="When audio %eventType"
//% block="when audio %eventType"
export function audioEvent( eventType: AudioEvent, handler: () => void ) : void {
/* Dummy function */
}
Expand Down
Loading

0 comments on commit 78d1fa9

Please sign in to comment.