mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-28 01:38:46 +02:00
Implement state-machine to detect gate opening/closing. Fixes bugs with mute.
This commit is contained in:
parent
850dbd76c9
commit
175d1be7ca
2 changed files with 17 additions and 11 deletions
|
@ -1057,19 +1057,24 @@ void AudioClient::handleAudioInput(QByteArray& audioBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
emit inputReceived(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
|
// state machine to detect gate opening and closing
|
||||||
// do not send one if the gate closed in this block (eventually this can be crossfaded).
|
bool audioGateOpen = (_lastInputLoudness != 0.0f);
|
||||||
auto packetType = _shouldEchoToServer ?
|
bool openedInLastBlock = !_audioGateOpen && audioGateOpen; // the gate just opened
|
||||||
PacketType::MicrophoneAudioWithEcho : PacketType::MicrophoneAudioNoEcho;
|
bool closedInLastBlock = _audioGateOpen && !audioGateOpen; // the gate just closed
|
||||||
if (_lastInputLoudness == 0.0f && !_noiseGate.closedInLastBlock()) {
|
_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;
|
packetType = PacketType::SilentAudioFrame;
|
||||||
_silentOutbound.increment();
|
_silentOutbound.increment();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -363,6 +363,7 @@ private:
|
||||||
|
|
||||||
AudioNoiseGate _noiseGate;
|
AudioNoiseGate _noiseGate;
|
||||||
AudioGate* _audioGate { nullptr };
|
AudioGate* _audioGate { nullptr };
|
||||||
|
bool _audioGateOpen { false };
|
||||||
|
|
||||||
AudioPositionGetter _positionGetter;
|
AudioPositionGetter _positionGetter;
|
||||||
AudioOrientationGetter _orientationGetter;
|
AudioOrientationGetter _orientationGetter;
|
||||||
|
|
Loading…
Reference in a new issue