Skip to content

Commit

Permalink
EarpieceMixer: change tmp buffers and expand comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chipaudette committed Sep 23, 2021
1 parent 5152bc1 commit 072e26f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
36 changes: 21 additions & 15 deletions src/EarpieceMixer_F32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,33 @@
void EarpieceMixerBase_F32::update(void) {

//allocate the input and output audio memory...if successfull, we must remember to release all of these audio blocks
audio_block_f32_t *audio_in[4], *tmp[6], *audio_out[2];
if (allocateAndGetAudioBlocks(audio_in, tmp, audio_out) == false) return; //If it fails, we stop and return. If success, we continue.
audio_block_f32_t *audio_in[4], *tmp[8], *audio_out[2];
if (allocateAndGetAudioBlocks(audio_in, tmp, audio_out) == false) {
//Serial.println("EarpieceMixerBase_F32: update: failed to allocated audio blocks!");
return; //If it fails, we stop and return. If success, we continue.
}

//do the work
processData(audio_in, tmp, audio_out);

//transmit the output
AudioStream_F32::transmit(audio_out[0], 0); AudioStream_F32::transmit(audio_out[1], 1);

//release all the memory
for (int i = 0; i < 6; i++) AudioStream_F32::release(tmp[i]);
//release all the memory that was allocated in allocateAndGetAudioBlocks()
for (int i = 0; i < 8; i++) AudioStream_F32::release(tmp[i]);
for (int i = 0; i < 2; i++) AudioStream_F32::release(audio_out[i]);
for (int i = 0; i < 4; i++) AudioStream_F32::release(audio_in[i]);

//we're done!
}

