diff --git a/src/app/basicMP4Writer.cpp b/src/app/basicMP4Writer.cpp index a90fba1..2aad5e5 100644 --- a/src/app/basicMP4Writer.cpp +++ b/src/app/basicMP4Writer.cpp @@ -60,7 +60,7 @@ static const uint8_t staticHeaderTemplate[STAT_HEADER_SIZE] = { }; // static helper functions -static uint32_t toBigEndian (const unsigned ui) // Motorola endianness +static uint32_t toBigEndian (const unsigned ui) // to Motorola endianness { return ((ui & UCHAR_MAX) << 24) | (((ui >> 8) & UCHAR_MAX) << 16) | (((ui >> 16) & UCHAR_MAX) << 8) | ((ui >> 24) & UCHAR_MAX); } diff --git a/src/app/basicWavReader.cpp b/src/app/basicWavReader.cpp index 036770f..5c347d3 100644 --- a/src/app/basicWavReader.cpp +++ b/src/app/basicWavReader.cpp @@ -386,14 +386,19 @@ unsigned BasicWavReader::read (int32_t* const frameBuf, const uint16_t frameCoun { unsigned framesRead; - if ((frameBuf == nullptr) || (m_fileHandle == -1) || (__min (m_frameLimit, frameCount) == 0) || (m_byteBuffer == nullptr)) + if ((frameBuf == nullptr) || (m_fileHandle == -1) || (__min (m_frameLimit, frameCount) == 0) || (m_byteBuffer == nullptr) || + (m_bytesRemaining <= 0)) // end of chunk reached { return 0; // invalid args or class not initialized } framesRead = m_readDataFunc (m_fileHandle, frameBuf, __min (m_frameLimit, frameCount), m_waveChannels, m_byteBuffer); m_bytesRead = m_waveFrameSize * framesRead; - m_bytesRemaining -= m_bytesRead; - m_chunkLength += m_bytesRead; + if ((m_bytesRemaining -= m_bytesRead) < 0) + { + m_bytesRead = unsigned (m_bytesRead + m_bytesRemaining); + framesRead = m_bytesRead / m_waveFrameSize; + } + m_chunkLength += m_bytesRead; return framesRead; } diff --git a/src/lib/tempAnalysis.cpp b/src/lib/tempAnalysis.cpp index 7097cd7..0b1ec2c 100644 --- a/src/lib/tempAnalysis.cpp +++ b/src/lib/tempAnalysis.cpp @@ -64,7 +64,7 @@ static inline uint32_t packAvgTempAnalysisStats (const unsigned avgAbsHpL, cons static inline int16_t getMaxAbsHpValueLocation (const unsigned maxAbsValL, const unsigned maxAbsValR, const unsigned maxAbsValP, const int16_t maxAbsIdxL, const int16_t maxAbsIdxR) { - if ((maxAbsValP * 8 < maxAbsValL * 3) || (maxAbsValL * 8 < maxAbsValR * 3)) // has transient + if ((maxAbsValP * 5 < maxAbsValL * 2) || (maxAbsValL * 5 < maxAbsValR * 2)) // has transient { return maxAbsValR > maxAbsValL ? maxAbsIdxR : maxAbsIdxL; }