Skip to content

Commit

Permalink
Merge pull request #816 from Mikewando/ld-discmap-fix
Browse files Browse the repository at this point in the history
Fix pcmAudioField map contents and access
  • Loading branch information
happycube authored Nov 28, 2022
2 parents 5902afa + a01135b commit 516ba8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions tools/library/tbc/lddecodemetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ void LdDecodeMetaData::generatePcmAudioMap()
pcmAudioFieldStartSampleMap[fieldNo] = 0;
} else {
// Every following field's start position is the start+length of the previous
pcmAudioFieldStartSampleMap[fieldNo] = pcmAudioFieldStartSampleMap[fieldNo - 1] + pcmAudioFieldLengthMap[fieldNo];
pcmAudioFieldStartSampleMap[fieldNo] = pcmAudioFieldStartSampleMap[fieldNo - 1] + pcmAudioFieldLengthMap[fieldNo - 1];
}
}
}
Expand All @@ -1080,12 +1080,14 @@ void LdDecodeMetaData::generatePcmAudioMap()
qint32 LdDecodeMetaData::getFieldPcmAudioStart(qint32 sequentialFieldNumber)
{
if (pcmAudioFieldStartSampleMap.size() < sequentialFieldNumber) return -1;
return pcmAudioFieldStartSampleMap[sequentialFieldNumber];
// Field numbers are 1 indexed, but our map is 0 indexed
return pcmAudioFieldStartSampleMap[sequentialFieldNumber - 1];
}

// Method to get the sample length of the specified sequential field number
qint32 LdDecodeMetaData::getFieldPcmAudioLength(qint32 sequentialFieldNumber)
{
if (pcmAudioFieldLengthMap.size() < sequentialFieldNumber) return -1;
return pcmAudioFieldLengthMap[sequentialFieldNumber];
// Field numbers are 1 indexed, but our map is 0 indexed
return pcmAudioFieldLengthMap[sequentialFieldNumber - 1];
}
8 changes: 4 additions & 4 deletions tools/library/tbc/sourceaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ SourceAudio::Data SourceAudio::getAudioData(qint32 startSample, qint32 numberOfS
for (qint32 sample = 0; sample < numberOfSamples; sample++) {
// Left 16 bit sample
audioData >> x;
sampleData.append(x);
if (audioData.atEnd()) {
qFatal("getAudioData hit premature end of file!");
qWarning("getAudioData hit end of file!");
return sampleData;
}
sampleData.append(x);

// Right 16 bit sample
audioData >> x;
sampleData.append(x);
if (audioData.atEnd()) {
qFatal("getAudioData hit premature end of file!");
qWarning("getAudioData hit end of file!");
return sampleData;
}
sampleData.append(x);
}

return sampleData;
Expand Down

0 comments on commit 516ba8a

Please sign in to comment.