Skip to content

Commit

Permalink
Added option to dump the audio streams to debug the echo canceller
Browse files Browse the repository at this point in the history
  • Loading branch information
fedetft committed May 11, 2020
1 parent 54eb261 commit b3aa5de
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/mumble/AudioInput.cpp
Expand Up @@ -76,6 +76,15 @@ bool AudioInputRegistrar::canExclusive() const {
}

AudioInput::AudioInput() : opusBuffer(g.s.iFramesPerPacket * (SAMPLE_RATE / 100)) {

bDebugDumpInput = g.bDebugDumpInput;
if(bDebugDumpInput)
{
outMic.open("raw_microphone_dump", std::ios::binary);
outSpeaker.open("speaker_dump", std::ios::binary);
outProcessed.open("processed_microphone_dump", std::ios::binary);
}

adjustBandwidth(g.iMaxBandwidth, iAudioQuality, iAudioFrames, bAllowLowDelay);

g.iAudioBandwidth = getNetworkBandwidth(iAudioQuality, iAudioFrames);
Expand Down Expand Up @@ -555,10 +564,15 @@ void AudioInput::addEcho(const void *data, unsigned int nsamp) {
outbuff[j] = static_cast<short>(ptr[j] * mul);

// Push frame into the echo chancellers jitter buffer
QMutexLocker l(&qmEcho);
int queueLength;
{
QMutexLocker l(&qmEcho);

iJitterSeq = qMin(iJitterSeq + 1,10000U);
qlEchoFrames.append(outbuff);
iJitterSeq = qMin(iJitterSeq + 1,10000U);
qlEchoFrames.append(outbuff);
queueLength = qlEchoFrames.size();
}
if(bDebugDumpInput) printf("Queue=%d\n",queueLength);
}
}
}
Expand Down Expand Up @@ -869,6 +883,14 @@ void AudioInput::encodeAudioFrame() {
sum += static_cast<float>(psSource[i] * psSource[i]);
float micLevel = sqrtf(sum / static_cast<float>(iFrameSize));
dPeakSignal = qMax(20.0f*log10f(micLevel / 32768.0f), -96.0f);

if(bDebugDumpInput)
{
outMic.write(reinterpret_cast<const char*>(psMic),iFrameSize*sizeof(short));
if(psSpeaker)
outSpeaker.write(reinterpret_cast<const char*>(psSpeaker),iFrameSize*sizeof(short));
outProcessed.write(reinterpret_cast<const char*>(psSource),iFrameSize*sizeof(short));
}

spx_int32_t prob = 0;
speex_preprocess_ctl(sppPreprocess, SPEEX_PREPROCESS_GET_PROB, &prob);
Expand Down
5 changes: 5 additions & 0 deletions src/mumble/AudioInput.h
Expand Up @@ -15,6 +15,7 @@
#include <QtCore/QObject>
#include <QtCore/QThread>
#include <vector>
#include <fstream>

#include "Audio.h"
#include "Settings.h"
Expand Down Expand Up @@ -62,6 +63,10 @@ class AudioInput : public QThread {
typedef enum { SampleShort, SampleFloat } SampleFormat;
typedef void (*inMixerFunc)(float * RESTRICT, const void * RESTRICT, unsigned int, unsigned int, quint64);
private:

bool bDebugDumpInput;
std::ofstream outMic, outSpeaker, outProcessed;

SpeexResamplerState *srsMic, *srsEcho;

QMutex qmEcho;
Expand Down
1 change: 1 addition & 0 deletions src/mumble/Global.cpp
Expand Up @@ -113,6 +113,7 @@ Global::Global() {
bHappyEaster = false;

bQuit = false;
bDebugDumpInput = false;

QStringList qsl;
qsl << QCoreApplication::instance()->applicationDirPath();
Expand Down
1 change: 1 addition & 0 deletions src/mumble/Global.h
Expand Up @@ -97,6 +97,7 @@ struct Global Q_DECL_FINAL {
unsigned int uiImageLength;
unsigned int uiMaxUsers;
bool bQuit;
bool bDebugDumpInput;

bool bHappyEaster;
static const char ccHappyEaster[];
Expand Down
8 changes: 8 additions & 0 deletions src/mumble/main.cpp
Expand Up @@ -170,6 +170,12 @@ int main(int argc, char **argv) {
" Show the Mumble authors.\n"
" --third-party-licenses\n"
" Show licenses for third-party software used by Mumble.\n"
" --dump-input-streams\n"
" Dump pcm streams at various parts of the input chain\n"
" (useful for debugging purposes)\n"
" - raw microphone input\n"
" - speaker readback for echo cancelling\n"
" - processed microphone input\n"
"\n"
);
QString rpcHelpBanner = MainWindow::tr(
Expand Down Expand Up @@ -240,6 +246,8 @@ int main(int argc, char **argv) {
#endif
return 1;
}
} else if (args.at(i) == QLatin1String("--dump-input-streams")) {
g.bDebugDumpInput = true;
} else {
if (!bRpcMode) {
QUrl u = QUrl::fromEncoded(args.at(i).toUtf8());
Expand Down

0 comments on commit b3aa5de

Please sign in to comment.