1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Cleanup mic feedback related code

It simply doesn't work, so let's do it right later
This commit is contained in:
tux3 2016-01-21 16:25:25 +01:00
parent ffbd8fba91
commit fb68d3750c
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 6 additions and 148 deletions

View File

@ -118,52 +118,6 @@ private:
ALuint mSource;
};
class AudioMeter : public QThread
{
public:
AudioMeter()
{
connect(this, &AudioMeter::finished, this, &AudioMeter::deleteLater);
}
inline void stop()
{
requestInterruption();
}
private:
void run() override final
{
static const int framesize = AUDIO_FRAME_SAMPLE_COUNT * AUDIO_CHANNELS;
Audio& audio = Audio::getInstance();
mNewMaxGain = 0.f;
QMutexLocker locker(&mMeterLock);
while (!isInterruptionRequested()) {
mListenerReady.wait(locker.mutex());
locker.relock();
int16_t buff[framesize] = {0};
if (audio.tryCaptureSamples(buff, AUDIO_FRAME_SAMPLE_COUNT)) {
mNewMaxGain = 0.f;
for (int i = 0; i < framesize; ++i) {
mNewMaxGain = qMax(mNewMaxGain, qAbs(buff[i]) / 32767.0);
}
}
mGainMeasured.wakeAll();
}
}
public:
QMutex mMeterLock;
QWaitCondition mListenerReady;
QWaitCondition mGainMeasured;
qreal mNewMaxGain;
};
class AudioPrivate
{
typedef QList<Audio::SID> ALSources;
@ -185,9 +139,6 @@ public:
~AudioPrivate()
{
if (audioMeter)
audioMeter->stop();
audioThread->exit();
audioThread->wait();
cleanupInput();
@ -216,71 +167,8 @@ public:
bool outputInitialized;
ALSources outSources;
QPointer<AudioMeter> audioMeter;
};
AudioMeterListener::AudioMeterListener(AudioMeter* measureThread)
: mActive(false)
, mAudioMeter(measureThread)
{
assert(mAudioMeter);
}
void AudioMeterListener::start()
{
if (!mAudioMeter->isRunning()) {
mAudioMeter->start();
// TODO: ensure that audiometer is running
// -> Start listeners from AudioMeter::started signal
while (!mAudioMeter->isRunning())
QThread::msleep(10);
}
QThread* listener = new QThread;
connect(listener, &QThread::started, this, &AudioMeterListener::doListen);
connect(listener, &QThread::finished, listener, &QThread::deleteLater);
moveToThread(listener);
listener->start();
}
void AudioMeterListener::stop()
{
mActive = false;
}
void AudioMeterListener::processed()
{
mGainProcessed.wakeAll();
}
void AudioMeterListener::doListen()
{
mMaxGain = 0.f;
mActive = true;
QMutexLocker locker(&mAudioMeter->mMeterLock);
while (mActive) {
mAudioMeter->mListenerReady.wakeAll();
mAudioMeter->mGainMeasured.wait(&mAudioMeter->mMeterLock);
locker.relock();
if (mAudioMeter->mNewMaxGain > mMaxGain) {
mMaxGain = mAudioMeter->mNewMaxGain;
emit gainChanged(mMaxGain);
} else if (mMaxGain > 0.02f) {
mMaxGain -= 0.008f;
emit gainChanged(mMaxGain);
}
mGainProcessed.wait(locker.mutex(), 10);
locker.relock();
}
mAudioMeter->requestInterruption();
}
/**
Returns the singleton instance.
*/
@ -290,14 +178,6 @@ Audio& Audio::getInstance()
return instance;
}
AudioMeterListener* Audio::createAudioMeterListener() const
{
if (!d->audioMeter)
d->audioMeter = new AudioMeter;
return new AudioMeterListener(d->audioMeter);
}
Audio::Audio()
: d(new AudioPrivate)
{

View File

@ -29,8 +29,6 @@
struct Tox;
class AudioFilterer;
class AudioMeter;
class AudioMeterListener;
class AudioPrivate;
// Public default audio settings
@ -50,8 +48,6 @@ public:
static Audio& getInstance();
public:
AudioMeterListener* createAudioMeterListener() const;
qreal outputVolume();
void setOutputVolume(qreal volume);
@ -102,28 +98,4 @@ private:
AudioPrivate* d;
};
class AudioMeterListener : public QObject
{
Q_OBJECT
public:
explicit AudioMeterListener(AudioMeter* measureThread);
void start();
void stop();
void processed();
signals:
void gainChanged(qreal newMaxGain);
private slots:
void doListen();
private:
bool mActive;
AudioMeter* mAudioMeter;
qreal mMaxGain;
QWaitCondition mGainProcessed;
};
#endif // AUDIO_H

View File

@ -60,20 +60,26 @@ void MicFeedbackWidget::paintEvent(QPaintEvent*)
void MicFeedbackWidget::showEvent(QShowEvent*)
{
#if 0
mMeterListener = Audio::getInstance().createAudioMeterListener();
connect(mMeterListener, &AudioMeterListener::gainChanged,
this, &MicFeedbackWidget::onGainMetered);
mMeterListener->start();
#endif
}
void MicFeedbackWidget::hideEvent(QHideEvent*)
{
#if 0
mMeterListener->stop();
#endif
}
void MicFeedbackWidget::onGainMetered(qreal value)
{
#if 0
current = value;
update();
mMeterListener->processed();
#endif
}