Faster and better Local reverb / no echo

This commit is contained in:
Atlante45 2014-11-17 13:43:55 -08:00
parent de2b86957b
commit 082b9ff59f
2 changed files with 9 additions and 18 deletions

View file

@ -565,7 +565,7 @@ void Audio::setReverbOptions(const AudioEffectOptions* options) {
} }
} }
void Audio::addReverb(int16_t* samplesData, int numSamples, QAudioFormat& audioFormat) { void Audio::addReverb(int16_t* samplesData, int numSamples, QAudioFormat& audioFormat, bool noEcho) {
float wetFraction = DB_CO(_reverbOptions->getWetLevel()); float wetFraction = DB_CO(_reverbOptions->getWetLevel());
float dryFraction = 1.0f - wetFraction; float dryFraction = 1.0f - wetFraction;
@ -579,11 +579,15 @@ void Audio::addReverb(int16_t* samplesData, int numSamples, QAudioFormat& audioF
for (int j = sample; j < sample + audioFormat.channelCount(); j++) { for (int j = sample; j < sample + audioFormat.channelCount(); j++) {
if (j == sample) { if (j == sample) {
// left channel // left channel
int lResult = glm::clamp((int)(samplesData[j] * dryFraction + lValue * wetFraction), MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE); int lResult = glm::clamp((int)(samplesData[j] * ((noEcho) ? 0.0f : dryFraction) +
lValue * wetFraction),
MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
samplesData[j] = (int16_t)lResult; samplesData[j] = (int16_t)lResult;
} else if (j == (sample + 1)) { } else if (j == (sample + 1)) {
// right channel // right channel
int rResult = glm::clamp((int)(samplesData[j] * dryFraction + rValue * wetFraction), MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE); int rResult = glm::clamp((int)(samplesData[j] * ((noEcho) ? 0.0f : dryFraction) +
rValue * wetFraction),
MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
samplesData[j] = (int16_t)rResult; samplesData[j] = (int16_t)rResult;
} else { } else {
// ignore channels above 2 // ignore channels above 2
@ -622,23 +626,10 @@ void Audio::handleLocalEchoAndReverb(QByteArray& inputByteArray) {
} }
if (hasLocalReverb) { if (hasLocalReverb) {
QByteArray loopbackCopy;
if (!hasEcho) {
loopbackCopy = loopBackByteArray;
}
int16_t* loopbackSamples = reinterpret_cast<int16_t*>(loopBackByteArray.data()); int16_t* loopbackSamples = reinterpret_cast<int16_t*>(loopBackByteArray.data());
int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t); int numLoopbackSamples = loopBackByteArray.size() / sizeof(int16_t);
updateGverbOptions(); updateGverbOptions();
addReverb(loopbackSamples, numLoopbackSamples, _outputFormat); addReverb(loopbackSamples, numLoopbackSamples, _outputFormat, !hasEcho);
if (!hasEcho) {
int16_t* loopbackCopySamples = reinterpret_cast<int16_t*>(loopbackCopy.data());
for (int i = 0; i < numLoopbackSamples; ++i) {
loopbackSamples[i] = glm::clamp((int)loopbackSamples[i] - loopbackCopySamples[i],
MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE);
}
}
} }
if (_loopbackOutputDevice) { if (_loopbackOutputDevice) {

View file

@ -269,7 +269,7 @@ private:
// Adds Reverb // Adds Reverb
void initGverb(); void initGverb();
void updateGverbOptions(); void updateGverbOptions();
void addReverb(int16_t* samples, int numSamples, QAudioFormat& format); void addReverb(int16_t* samples, int numSamples, QAudioFormat& format, bool noEcho = false);
void handleLocalEchoAndReverb(QByteArray& inputByteArray); void handleLocalEchoAndReverb(QByteArray& inputByteArray);