Break out chunk/riff helpers into separate files

adpcm
Dimitri Diakopoulos 11 years ago
parent c4bceacc5e
commit 6499bc7455

@ -271,27 +271,6 @@ inline void ConvertToFloat32(float * dst, const int32_t * src, const size_t N, P
}
}
///////////////////////////////////////////
// Chunk utilities (move somewhere else) //
///////////////////////////////////////////
struct ChunkHeaderInfo
{
uint32_t offset; // Byte offset into chunk
uint32_t size; // Size of the chunk in bytes
};
inline uint32_t GenerateChunkCode(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{
#ifdef ARCH_CPU_LITTLE_ENDIAN
return ((uint32_t) ((a) | ((b) << 8) | ((c) << 16) | (((uint32_t) (d)) << 24)));
#else
return ((uint32_t) ((((uint32_t) (a)) << 24) | ((b) << 16) | ((c) << 8) | (d)));
#endif
}
ChunkHeaderInfo ScanForChunk(const std::vector<uint8_t> & fileData, uint32_t chunkMarker);
//////////////////////////
// User Data + File Ops //
//////////////////////////

@ -13,3 +13,4 @@ namespace nqr
} // end namespace nqr
#endif

@ -0,0 +1,34 @@
#pragma comment(user, "license")
#ifndef RIFF_UTILS_H
#define RIFF_UTILS_H
#include "Common.h"
namespace nqr
{
/////////////////////
// Chunk utilities //
/////////////////////
struct ChunkHeaderInfo
{
uint32_t offset; // Byte offset into chunk
uint32_t size; // Size of the chunk in bytes
};
inline uint32_t GenerateChunkCode(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{
#ifdef ARCH_CPU_LITTLE_ENDIAN
return ((uint32_t) ((a) | ((b) << 8) | ((c) << 16) | (((uint32_t) (d)) << 24)));
#else
return ((uint32_t) ((((uint32_t) (a)) << 24) | ((b) << 16) | ((c) << 8) | (d)));
#endif
}
ChunkHeaderInfo ScanForChunk(const std::vector<uint8_t> & fileData, uint32_t chunkMarker);
} // end namespace nqr
#endif

@ -10,6 +10,7 @@
0804D13F1AE69F0100F4B1FD /* OpusDependencies.c in Sources */ = {isa = PBXBuildFile; fileRef = 0804D13E1AE69F0100F4B1FD /* OpusDependencies.c */; };
0804D1451AE6BA5100F4B1FD /* celt_decoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 0804D1431AE6BA5100F4B1FD /* celt_decoder.c */; };
0804D1461AE6BA5100F4B1FD /* celt_encoder.c in Sources */ = {isa = PBXBuildFile; fileRef = 0804D1441AE6BA5100F4B1FD /* celt_encoder.c */; };
080A58581B0866F600302850 /* RiffUtils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 080A58571B0866F600302850 /* RiffUtils.cpp */; };
081FFB191ADF803800673073 /* FlacDependencies.c in Sources */ = {isa = PBXBuildFile; fileRef = 081FFB181ADF803800673073 /* FlacDependencies.c */; };
086DADAD1AE029860031F793 /* VorbisDependencies.c in Sources */ = {isa = PBXBuildFile; fileRef = 086DADAB1ADF9DF30031F793 /* VorbisDependencies.c */; };
08894F291AEAA5D7007AAF90 /* bits.c in Sources */ = {isa = PBXBuildFile; fileRef = 08894F1E1AEAA5D7007AAF90 /* bits.c */; };
@ -56,6 +57,8 @@
0804D13E1AE69F0100F4B1FD /* OpusDependencies.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = OpusDependencies.c; path = src/OpusDependencies.c; sourceTree = SOURCE_ROOT; };
0804D1431AE6BA5100F4B1FD /* celt_decoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = celt_decoder.c; path = third_party/opus/celt/celt_decoder.c; sourceTree = SOURCE_ROOT; };
0804D1441AE6BA5100F4B1FD /* celt_encoder.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = celt_encoder.c; path = third_party/opus/celt/celt_encoder.c; sourceTree = SOURCE_ROOT; };
080A58561B0866AA00302850 /* RiffUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RiffUtils.h; path = include/libnyquist/RiffUtils.h; sourceTree = SOURCE_ROOT; };
080A58571B0866F600302850 /* RiffUtils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RiffUtils.cpp; path = src/RiffUtils.cpp; sourceTree = SOURCE_ROOT; };
081FFB181ADF803800673073 /* FlacDependencies.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = FlacDependencies.c; path = src/FlacDependencies.c; sourceTree = SOURCE_ROOT; };
086DADAB1ADF9DF30031F793 /* VorbisDependencies.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = VorbisDependencies.c; path = src/VorbisDependencies.c; sourceTree = SOURCE_ROOT; };
08894F1E1AEAA5D7007AAF90 /* bits.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = bits.c; path = third_party/wavpack/src/bits.c; sourceTree = SOURCE_ROOT; };
@ -221,6 +224,7 @@
08B91D881AC73B8000335131 /* FlacDecoder.h */,
08B91D891AC73B8000335131 /* VorbisDecoder.h */,
08B91D8A1AC73B8000335131 /* OpusDecoder.h */,
080A58561B0866AA00302850 /* RiffUtils.h */,
08B91D8B1AC73B8000335131 /* PostProcess.h */,
08B91D8C1AC73B8000335131 /* RingBuffer.h */,
08B91D8E1AC73B8000335131 /* WavDecoder.h */,
@ -237,6 +241,7 @@
08B91D911AC73B8A00335131 /* AudioDecoder.cpp */,
08B91D921AC73B8A00335131 /* AudioDevice.cpp */,
08B91D931AC73B8A00335131 /* Common.cpp */,
080A58571B0866F600302850 /* RiffUtils.cpp */,
08B91D941AC73B8A00335131 /* FlacDecoder.cpp */,
08B91D951AC73B8A00335131 /* Main.cpp */,
08B91D961AC73B8A00335131 /* VorbisDecoder.cpp */,
@ -321,6 +326,7 @@
08B91DA21AC73B8A00335131 /* WavDecoder.cpp in Sources */,
08B91D9A1AC73B8A00335131 /* CafDecoder.cpp in Sources */,
08894F2F1AEAA5D7007AAF90 /* tags.c in Sources */,
080A58581B0866F600302850 /* RiffUtils.cpp in Sources */,
08B91DA11AC73B8A00335131 /* OpusDecoder.cpp in Sources */,
08894F2D1AEAA5D7007AAF90 /* metadata.c in Sources */,
08B91D9E1AC73B8A00335131 /* FlacDecoder.cpp in Sources */,

@ -2,26 +2,6 @@
using namespace nqr;
ChunkHeaderInfo nqr::ScanForChunk(const std::vector<uint8_t> & fileData, uint32_t chunkMarker)
{
// D[n] aligned to 16 bytes now
const uint16_t * d = reinterpret_cast<const uint16_t *>(fileData.data());
for (size_t i = 0; i < fileData.size() / sizeof(uint16_t); i++)
{
// This will be in machine endianess
uint32_t m = Pack(Read16(d[i]), Read16(d[i+1]));
if (m == chunkMarker)
{
uint32_t cSz = Pack(Read16(d[i+2]), Read16(d[i+3]));
return {(uint32_t (i * sizeof(uint16_t))), cSz}; // return i in bytes to the start of the data
}
else continue;
}
return {0, 0};
};
NyquistFileBuffer nqr::ReadFile(std::string pathToFile)
{
std::cout << "[Debug] Open: " << pathToFile << std::endl;

@ -0,0 +1,23 @@
#include "RiffUtils.h"
using namespace nqr;
ChunkHeaderInfo nqr::ScanForChunk(const std::vector<uint8_t> & fileData, uint32_t chunkMarker)
{
// D[n] aligned to 16 bytes now
const uint16_t * d = reinterpret_cast<const uint16_t *>(fileData.data());
for (size_t i = 0; i < fileData.size() / sizeof(uint16_t); i++)
{
// This will be in machine endianess
uint32_t m = Pack(Read16(d[i]), Read16(d[i+1]));
if (m == chunkMarker)
{
uint32_t cSz = Pack(Read16(d[i+2]), Read16(d[i+3]));
return {(uint32_t (i * sizeof(uint16_t))), cSz}; // return i in bytes to the start of the data
}
else continue;
}
return {0, 0};
};
Loading…
Cancel
Save