Implement state-machine to detect gate opening/closing. Fixes bugs with mute.

This commit is contained in:
Ken Cooke 2017-05-23 12:32:41 -07:00
parent 850dbd76c9
commit 175d1be7ca
2 changed files with 17 additions and 11 deletions

View file

@ -1057,19 +1057,24 @@ void AudioClient::handleAudioInput(QByteArray& audioBuffer) {
}
emit inputReceived(audioBuffer);
if (_noiseGate.openedInLastBlock()) {
emit noiseGateOpened();
} else if (_noiseGate.closedInLastBlock()) {
emit noiseGateClosed();
}
}
// the codec needs a flush frame before sending silent packets, so
// do not send one if the gate closed in this block (eventually this can be crossfaded).
auto packetType = _shouldEchoToServer ?
PacketType::MicrophoneAudioWithEcho : PacketType::MicrophoneAudioNoEcho;
if (_lastInputLoudness == 0.0f && !_noiseGate.closedInLastBlock()) {
// state machine to detect gate opening and closing
bool audioGateOpen = (_lastInputLoudness != 0.0f);
bool openedInLastBlock = !_audioGateOpen && audioGateOpen; // the gate just opened
bool closedInLastBlock = _audioGateOpen && !audioGateOpen; // the gate just closed
_audioGateOpen = audioGateOpen;
if (openedInLastBlock) {
emit noiseGateOpened();
} else if (closedInLastBlock) {
emit noiseGateClosed();
}
// the codec must be flushed to silence before sending silent packets,
// so delay the transition to silent packets by one packet after becoming silent.
auto packetType = _shouldEchoToServer ? PacketType::MicrophoneAudioWithEcho : PacketType::MicrophoneAudioNoEcho;
if (!audioGateOpen && !closedInLastBlock) {
packetType = PacketType::SilentAudioFrame;
_silentOutbound.increment();
} else {

View file

@ -363,6 +363,7 @@ private:
AudioNoiseGate _noiseGate;
AudioGate* _audioGate { nullptr };
bool _audioGateOpen { false };
AudioPositionGetter _positionGetter;
AudioOrientationGetter _orientationGetter;