Skip to content

Commit

Permalink
Merge PR mumble-voip#5926: FEAT(client): Always stop audio on/off cue…
Browse files Browse the repository at this point in the history
… when switching state

Previously, audio cues would play and continue to play no matter what. If very long sound samples were used, they would play longer than the user sends audio (regardless of PTT or VA) and they could even play over each other.

Fixes mumble-voip#1671
  • Loading branch information
Krzmbrzl authored Jan 3, 2023
2 parents 6516951 + d79850c commit 33c7d91
Show file tree
Hide file tree
Showing 19 changed files with 256 additions and 136 deletions.
1 change: 1 addition & 0 deletions src/mumble/API_v_1_x_x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "API.h"
#include "AudioOutput.h"
#include "AudioOutputToken.h"
#include "Channel.h"
#include "ClientUser.h"
#include "Database.h"
Expand Down
2 changes: 1 addition & 1 deletion src/mumble/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ RecordUser::RecordUser() {
RecordUser::~RecordUser() {
AudioOutputPtr ao = Global::get().ao;
if (ao)
ao->removeBuffer(this);
ao->removeUser(this);
}

void RecordUser::addFrame(const Mumble::Protocol::AudioData &audioData) {
Expand Down
15 changes: 10 additions & 5 deletions src/mumble/AudioConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "AudioInput.h"
#include "AudioOutput.h"
#include "AudioOutputSample.h"
#include "AudioOutputToken.h"
#include "NetworkConfig.h"
#include "Utils.h"
#include "Global.h"
Expand Down Expand Up @@ -411,11 +412,14 @@ void AudioInputDialog::on_qpbPushClickBrowseOff_clicked() {
void AudioInputDialog::on_qpbPushClickPreview_clicked() {
AudioOutputPtr ao = Global::get().ao;
if (ao) {
AudioOutputSample *sample = ao->playSample(qlePushClickPathOn->text(), Global::get().s.cueVolume);
if (sample)
connect(sample, SIGNAL(playbackFinished()), this, SLOT(continuePlayback()));
else // If we fail to playback the first play on play at least off
AudioOutputToken sample = ao->playSample(qlePushClickPathOn->text(), Global::get().s.cueVolume);
if (sample) {
sample.connect< AudioOutputSample >(&AudioOutputSample::playbackFinished, *this,
&AudioInputDialog::continuePlayback);
} else {
// If we fail to playback the first play on play at least off
ao->playSample(qlePushClickPathOff->text(), Global::get().s.cueVolume);
}
}
}

Expand All @@ -435,8 +439,9 @@ void AudioInputDialog::on_qpbMuteCueBrowse_clicked() {

void AudioInputDialog::on_qpbMuteCuePreview_clicked() {
AudioOutputPtr ao = Global::get().ao;
if (ao)
if (ao) {
ao->playSample(qleMuteCuePath->text(), Global::get().s.cueVolume);
}
}

void AudioInputDialog::continuePlayback() {
Expand Down
17 changes: 13 additions & 4 deletions src/mumble/AudioInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,19 @@ void AudioInput::encodeAudioFrame(AudioChunk chunk) {

if (ao) {
if (Global::get().s.bTxAudioCue) {
if (bIsSpeech && !bPreviousVoice) {
ao->playSample(Global::get().s.qsTxAudioCueOn, Global::get().s.cueVolume);
} else if (!bIsSpeech && bPreviousVoice) {
ao->playSample(Global::get().s.qsTxAudioCueOff, Global::get().s.cueVolume);
const bool playAudioOnCue = bIsSpeech && !bPreviousVoice;
const bool playAudioOffCue = !bIsSpeech && bPreviousVoice;
const bool stopActiveCue = m_activeAudioCue && (playAudioOnCue || playAudioOffCue);

if (stopActiveCue) {
// Cancel active cue first, if there is any
ao->removeToken(m_activeAudioCue);
}

if (playAudioOnCue) {
m_activeAudioCue = ao->playSample(Global::get().s.qsTxAudioCueOn, Global::get().s.cueVolume);
} else if (playAudioOffCue) {
m_activeAudioCue = ao->playSample(Global::get().s.qsTxAudioCueOff, Global::get().s.cueVolume);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/mumble/AudioInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <speex/speex_resampler.h>

#include "Audio.h"
#include "AudioOutputToken.h"
#include "EchoCancelOption.h"
#include "MumbleProtocol.h"
#include "Settings.h"
Expand Down Expand Up @@ -197,6 +198,8 @@ class AudioInput : public QThread {

QElapsedTimer qetLastMuteCue;

AudioOutputToken m_activeAudioCue;

protected:
Mumble::Protocol::AudioCodec m_codec;
SampleFormat eMicFormat, eEchoFormat;
Expand Down
Loading

0 comments on commit 33c7d91

Please sign in to comment.