Skip to content

Commit

Permalink
Added a a rec/playback test to the StreamAPITest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnVidler committed Sep 14, 2023
1 parent efd034a commit 93b0c20
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions source/samples/StreamAPITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "CodalAssert.h"
#include "LevelDetector.h"
#include "LevelDetectorSPL.h"
#include "StreamRecording.h"
#include "Tests.h"

/**
Expand Down Expand Up @@ -43,6 +44,53 @@ void stream_test_getValue_interval() {
assert_pass( NULL );
}

void stream_test_record() {
uBit.audio.requestActivation();
static SplitterChannel * input = uBit.audio.splitter->createChannel();
static StreamRecording * recording = new StreamRecording( *input );
static MixerChannel * output = uBit.audio.mixer.addChannel( *recording );

input->requestSampleRate( 11000 );
output->setSampleRate( 11000 );
output->setVolume( CONFIG_MIXER_INTERNAL_RANGE * 0.8 ); // 80% volume

uBit.display.printChar( '3', 1000 );
uBit.display.printChar( '2', 1000 );
uBit.display.printChar( '1', 1000 );

uBit.display.printChar( 'R' );
recording->recordAsync();
while( recording->isRecording() ) {
if( uBit.buttonA.isPressed() )
input->requestSampleRate( 6600 );
uBit.display.printChar( '~' );
uBit.sleep( 100 );
uBit.display.printChar( '-' );
uBit.sleep( 100 );
}
uBit.display.printChar( 'X' );

uBit.sleep( 1000 );

uBit.display.printChar( 'P' );
output->setSampleRate( 11000 );
recording->playAsync();
while( recording->isPlaying() ) {
if( uBit.buttonB.isPressed() )
output->setSampleRate( 22000 );

uBit.display.printChar( '>' );
uBit.sleep( 100 );
uBit.display.printChar( ' ' );
uBit.sleep( 100 );
}
uBit.display.printChar( 'X' );

uBit.sleep( 1000 );

recording->erase();
}

void stream_test_all() {
stream_test_mic_activate();
stream_test_getValue_interval();
Expand Down
1 change: 1 addition & 0 deletions source/samples/Tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void deepsleep_test( int test);
void neopixel_test();
void stream_test_mic_activate();
void stream_test_getValue_interval();
void stream_test_record();
void stream_test_all();

#endif

0 comments on commit 93b0c20

Please sign in to comment.