From 92e148506c433d6eb40bd001187a23fef77dc05f Mon Sep 17 00:00:00 2001 From: "Christian R. Helmrich" Date: Mon, 6 Jul 2020 01:00:00 +0200 Subject: [PATCH] ext. WAVE support --- src/app/basicMP4Writer.cpp | 5 ----- src/app/basicWavReader.cpp | 14 ++++++++++++-- src/app/basicWavReader.h | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/app/basicMP4Writer.cpp b/src/app/basicMP4Writer.cpp index d7ce834..e775d67 100644 --- a/src/app/basicMP4Writer.cpp +++ b/src/app/basicMP4Writer.cpp @@ -272,11 +272,6 @@ int BasicMP4Writer::finishFile (const unsigned avgBitrate, const unsigned maxBit m_dynamicHeader.push_back (0x6F); m_dynamicHeader.push_back (0x6C); // prol m_dynamicHeader.push_back (0x00); m_dynamicHeader.push_back (0x00); m_dynamicHeader.push_back (0x00); m_dynamicHeader.push_back (0x01); - if (patternLengthSize > 2) - { - m_dynamicHeader.push_back ((m_rndAccPeriod >> 24) & UCHAR_MAX); - m_dynamicHeader.push_back ((m_rndAccPeriod >> 16) & UCHAR_MAX); - } if (patternLengthSize > 1) { m_dynamicHeader.push_back ((m_rndAccPeriod >> 8) & UCHAR_MAX); diff --git a/src/app/basicWavReader.cpp b/src/app/basicWavReader.cpp index d20f960..24f6220 100644 --- a/src/app/basicWavReader.cpp +++ b/src/app/basicWavReader.cpp @@ -31,7 +31,8 @@ bool BasicWavReader::readRiffHeader () { uint8_t b[FILE_HEADER_SIZE] = {0}; // temp. byte buffer - if ((m_bytesRead = _READ (m_fileHandle, b, FILE_HEADER_SIZE)) != FILE_HEADER_SIZE) return false; // error + m_bytesRead = _READ (m_fileHandle, b, 8); + if ((m_bytesRead += _READ (m_fileHandle, &b[8], FILE_HEADER_SIZE - 8)) != FILE_HEADER_SIZE) return false; // error m_bytesRemaining -= m_bytesRead; m_chunkLength = fourBytesToLength (&b[4], m_bytesRemaining) - 4; // minus 4 bytes for WAVE tag @@ -48,9 +49,18 @@ bool BasicWavReader::readFormatChunk () { return false; // fmt_ chunk invalid or read incomplete } - if ((m_bytesRead = _READ (m_fileHandle, b, (unsigned) m_chunkLength)) != m_chunkLength) return false; // error + m_bytesRead = _READ (m_fileHandle, b, 8); + for (int64_t i = 8; i < m_chunkLength; i += 2) m_bytesRead += _READ (m_fileHandle, &b[i], 2); + if (m_bytesRead != m_chunkLength) return false; // error m_bytesRemaining -= m_bytesRead; + if ((b[0] == 0xFE) && (b[1] == 0xFF) && (m_chunkLength == CHUNK_FORMAT_MAX) && (b[16] == CHUNK_FORMAT_MAX - CHUNK_FORMAT_SIZE - 2) && + (b[17] == 0) && (b[18] == b[14]) && (b[19] == 0) && ((b[25] | b[26] | b[27] | b[28] | b[29] | b[31] | b[33] | b[34] | b[36]) == 0)) + { + m_waveDataType = WAV_TYPE (b[24]-1); // extensible WAV + b[1] = 0; + } + else m_waveDataType = WAV_TYPE (b[0]-1); // 1: PCM, 3: float m_waveChannels = b[2]; // only 1, 2, ..., 63 supported m_waveFrameRate = reverseFourBytes (&b[4]); // frames/s diff --git a/src/app/basicWavReader.h b/src/app/basicWavReader.h index 5b2a136..054e13d 100644 --- a/src/app/basicWavReader.h +++ b/src/app/basicWavReader.h @@ -16,7 +16,7 @@ // constant data sizes & limits #define BWR_BUFFERED_READ 1 // faster reader #define BWR_READ_FRACT 5 // 2^-READ_FRACT -#define CHUNK_FORMAT_MAX 20 +#define CHUNK_FORMAT_MAX 40 #define CHUNK_FORMAT_SIZE 16 #define CHUNK_HEADER_SIZE 8 #define FILE_HEADER_SIZE 12