diff options
author | Thorvald Natvig <slicer@users.sourceforge.net> | 2007-11-23 15:26:51 +0300 |
---|---|---|
committer | Thorvald Natvig <slicer@users.sourceforge.net> | 2007-11-23 15:26:51 +0300 |
commit | 7ae7fb67d019562fe717e687468c4fa231d39b55 (patch) | |
tree | 9c186668779b82f57dfd6c54c79a0c2bf55ccf70 /src | |
parent | 0133055af478dccef681b1a83077c3218ed1ec7a (diff) |
Better audio path detection. Fix race bug in AudioOutput
git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@871 05730e5d-ab1b-0410-a4ac-84af385074fa
Diffstat (limited to 'src')
-rw-r--r-- | src/mumble/ALSAAudio.cpp | 8 | ||||
-rw-r--r-- | src/mumble/ASIOInput.cpp | 5 | ||||
-rw-r--r-- | src/mumble/AudioInput.cpp | 20 | ||||
-rw-r--r-- | src/mumble/AudioInput.h | 2 | ||||
-rw-r--r-- | src/mumble/AudioOutput.cpp | 6 | ||||
-rw-r--r-- | src/mumble/AudioOutput.h | 2 | ||||
-rw-r--r-- | src/mumble/AudioWizard.cpp | 17 | ||||
-rw-r--r-- | src/mumble/DXAudioInput.cpp | 4 | ||||
-rw-r--r-- | src/mumble/GlobalShortcut_unix.h | 2 | ||||
-rw-r--r-- | src/mumble/OSS.cpp | 7 | ||||
-rw-r--r-- | src/mumble/PAAudio.cpp | 2 | ||||
-rw-r--r-- | src/mumble/PulseAudio.cpp | 5 | ||||
-rw-r--r-- | src/mumble/PulseAudio.h | 1 |
13 files changed, 51 insertions, 30 deletions
diff --git a/src/mumble/ALSAAudio.cpp b/src/mumble/ALSAAudio.cpp index 0f9f6f3a0..1dc360fdc 100644 --- a/src/mumble/ALSAAudio.cpp +++ b/src/mumble/ALSAAudio.cpp @@ -283,6 +283,7 @@ void ALSAConfig::on_qsOutputDelay_valueChanged(int v) { } ALSAAudioInput::ALSAAudioInput() { + bRunning = true; } ALSAAudioInput::~ALSAAudioInput() { @@ -306,7 +307,6 @@ void ALSAAudioInput::run() { unsigned int rrate = SAMPLE_RATE; bool bOk = true; - bRunning = true; int err = 0; qWarning("ALSAAudioInput: Initing audiocapture %s.",device_name.data()); @@ -438,6 +438,7 @@ void ALSAAudioOutput::initialize(snd_pcm_t * &pcm_handle, int period) { ALSAAudioOutput::ALSAAudioOutput() { qWarning("ALSAAudioOutput: Initialized"); + bRunning = true; } ALSAAudioOutput::~ALSAAudioOutput() { @@ -457,8 +458,6 @@ void ALSAAudioOutput::run() { initialize(pcm_handle, iFrameSize); - bRunning = true; - if (! pcm_handle) return; @@ -468,11 +467,9 @@ void ALSAAudioOutput::run() { for (int i=0;i<iFrameSize;i++) zerobuff[i]=0; - count = snd_pcm_poll_descriptors_count(pcm_handle); snd_pcm_poll_descriptors(pcm_handle, fds, count); - while (bRunning) { poll(fds, count, 20); unsigned short revents; @@ -511,4 +508,5 @@ void ALSAAudioOutput::run() { } } } + snd_pcm_close(pcm_handle); } diff --git a/src/mumble/ASIOInput.cpp b/src/mumble/ASIOInput.cpp index 2394fc47e..1134695a0 100644 --- a/src/mumble/ASIOInput.cpp +++ b/src/mumble/ASIOInput.cpp @@ -460,8 +460,10 @@ ASIOInput::ASIOInput() { asioCallbacks.asioMessage = &asioMessages; asioCallbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfo; - if (iasio->createBuffers(abiInfo, idx, 960, &asioCallbacks) == ASE_OK) + if (iasio->createBuffers(abiInfo, idx, 960, &asioCallbacks) == ASE_OK) { + bRunning = true; return; + } } } } @@ -512,7 +514,6 @@ ASIOInput::~ASIOInput() { void ASIOInput::run() { QMutex m; m.lock(); - bRunning = true; if (iasio) { aiSelf = this; iasio->start(); diff --git a/src/mumble/AudioInput.cpp b/src/mumble/AudioInput.cpp index 6e7c3187d..a1a6905bc 100644 --- a/src/mumble/AudioInput.cpp +++ b/src/mumble/AudioInput.cpp @@ -280,14 +280,24 @@ void AudioInput::encodeAudioFrame() { for(i=0;i<iFrameSize;i++) in[i] = psMic[i]; spx_fft(fftTable, in, out); + double power[iFrameSize]; double mp = 0.0; - for(i=2;i<50;i++) { - double power = out[2*i]*out[2*i]+out[2*i-1]*out[2*i-1]; - if (power > mp) { - iBestBin=2*i; - mp = power; + int bin = 0; + power[0]=power[1]=0.0; + for(i=2;i < iFrameSize / 2;i++) { + power[i] = sqrt(out[2*i]*out[2*i]+out[2*i-1]*out[2*i-1]); + if (power[i] > mp) { + bin = i; + mp = power[i]; } } + for(i=2;i< iFrameSize / 2;i++) { + if (power[i] * 2 > mp) { + if (i != bin) + bin = 0; + } + } + iBestBin = bin * 2; } if (bHasSpeaker) { diff --git a/src/mumble/AudioInput.h b/src/mumble/AudioInput.h index 14a60c444..9ee1556da 100644 --- a/src/mumble/AudioInput.h +++ b/src/mumble/AudioInput.h @@ -74,7 +74,7 @@ class AudioInput : public QThread { void encodeAudioFrame(); - bool bRunning; + volatile bool bRunning; bool bPreviousVoice; bool bHasSpeaker; diff --git a/src/mumble/AudioOutput.cpp b/src/mumble/AudioOutput.cpp index 8bfc318b6..cfa83add6 100644 --- a/src/mumble/AudioOutput.cpp +++ b/src/mumble/AudioOutput.cpp @@ -120,7 +120,7 @@ AudioOutputSpeech::AudioOutputSpeech(ClientPlayer *player) : AudioOutputPlayer(p iMissCount = 0; iMissedFrames = 0; - jbJitter = jitter_buffer_init(); + jbJitter = jitter_buffer_init(iFrameSize); int margin = g.s.iJitterBufferSize * iFrameSize; jitter_buffer_ctl(jbJitter, JITTER_BUFFER_SET_MARGIN, &margin); @@ -186,6 +186,7 @@ bool AudioOutputSpeech::decodeNextFrame() { char data[4096]; JitterBufferPacket jbp; jbp.data = data; + jbp.len = 4096; spx_int32_t startofs = 0; @@ -349,6 +350,9 @@ AudioSine::AudioSine(float hz, float i, unsigned int frm, float vol) : AudioOutp psBuffer = new short[iFrameSize]; fftTable = NULL; tbin = 4; + + if (inc == 0.0) + g.iAudioPathTime = 0; } AudioSine::~AudioSine() { diff --git a/src/mumble/AudioOutput.h b/src/mumble/AudioOutput.h index d54e20068..dde0a3cd9 100644 --- a/src/mumble/AudioOutput.h +++ b/src/mumble/AudioOutput.h @@ -122,7 +122,7 @@ class AudioSine : public AudioOutputPlayer { class AudioOutput : public QThread { Q_OBJECT protected: - bool bRunning; + volatile bool bRunning; int iFrameSize; QReadWriteLock qrwlOutputs; QMultiHash<const ClientPlayer *, AudioOutputPlayer *> qmOutputs; diff --git a/src/mumble/AudioWizard.cpp b/src/mumble/AudioWizard.cpp index 6120ccef9..26fa934e5 100644 --- a/src/mumble/AudioWizard.cpp +++ b/src/mumble/AudioWizard.cpp @@ -50,6 +50,8 @@ AudioWizard::AudioWizard() { g.s.lmLoopMode = Settings::Local;
g.s.dPacketLoss = 0.0;
g.s.dMaxPacketDelay = 0.0;
+ g.s.bMute = false;
+ g.s.bDeaf = false;
g.s.atTransmit = Settings::Continous;
@@ -361,7 +363,8 @@ QWizardPage *AudioWizard::deviceTuningPage() { grid->addWidget(l, 0, 0, 1, 2);
l = new QLabel(tr("You should hear a single tone that's changing in frequency. Change the slider below to the lowest value which gives <b>no</b> interruptions or jitter "
- "in the sound."));
+ "in the sound. Please note that local echo is disabled during this test to "
+ "improve audio path recognition."));
l->setWordWrap(true);
grid->addWidget(l, 1, 0, 1, 2);
@@ -482,8 +485,12 @@ void AudioWizard::showPage(int v) { AudioOutputPtr ao = g.ao;
ao->wipe();
- if (v == 2)
+ if (v == 2) {
+ g.s.bMute = true;
playChord();
+ } else {
+ g.s.bMute = false;
+ }
}
void AudioWizard::playChord() {
@@ -575,7 +582,11 @@ void AudioWizard::on_Ticker_timeout() { }
abVAD->update();
- QString txt=tr("Audio path is %1ms long.").arg(g.iAudioPathTime*20);
+ QString txt;
+ if (g.iAudioPathTime)
+ txt=tr("Audio path is %1ms long.").arg(g.iAudioPathTime*20);
+ else
+ txt=tr("Audio path cannot be determined. Input not recognized.");
qlAudioPath->setText(txt);
}
diff --git a/src/mumble/DXAudioInput.cpp b/src/mumble/DXAudioInput.cpp index 7b6b8be75..0d4f60fee 100644 --- a/src/mumble/DXAudioInput.cpp +++ b/src/mumble/DXAudioInput.cpp @@ -166,6 +166,8 @@ DXAudioInput::DXAudioInput() { QMessageBox::warning(NULL, tr("Mumble"), tr("Opening chosen DirectSound Input failed. Default device will be used."), QMessageBox::Ok, QMessageBox::NoButton); qWarning("DXAudioInput: Initialized"); + + bRunning = true; } DXAudioInput::~DXAudioInput() { @@ -198,8 +200,6 @@ void DXAudioInput::run() { if (FAILED(hr = pDSCaptureBuffer->Start(DSCBSTART_LOOPING))) qFatal("DXAudioInput: Start"); - bRunning = true; - while (bRunning) { do { diff --git a/src/mumble/GlobalShortcut_unix.h b/src/mumble/GlobalShortcut_unix.h index fd8692f39..bb25268ff 100644 --- a/src/mumble/GlobalShortcut_unix.h +++ b/src/mumble/GlobalShortcut_unix.h @@ -37,7 +37,7 @@ class GlobalShortcutX : public GlobalShortcutEngine { Q_OBJECT public: Display *display; - bool bRunning; + volatile bool bRunning; QList<QFile *> qlInputDevices; GlobalShortcutX(); diff --git a/src/mumble/OSS.cpp b/src/mumble/OSS.cpp index 013359416..32e14123a 100644 --- a/src/mumble/OSS.cpp +++ b/src/mumble/OSS.cpp @@ -263,6 +263,7 @@ void OSSConfig::on_qsOutputDelay_valueChanged(int v) { } OSSInput::OSSInput() { + bRunning = true; } OSSInput::~OSSInput() { @@ -272,8 +273,6 @@ OSSInput::~OSSInput() { } void OSSInput::run() { - bRunning = true; - QByteArray device = cards->qhDevices.value(g.s.qsOSSInput).toLatin1(); if (device.isEmpty()) { qWarning("OSSInput: Stored device not found, falling back to default"); @@ -323,6 +322,8 @@ void OSSInput::run() { } OSSOutput::OSSOutput() { + bRunning = true; + qWarning("OSSOutput: Initialized"); } @@ -336,8 +337,6 @@ OSSOutput::~OSSOutput() { } void OSSOutput::run() { - bRunning = true; - QByteArray device = cards->qhDevices.value(g.s.qsOSSOutput).toLatin1(); if (device.isEmpty()) { qWarning("OSSOutput: Stored device not found, falling back to default"); diff --git a/src/mumble/PAAudio.cpp b/src/mumble/PAAudio.cpp index 061ee53c9..0da81b9b5 100644 --- a/src/mumble/PAAudio.cpp +++ b/src/mumble/PAAudio.cpp @@ -408,6 +408,7 @@ void PortAudioInput::run() { PortAudioOutput::PortAudioOutput() { qWarning() << "PortAudioOutput::PortAudioOutput()"; + bRunning = true; } PortAudioOutput::~PortAudioOutput() { @@ -428,7 +429,6 @@ void PortAudioOutput::run() { if (!pSys->initStream(&outputStream, g.s.iPortAudioOutput, iFrameSize, false)) return; // PA initialization or stream opening failed, we will give up - bRunning = true; while (bRunning) { bool nextHasMoreToMix = mixAudio(outBuffer); if (hasMoreToMix) { diff --git a/src/mumble/PulseAudio.cpp b/src/mumble/PulseAudio.cpp index 2a74f36a3..b9648c806 100644 --- a/src/mumble/PulseAudio.cpp +++ b/src/mumble/PulseAudio.cpp @@ -83,8 +83,6 @@ PulseAudioSystem::PulseAudioSystem() { iInputIdx = iEchoIdx = 0; iEchoSeq = 0; - bRunning = true; - pam = pa_mainloop_new(); pa_mainloop_api *api = pa_mainloop_get_api(pam); @@ -95,8 +93,8 @@ PulseAudioSystem::PulseAudioSystem() { pade = api->defer_new(api, defer_event_callback, this); api->defer_enable(pade, false); - jbJitter = jitter_buffer_init(); int margin = 320; + jbJitter = jitter_buffer_init(margin); jitter_buffer_ctl(jbJitter, JITTER_BUFFER_SET_MARGIN, &margin); start(QThread::TimeCriticalPriority); } @@ -381,6 +379,7 @@ void PulseAudioSystem::read_callback(pa_stream *s, size_t bytes, void *userdata) if (g.s.bPulseAudioEcho) { JitterBufferPacket jbp; jbp.data = reinterpret_cast<char *>(pai->psSpeaker); + jbp.len = pai->iFrameSize * sizeof(short); spx_int32_t startofs = 0; jitter_buffer_get(pas->jbJitter, &jbp, pai->iFrameSize, &startofs); jitter_buffer_update_delay(pas->jbJitter, &jbp, NULL); diff --git a/src/mumble/PulseAudio.h b/src/mumble/PulseAudio.h index e36527600..50819e8ce 100644 --- a/src/mumble/PulseAudio.h +++ b/src/mumble/PulseAudio.h @@ -60,7 +60,6 @@ class PulseAudioSystem : public QThread { pa_stream *pasInput, *pasOutput, *pasSpeaker; pa_mainloop *pam; pa_defer_event *pade; - bool bRunning; bool bSourceDone, bSinkDone, bServerDone; |