//the audio_in must be writable and the audio-out must also be writable
void EarpieceMixerBase_F32::processData(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[6], audio_block_f32_t *audio_out[2]) {
audio_block_f32_t *tmp_out_left = tmp[4];
audio_block_f32_t *tmp_out_right = tmp[5];
void EarpieceMixerBase_F32::processData(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[8], audio_block_f32_t *audio_out[2]) {
//tmp[0]-tmp[3] are used to temporarily hold the delayed versions of the four mic signals
audio_block_f32_t *pdm_mix_left = tmp[4];
audio_block_f32_t *pdm_mix_right = tmp[5];
audio_block_f32_t *tmp_out_left = tmp[6];
audio_block_f32_t *tmp_out_right = tmp[7];
audio_block_f32_t *tmp_input[4]; //each mixer assumes that it's getting a 4-element array of audio pointers

//apply delay to each mic channel
Expand All @@ -45,19 +51,19 @@ void EarpieceMixerBase_F32::processData(audio_block_f32_t *audio_in[4], audio_bl
//AudioConnection_F32 patchcord9(rearMicDelayR, 0, frontRearMixer[RIGHT], REAR);
for (int i=0; i<4; i++) tmp_input[i]=NULL; //clear the temporary inputs
tmp_input[FRONT] = tmp[PDM_LEFT_FRONT]; tmp_input[REAR] = tmp[PDM_LEFT_REAR]; //put the left-earpiece audio into the temp array
frontRearMixer[LEFT].processData(tmp_input, tmp_out_left); //process to make a mix from the left earpiece
frontRearMixer[LEFT].processData(tmp_input, pdm_mix_left); //process to make a mix from the left earpiece
tmp_input[FRONT] = tmp[PDM_RIGHT_FRONT]; tmp_input[REAR] = tmp[PDM_RIGHT_REAR]; //put the right-earpiece audio into the temp array
frontRearMixer[RIGHT].processData(tmp_input, tmp_out_right); //process to make a mix from the right earpiece
frontRearMixer[RIGHT].processData(tmp_input, pdm_mix_right); //process to make a mix from the right earpiece

//switch between digital inputs or analog inputs
//AudioConnection_F32 patchcord11(i2s_in, LEFT, analogVsDigitalSwitch[LEFT], ANALOG_IN);
//AudioConnection_F32 patchcord12(frontRearMixer[LEFT], 0, analogVsDigitalSwitch[LEFT], PDM_IN);
//AudioConnection_F32 patchcord13(i2s_in, RIGHT, analogVsDigitalSwitch[RIGHT], ANALOG_IN);
//AudioConnection_F32 patchcord14(frontRearMixer[RIGHT], 0, analogVsDigitalSwitch[RIGHT], PDM_IN);
for (int i=0; i<4; i++) tmp_input[i]=NULL; //clear the temporary inputs
tmp_input[INPUT_ANALOG] = audio_in[LEFT]; tmp_input[INPUT_PDM] = tmp_out_left;
tmp_input[INPUT_ANALOG] = audio_in[LEFT]; tmp_input[INPUT_PDM] = pdm_mix_left;
analogVsDigitalSwitch[LEFT].processData(tmp_input, tmp_out_left); //will overrite the tmp_out_left (which is also part of the tmp_input array)
tmp_input[INPUT_ANALOG] = audio_in[RIGHT]; tmp_input[INPUT_PDM] = tmp_out_right;
tmp_input[INPUT_ANALOG] = audio_in[RIGHT]; tmp_input[INPUT_PDM] = pdm_mix_right;
analogVsDigitalSwitch[RIGHT].processData(tmp_input, tmp_out_right); //will overrite the tmp_out_right (which is also part of the tmp_input array)

//do the left-right mixing
Expand All @@ -71,7 +77,7 @@ void EarpieceMixerBase_F32::processData(audio_block_f32_t *audio_in[4], audio_bl
leftRightMixer[RIGHT].processData(tmp_input, audio_out[RIGHT]); //process to make a mix for the left output
};

bool EarpieceMixerBase_F32::allocateAndGetAudioBlocks(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[6], audio_block_f32_t *audio_out[2]) {
bool EarpieceMixerBase_F32::allocateAndGetAudioBlocks(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[8], audio_block_f32_t *audio_out[2]) {

bool any_data_present = false;
if ((audio_out[0] = allocate_f32()) == NULL) return false;
Expand Down Expand Up @@ -108,13 +114,13 @@ bool EarpieceMixerBase_F32::allocateAndGetAudioBlocks(audio_block_f32_t *audio_i

//allocate a bunch of working memory
bool any_allocate_fail = false;
for (int i = 0; i < 6; i++) {
for (int i = 0; i < 8; i++) {
tmp[i] = allocate_f32();
if (tmp[i] == NULL) any_allocate_fail = true;
}
if (any_allocate_fail) {
//we must be out of audio memory...so release any buffers that were allocated and then return
for (int i = 0; i < 6; i++) { if (tmp[i]) AudioStream_F32::release(tmp[i]); }
for (int i = 0; i < 8; i++) { if (tmp[i]) AudioStream_F32::release(tmp[i]); }
for (int Ichan = 0; Ichan < 4; Ichan++) {if (audio_in[Ichan]) AudioStream_F32::release(audio_in[Ichan]);}
for (int Ichan = 0; Ichan < 2; Ichan++) {if (audio_out[Ichan]) AudioStream_F32::release(audio_out[Ichan]);}
return false;
Expand Down Expand Up @@ -161,7 +167,7 @@ int EarpieceMixer_F32::setInputAnalogVsPDM(int input) {

switch (input) {
case EarpieceMixerState::INPUT_PDM:
myTympan->enableDigitalMicInputs(true); //two of the earpiece digital mics are routed here
myTympan->enableDigitalMicInputs(true); //two of the earpiece digital mics are routed here
earpieceShield->enableDigitalMicInputs(true); //the other two of the earpiece digital mics are routed here
analogVsDigitalSwitch[LEFT].switchChannel(input);
analogVsDigitalSwitch[RIGHT].switchChannel(input);
Expand Down
4 changes: 2 additions & 2 deletions src/EarpieceMixer_F32.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class EarpieceMixerBase_F32 : public AudioStream_F32 {

//primary processing methods
virtual void update(void);
virtual void processData(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[6], audio_block_f32_t *audio_out[2]);
virtual void processData(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[8], audio_block_f32_t *audio_out[2]);

//Audio classes used here
AudioEffectDelay_F32 frontMicDelay[2]; //delays front microphone (left and right)
Expand All @@ -98,7 +98,7 @@ class EarpieceMixerBase_F32 : public AudioStream_F32 {
audio_block_f32_t *inputQueueArray_f32[4]; //memory pointer for the input to this module

//supporting methods
bool allocateAndGetAudioBlocks(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[6], audio_block_f32_t *audio_out[2]);
bool allocateAndGetAudioBlocks(audio_block_f32_t *audio_in[4], audio_block_f32_t *tmp[8], audio_block_f32_t *audio_out[2]);

};

Expand Down
24 changes: 12 additions & 12 deletions src/EarpieceMixer_F32_UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,51 @@ bool EarpieceMixer_F32_UI::processCharacterTriple(char mode_char, char chan_char
return_val = true;
switch (c) {
case 'w':
Serial.println("Received: Listen to PCB mics");
Serial.println("EarpieceMixer_F32_UI: Received: Listen to PCB mics");
setInputAnalogVsPDM(EarpieceMixerState::INPUT_ANALOG);
setAnalogInputSource(EarpieceMixerState::INPUT_PCBMICS);
setInputConfigButtons();
setButtonState_frontRearMixer();
break;
case 'W':
Serial.println("Received: Mic jack as mic");
Serial.println("EarpieceMixer_F32_UI: Received: Mic jack as mic");
setInputAnalogVsPDM(EarpieceMixerState::INPUT_ANALOG);
setAnalogInputSource(EarpieceMixerState::INPUT_MICJACK_MIC);
setInputConfigButtons();
setButtonState_frontRearMixer();
break;
case 'e':
Serial.println("Received: Mic jack as line-in");
Serial.println("EarpieceMixer_F32_UI: Received: Mic jack as line-in");
setInputAnalogVsPDM(EarpieceMixerState::INPUT_ANALOG);
setAnalogInputSource(EarpieceMixerState::INPUT_MICJACK_LINEIN);
setInputConfigButtons();
setButtonState_frontRearMixer();
break;
case 'E':
Serial.println("Received: Switch to BT Audio");
Serial.println("EarpieceMixer_F32_UI: Received: Switch to BT Audio");
setInputAnalogVsPDM(EarpieceMixerState::INPUT_ANALOG);
setAnalogInputSource(EarpieceMixerState::INPUT_LINEIN_SE);
setInputConfigButtons();
setButtonState_frontRearMixer();
break;
case 'd':
Serial.println("Received: Listen to PDM mics"); //digital mics
Serial.println("EarpieceMixer_F32_UI: Received: Listen to PDM mics"); //digital mics
setInputAnalogVsPDM(EarpieceMixerState::INPUT_PDM);
setInputConfigButtons();
setButtonState_frontRearMixer();
break;
case 't':
Serial.println("Received: Front Mics (if using earpieces)");
Serial.println("EarpieceMixer_F32_UI: Received: Front Mics (if using earpieces)");
configureFrontRearMixer(EarpieceMixerState::MIC_FRONT);
setButtonState_frontRearMixer();
break;
case 'T':
Serial.println("Received: Mix of Front Mics + Inverted Rear Mics");
Serial.println("EarpieceMixer_F32_UI: Received: Mix of Front Mics + Inverted Rear Mics");
configureFrontRearMixer(EarpieceMixerState::MIC_BOTH_INVERTED);
setButtonState_frontRearMixer();
break;
case 'H':
Serial.println("Received: Rear Mics (if using earpieces)");
Serial.println("EarpieceMixer_F32_UI: Received: Rear Mics (if using earpieces)");
configureFrontRearMixer(EarpieceMixerState::MIC_REAR);
setButtonState_frontRearMixer();
break;
Expand Down Expand Up @@ -112,26 +112,26 @@ bool EarpieceMixer_F32_UI::processCharacterTriple(char mode_char, char chan_char
break;
case 'q':
configureLeftRightMixer(EarpieceMixerState::INPUTMIX_MUTE);
Serial.println("Received: Muting audio.");
Serial.println("EarpieceMixer_F32_UI: Received: Muting audio.");
setButtonState_inputMixer();
break;
case 'Q':
configureLeftRightMixer(state.input_mixer_nonmute_config);
setButtonState_inputMixer();
break;
case 'B':
Serial.println("Received: Input: Mix L+R.");
Serial.println("EarpieceMixer_F32_UI: Received: Input: Mix L+R.");
configureLeftRightMixer(EarpieceMixerState::INPUTMIX_MONO);
setButtonState_inputMixer();
break;
case 's':
configureLeftRightMixer(EarpieceMixerState::INPUTMIX_BOTHLEFT);
Serial.println("Received: Input: Both Left.");
Serial.println("EarpieceMixer_F32_UI: Received: Input: Both Left.");
setButtonState_inputMixer();
break;
case 'S':
configureLeftRightMixer(EarpieceMixerState::INPUTMIX_BOTHRIGHT);
Serial.println("Received: Input: Both Right.");
Serial.println("EarpieceMixer_F32_UI: Received: Input: Both Right.");
setButtonState_inputMixer();
break;
default:
Expand Down
4 changes: 2 additions & 2 deletions src/control_aic3206.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ bool AudioControlAIC3206::enableDigitalMicInputs(bool desired_state) {

return true;
} else {
//change the AIC's pin "MFP4" to clock input for digital microphone
//change the AIC's pin "MFP4"
aic_writePage(0,55,0b00000010); //page 0, register 55, set to "disabled" ??? is this the default state?

//change the IAC's pin "MFP3" to Digital Microphone input
//change the AIC's pin "MFP3"
aic_writePage(0,56,0b00000010); //page 0, register 56, set to "disabled" ??? is this the default state?

//change the ADC to NOT use the digital mic
Expand Down

0 comments on commit 072e26f

Please sign in to comment.