Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get recogniser and interpreter working together #1

Merged
merged 1 commit into from
May 4, 2021

Conversation

mateiBanu
Copy link
Collaborator

Example main(sends a string back and forth):

#include "MicroBit.h"
#include "MicroBitAudioProcessor.h"
#include "StreamNormalizer.h"
#include "StreamSplitter.h"
#include "MicroBitMorseInterpreter.h"
#include "MicroBitMorsePlayer.h"

MicroBitAudioProcessor *fft = NULL;
MicroBitMorseCodeRecogniser *recogniser = NULL;
MicroBitMorseInterpreter *interpreter = NULL;

MicroBit uBit;

#define FREQUENCY 2200
#define TIME_UNIT 186

void onMessage(ManagedString message){
interpreter->stopInterpreting();
uBit.display.scroll(message);
interpreter->startInterpreting(onMessage);
}

void sendMessage(MicroBitEvent){
interpreter->stopInterpreting();
char in[] = "MORSE";
MicroBitMorsePlayer mp = MicroBitMorsePlayer(uBit, FREQUENCY, TIME_UNIT);
mp.play(in);
interpreter->startInterpreting(onMessage);
}

void interpret_test(){

NRF52ADCChannel *mic = uBit.adc.getChannel(uBit.io.microphone);
mic->setGain(7,0);
uBit.io.runmic.setDigitalValue(1);
uBit.io.runmic.setHighDrive(true);

StreamNormalizer *processor = new StreamNormalizer(mic->output, 1.2f, true, DATASTREAM_FORMAT_8BIT_SIGNED, 10);
StreamSplitter *splitter = new StreamSplitter(processor->output);
fft         = new MicroBitAudioProcessor(*splitter, MORSE_AUDIO_SAMPLES_NUMBER);
recogniser  = new MicroBitMorseCodeRecogniser(*fft, uBit, FREQUENCY, TIME_UNIT);
interpreter = new MicroBitMorseInterpreter(*recogniser, uBit);
interpreter->startInterpreting(onMessage);

uBit.messageBus.listen(DEVICE_ID_BUTTON_A, DEVICE_BUTTON_EVT_CLICK, sendMessage);

while(1){
    uBit.display.print(" ");
    uBit.sleep(500);
}

}

int
main()
{

uBit.init();
interpret_test();

}

@vladturcuman vladturcuman merged commit 0d48ede into sound_recognition May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants