Ensure demodulator always gets even buffer lengths

This commit is contained in:
Charles J. Cliffe 2015-02-16 13:49:04 -05:00
parent 24fe742f8e
commit ddbdd81699
2 changed files with 26 additions and 7 deletions

View File

@ -70,6 +70,8 @@ void DemodulatorPreThread::threadMain() {
std::vector<liquid_float_complex> in_buf_data;
std::vector<liquid_float_complex> out_buf_data;
liquid_float_complex carrySample; // Keep the stream count even to simplify some demod operations
bool carrySampleFlag = false;
terminated = false;
@ -197,7 +199,30 @@ void DemodulatorPreThread::threadMain() {
msresamp_crcf_execute(iqResampler, in_buf, bufSize, &resampledData[0], &numWritten);
resamp->setRefCount(1);
bool uneven = (numWritten % 2 != 0);
if (!carrySampleFlag && !uneven) {
resamp->data.assign(resampledData.begin(), resampledData.begin() + numWritten);
carrySampleFlag = false;
} else if (!carrySampleFlag && uneven) {
resamp->data.assign(resampledData.begin(), resampledData.begin() + (numWritten-1));
carrySample = resampledData.back();
carrySampleFlag = true;
} else if (carrySampleFlag && uneven) {
resamp->data.resize(numWritten+1);
resamp->data[0] = carrySample;
memcpy(&resamp->data[1],&resampledData[0],sizeof(liquid_float_complex)*numWritten);
carrySampleFlag = false;
} else if (carrySampleFlag && !uneven) {
resamp->data.resize(numWritten);
resamp->data[0] = carrySample;
memcpy(&resamp->data[1],&resampledData[0],sizeof(liquid_float_complex)*(numWritten-1));
carrySample = resampledData.back();
carrySampleFlag = true;
}
resamp->audioResampleRatio = audioResampleRatio;
resamp->audioResampler = audioResampler;

View File

@ -190,9 +190,6 @@ void DemodulatorThread::threadMain() {
ampmodem_demodulate(demodAM, x, &demodOutputData[i * 2]);
ampmodem_demodulate(demodAM, y, &demodOutputData[i * 2 + 1]);
}
if (bufSize % 2) { // yep, this is ugly for the moment until I buffer the overflow byte
ampmodem_demodulate(demodAM, y, &demodOutputData[bufSize - 1]);
}
break;
case DEMOD_TYPE_USB:
for (int i = 0; i < bufSize / 2; i++) { // Reject lower band
@ -210,9 +207,6 @@ void DemodulatorThread::threadMain() {
ampmodem_demodulate(demodAM, x, &demodOutputData[i * 2]);
ampmodem_demodulate(demodAM, y, &demodOutputData[i * 2 + 1]);
}
if (bufSize % 2) {
ampmodem_demodulate(demodAM, y, &demodOutputData[bufSize - 1]);
}
break;
case DEMOD_TYPE_AM:
case DEMOD_TYPE_DSB: