From 8b31cb34fff4134f919919165e7b2c8bb7be58b8 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Sun, 24 May 2020 10:47:11 +0200 Subject: [PATCH] Use stdio instead of iostream, fix file not properly closed --- FMControl.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/FMControl.cpp b/FMControl.cpp index 79dbdcb..baa429c 100644 --- a/FMControl.cpp +++ b/FMControl.cpp @@ -21,8 +21,7 @@ #include #if defined(DUMP_RF_AUDIO) -#include -#include +#include #endif const float EMPHASIS_GAIN_DB = 0.0F; //Gain needs to be the same for pre an deeemphasis @@ -43,11 +42,6 @@ CFMControl::~CFMControl() bool CFMControl::writeModem(const unsigned char* data, unsigned int length) { -#if defined(DUMP_RF_AUDIO) - std::ofstream audiofile; - audiofile.open("audiodump.bin", std::ios::out | std::ios::app | std::ios::binary); -#endif - assert(data != NULL); assert(length > 0U); @@ -70,6 +64,10 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length) bufferLength = 255U; if (bufferLength >= 3U) { +#if defined(DUMP_RF_AUDIO) + FILE * audiofile = fopen("./audiodump.bin", "ab"); +#endif + bufferLength = bufferLength - bufferLength % 3U; //round down to nearest multiple of 3 unsigned char bufferData[255U]; m_incomingRFAudio.getData(bufferData, bufferLength); @@ -103,7 +101,8 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length) samples[i] = m_deemphasis.filter(samples[i]); #if defined(DUMP_RF_AUDIO) - audiofile.write((char*)(void*)samples, nSamples * sizeof(float)); + if(audiofile != NULL) + fwrite(samples, sizeof(float), nSamples, audiofile); #endif unsigned short out[170U]; // 85 * 2 @@ -116,13 +115,14 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length) out[nOut++] = (sample >> 0) & 0xFFU; } +#if defined(DUMP_RF_AUDIO) + if(audiofile != NULL) + fclose(audiofile); +#endif + return m_network->writeData((unsigned char*)out, nOut); } -#if defined(DUMP_RF_AUDIO) - audiofile.close(); -#endif - return true; }