Merge remote-tracking branch 'origin/mixer-fixes' into waterfall-optimize

This commit is contained in:
Charles J. Cliffe 2015-02-11 21:35:44 -05:00
commit c69d05010c
3 changed files with 22 additions and 6 deletions

View File

@ -60,12 +60,12 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
std::cout << "Audio buffer underflow.." << (src->underflowCount++) << std::endl; std::cout << "Audio buffer underflow.." << (src->underflowCount++) << std::endl;
} }
if (!src->boundThreads.load()->empty()) { if (src->boundThreads.load()->empty()) {
src->gain = 1.0 / src->boundThreads.load()->size();
} else {
return 0; return 0;
} }
float peak = 0.0;
for (int j = 0; j < src->boundThreads.load()->size(); j++) { for (int j = 0; j < src->boundThreads.load()->size(); j++) {
AudioThread *srcmix = (*(src->boundThreads.load()))[j]; AudioThread *srcmix = (*(src->boundThreads.load()))[j];
if (srcmix->terminated || !srcmix->inputQueue || srcmix->inputQueue->empty() || !srcmix->isActive()) { if (srcmix->terminated || !srcmix->inputQueue || srcmix->inputQueue->empty() || !srcmix->isActive()) {
@ -104,6 +104,8 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
continue; continue;
} }
peak += srcmix->currentInput->peak;
if (srcmix->currentInput->channels == 1) { if (srcmix->currentInput->channels == 1) {
for (int i = 0; i < nBufferFrames; i++) { for (int i = 0; i < nBufferFrames; i++) {
if (srcmix->audioQueuePtr >= srcmix->currentInput->data.size()) { if (srcmix->audioQueuePtr >= srcmix->currentInput->data.size()) {
@ -121,7 +123,7 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
srcmix->audioQueuePtr = 0; srcmix->audioQueuePtr = 0;
} }
if (srcmix->currentInput && srcmix->currentInput->data.size()) { if (srcmix->currentInput && srcmix->currentInput->data.size()) {
float v = srcmix->currentInput->data[srcmix->audioQueuePtr] * src->gain * srcmix->gain; float v = srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain;
out[i * 2] += v; out[i * 2] += v;
out[i * 2 + 1] += v; out[i * 2 + 1] += v;
} }
@ -144,12 +146,17 @@ static int audioCallback(void *outputBuffer, void *inputBuffer, unsigned int nBu
srcmix->audioQueuePtr = 0; srcmix->audioQueuePtr = 0;
} }
if (srcmix->currentInput && srcmix->currentInput->data.size()) { if (srcmix->currentInput && srcmix->currentInput->data.size()) {
out[i] = out[i] + srcmix->currentInput->data[srcmix->audioQueuePtr] * src->gain * srcmix->gain; out[i] = out[i] + srcmix->currentInput->data[srcmix->audioQueuePtr] * srcmix->gain;
} }
srcmix->audioQueuePtr++; srcmix->audioQueuePtr++;
} }
} }
if (peak > 1.0) {
for (int i = 0 ; i < nBufferFrames * 2; i ++) {
out[i] /= peak;
}
}
} }
return 0; return 0;

View File

@ -35,10 +35,11 @@ public:
long long frequency; long long frequency;
int sampleRate; int sampleRate;
int channels; int channels;
float peak;
std::vector<float> data; std::vector<float> data;
AudioThreadInput() : AudioThreadInput() :
frequency(0), sampleRate(0), channels(0) { frequency(0), sampleRate(0), channels(0), peak(0) {
} }

View File

@ -313,6 +313,14 @@ void DemodulatorThread::threadMain() {
ati->data.assign(resampledOutputData.begin(), resampledOutputData.begin() + numAudioWritten); ati->data.assign(resampledOutputData.begin(), resampledOutputData.begin() + numAudioWritten);
} }
std::vector<float>::iterator data_i;
ati->peak = 0;
for (data_i = ati->data.begin(); data_i != ati->data.end(); data_i++) {
if (float p = fabs(*data_i) > ati->peak) {
ati->peak = p;
}
}
audioOutputQueue->push(ati); audioOutputQueue->push(ati);
} }
} }