diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index b588755..c94b6c5 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -70,6 +70,8 @@ void DemodulatorPreThread::threadMain() { std::vector in_buf_data; std::vector 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); - resamp->data.assign(resampledData.begin(), resampledData.begin() + numWritten); + + 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; diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index e287035..88028de 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -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: