Break out chunk/riff helpers into separate files
parent
c4bceacc5e
commit
6499bc7455
@ -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
|
||||
@ -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…
Reference in New Issue