clarify variable names

adpcm
Dimitri Diakopoulos 10 years ago
parent d344856b8a
commit 5e7ccac364

@ -33,13 +33,11 @@ namespace nqr
struct ADPCMState struct ADPCMState
{ {
int nBlockAlign; int frame_size;
int firstDataBlockByte; int firstDataBlockByte;
int dataSize; int dataSize;
int currentByte; int currentByte;
const uint8_t * currentDatablock; // A buffer containing the current encoded datablock. const uint8_t * inBuffer;
int predict = 0;
int stepIndex = 0;
}; };
static const int ima_index_table[16] = static const int ima_index_table[16] =
@ -101,7 +99,7 @@ namespace nqr
void decode_ima_adpcm(ADPCMState & state, int16_t * outBuffer, uint32_t num_channels) void decode_ima_adpcm(ADPCMState & state, int16_t * outBuffer, uint32_t num_channels)
{ {
const uint8_t * data = state.currentDatablock; const uint8_t * data = state.inBuffer;
// Loop over the interleaved words // Loop over the interleaved words
for (int32_t ch = 0; ch < num_channels; ch++) for (int32_t ch = 0; ch < num_channels; ch++)
@ -120,7 +118,7 @@ namespace nqr
int idx = ch; int idx = ch;
// Decode each nibble of the current data word, containing 8 encoded samples, for the current channel // Decode each nibble of the current data word, containing 8 encoded samples, for the current channel
while (byteIdx < state.nBlockAlign) while (byteIdx < state.frame_size)
{ {
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {

@ -188,11 +188,11 @@ int WavDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & me
if (adpcmEncoded) if (adpcmEncoded)
{ {
ADPCMState s; ADPCMState s;
s.nBlockAlign = wavHeader.frame_size; s.frame_size = wavHeader.frame_size;
s.firstDataBlockByte = 0; s.firstDataBlockByte = 0;
s.dataSize = DataChunkInfo.size; s.dataSize = DataChunkInfo.size;
s.currentByte = 0; s.currentByte = 0;
s.currentDatablock = const_cast<uint8_t*>(memory.data() + DataChunkInfo.offset); s.inBuffer = const_cast<uint8_t*>(memory.data() + DataChunkInfo.offset);
// An encoded sample is 4 bits that expands to 16 // An encoded sample is 4 bits that expands to 16
size_t totalSamples = factChunk.sample_length * 4; size_t totalSamples = factChunk.sample_length * 4;
@ -200,13 +200,13 @@ int WavDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & me
uint32_t frameOffset = 0; uint32_t frameOffset = 0;
unsigned numFrames = DataChunkInfo.size / s.nBlockAlign; unsigned numFrames = DataChunkInfo.size / s.frame_size;
for (int i = 0; i < numFrames; ++i) for (int i = 0; i < numFrames; ++i)
{ {
decode_ima_adpcm(s, adpcm_pcm16.data() + frameOffset, wavHeader.channel_count); decode_ima_adpcm(s, adpcm_pcm16.data() + frameOffset, wavHeader.channel_count);
s.currentDatablock += s.nBlockAlign; s.inBuffer += s.frame_size;
frameOffset += (wavHeader.channel_count * s.nBlockAlign); frameOffset += (wavHeader.channel_count * s.frame_size);
} }
data->lengthSeconds = ((float) totalSamples / (float) wavHeader.sample_rate) / wavHeader.channel_count; data->lengthSeconds = ((float) totalSamples / (float) wavHeader.sample_rate) / wavHeader.channel_count;

Loading…
Cancel
Save