Now using a local stream normalizer to change recording mic gain
This commit is contained in:
Родитель
9f88afcb89
Коммит
69608fd738
|
@ -31,17 +31,7 @@ namespace record {
|
||||||
static StreamRecording *recording = NULL;
|
static StreamRecording *recording = NULL;
|
||||||
static SplitterChannel *splitterChannel = NULL;
|
static SplitterChannel *splitterChannel = NULL;
|
||||||
static MixerChannel *channel = NULL;
|
static MixerChannel *channel = NULL;
|
||||||
|
static StreamNormalizer *localProcessor = NULL;
|
||||||
void enableMic() {
|
|
||||||
uBit.audio.activateMic();
|
|
||||||
uBit.audio.mic->enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void disableMic() {
|
|
||||||
uBit.audio.mic->disable();
|
|
||||||
uBit.audio.deactivateMic();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void checkEnv(int sampleRate = -1) {
|
void checkEnv(int sampleRate = -1) {
|
||||||
if (recording == NULL) {
|
if (recording == NULL) {
|
||||||
|
@ -50,8 +40,8 @@ void checkEnv(int sampleRate = -1) {
|
||||||
MicroBitAudio::requestActivation();
|
MicroBitAudio::requestActivation();
|
||||||
|
|
||||||
splitterChannel = uBit.audio.splitter->createChannel();
|
splitterChannel = uBit.audio.splitter->createChannel();
|
||||||
|
localProcessor = new StreamNormalizer(*splitterChannel);
|
||||||
recording = new StreamRecording(*splitterChannel);
|
recording = new StreamRecording(localProcessor->output);
|
||||||
|
|
||||||
channel = uBit.audio.mixer.addChannel(*recording, sampleRate);
|
channel = uBit.audio.mixer.addChannel(*recording, sampleRate);
|
||||||
|
|
||||||
|
@ -72,7 +62,6 @@ void checkEnv(int sampleRate = -1) {
|
||||||
//% promise
|
//% promise
|
||||||
void record() {
|
void record() {
|
||||||
checkEnv();
|
checkEnv();
|
||||||
enableMic();
|
|
||||||
recording->record();
|
recording->record();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +71,6 @@ void record() {
|
||||||
//%
|
//%
|
||||||
void play() {
|
void play() {
|
||||||
checkEnv();
|
checkEnv();
|
||||||
disableMic();
|
|
||||||
recording->play();
|
recording->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +80,6 @@ void play() {
|
||||||
//%
|
//%
|
||||||
void stop() {
|
void stop() {
|
||||||
checkEnv();
|
checkEnv();
|
||||||
disableMic();
|
|
||||||
recording->stop();
|
recording->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +89,6 @@ void stop() {
|
||||||
//%
|
//%
|
||||||
void erase() {
|
void erase() {
|
||||||
checkEnv();
|
checkEnv();
|
||||||
disableMic();
|
|
||||||
recording->erase();
|
recording->erase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,15 +97,16 @@ void erase() {
|
||||||
*/
|
*/
|
||||||
//%
|
//%
|
||||||
void setMicrophoneGain(int gain) {
|
void setMicrophoneGain(int gain) {
|
||||||
|
checkEnv();
|
||||||
switch (gain) {
|
switch (gain) {
|
||||||
case 1:
|
case 1:
|
||||||
uBit.audio.processor->setGain(0.079f);
|
localProcessor->setGain(0.5f);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
uBit.audio.processor->setGain(0.2f);
|
localProcessor->setGain(1.0f);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
uBit.audio.processor->setGain(0.4f);
|
localProcessor->setGain(2.0f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче