diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 2eb751868e..b7076b6c1a 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -99,6 +99,7 @@ Audio::Audio(QObject* parent) : _muted(false), _reverb(false), _reverbOptions(&_scriptReverbOptions), + _gverbLocal(NULL), _gverb(NULL), _iconColor(1.0f), _iconPulseTimeReference(usecTimestampNow()), @@ -504,12 +505,23 @@ bool Audio::switchOutputToAudioDevice(const QString& outputDeviceName) { void Audio::initGverb() { // Initialize a new gverb instance + _gverbLocal = gverb_new(_outputFormat.sampleRate(), _reverbOptions->getMaxRoomSize(), _reverbOptions->getRoomSize(), + _reverbOptions->getReverbTime(), _reverbOptions->getDamping(), _reverbOptions->getSpread(), + _reverbOptions->getInputBandwidth(), _reverbOptions->getEarlyLevel(), + _reverbOptions->getTailLevel()); _gverb = gverb_new(_outputFormat.sampleRate(), _reverbOptions->getMaxRoomSize(), _reverbOptions->getRoomSize(), _reverbOptions->getReverbTime(), _reverbOptions->getDamping(), _reverbOptions->getSpread(), _reverbOptions->getInputBandwidth(), _reverbOptions->getEarlyLevel(), _reverbOptions->getTailLevel()); - + // Configure the instance (these functions are not super well named - they actually set several internal variables) + gverb_set_roomsize(_gverbLocal, _reverbOptions->getRoomSize()); + gverb_set_revtime(_gverbLocal, _reverbOptions->getReverbTime()); + gverb_set_damping(_gverbLocal, _reverbOptions->getDamping()); + gverb_set_inputbandwidth(_gverbLocal, _reverbOptions->getInputBandwidth()); + gverb_set_earlylevel(_gverbLocal, DB_CO(_reverbOptions->getEarlyLevel())); + gverb_set_taillevel(_gverbLocal, DB_CO(_reverbOptions->getTailLevel())); + gverb_set_roomsize(_gverb, _reverbOptions->getRoomSize()); gverb_set_revtime(_gverb, _reverbOptions->getReverbTime()); gverb_set_damping(_gverb, _reverbOptions->getDamping()); @@ -565,7 +577,7 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) { } } -void Audio::addReverb(int16_t* samplesData, int numSamples, QAudioFormat& audioFormat, bool noEcho) { +void Audio::addReverb(ty_gverb* gverb, int16_t* samplesData, int numSamples, QAudioFormat& audioFormat, bool noEcho) { float wetFraction = DB_CO(_reverbOptions->getWetLevel()); float dryFraction = (noEcho) ? 0.0f : (1.0f - wetFraction); @@ -573,7 +585,7 @@ void Audio::addReverb(int16_t* samplesData, int numSamples, QAudioFormat& audioF for (int sample = 0; sample < numSamples; sample += audioFormat.channelCount()) { // Run GVerb float value = (float)samplesData[sample]; - gverb_do(_gverb, value, &lValue, &rValue); + gverb_do(gverb, value, &lValue, &rValue); // Mix, accounting for clipping, the left and right channels. Ignore the rest. for (int j = sample; j < sample + audioFormat.channelCount(); j++) { @@ -627,7 +639,7 @@ void Audio::handleLocalEchoAndReverb(QByteArray& inputByteArray) { int16_t* loopbackSamples = reinterpret_cast(loopBackByteArray.data()); int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t); updateGverbOptions(); - addReverb(loopbackSamples, numLoopbackSamples, _outputFormat, !hasEcho); + addReverb(_gverbLocal, loopbackSamples, numLoopbackSamples, _outputFormat, !hasEcho); } if (_loopbackOutputDevice) { @@ -1018,7 +1030,7 @@ void Audio::processReceivedSamples(const QByteArray& inputBuffer, QByteArray& ou if(_reverb || _receivedAudioStream.hasReverb()) { updateGverbOptions(); - addReverb((int16_t*)outputBuffer.data(), numDeviceOutputSamples, _outputFormat); + addReverb(_gverb, (int16_t*)outputBuffer.data(), numDeviceOutputSamples, _outputFormat); } } diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 913524d8e5..127c2e3332 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -248,6 +248,7 @@ private: AudioEffectOptions _scriptReverbOptions; AudioEffectOptions _zoneReverbOptions; AudioEffectOptions* _reverbOptions; + ty_gverb* _gverbLocal; ty_gverb* _gverb; GLuint _micTextureId; GLuint _muteTextureId; @@ -269,7 +270,7 @@ private: // Adds Reverb void initGverb(); void updateGverbOptions(); - void addReverb(int16_t* samples, int numSamples, QAudioFormat& format, bool noEcho = false); + void addReverb(ty_gverb* gverb, int16_t* samples, int numSamples, QAudioFormat& format, bool noEcho = false); void handleLocalEchoAndReverb(QByteArray& inputByteArray);