aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKari Salminen2007-08-10 15:33:07 +0000
committerKari Salminen2007-08-10 15:33:07 +0000
commit6ea171189b2d6d847444306488a95f12493d8c77 (patch)
tree29941c902ba8f47255b512741f67febbc0633b83
parent9df29f1123f39d83f5df34ce0ad0e383a07bd5ae (diff)
downloadscummvm-rg350-6ea171189b2d6d847444306488a95f12493d8c77.tar.gz
scummvm-rg350-6ea171189b2d6d847444306488a95f12493d8c77.tar.bz2
scummvm-rg350-6ea171189b2d6d847444306488a95f12493d8c77.zip
Added Apple IIGS sample's true size calculation (A zero byte can end the sample prematurely).
svn-id: r28514
-rw-r--r--engines/agi/sound.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp
index 7769616fff..e842cdabcb 100644
--- a/engines/agi/sound.cpp
+++ b/engines/agi/sound.cpp
@@ -179,6 +179,25 @@ bool readIIgsSampleHeader(IIgsSampleHeader &header, Common::SeekableReadStream &
}
/**
+ * Calculates an Apple IIGS sample's true size.
+ * Needed because a zero byte in the sample data ends the sample prematurely.
+ */
+uint calcTrueSampleSize(byte *sample, uint size) {
+ if (sample == NULL) { // Check for an erroneous input value
+ warning("Agi::calcTrueSampleSize: A NULL-pointer parameter");
+ return size; // Might as well return 0
+ } else { // Input values are ok
+ // Search for a zero byte in the sample data,
+ // as that would end the sample prematurely.
+ for (uint i = 0; i < size; i++)
+ if (sample[i] == 0)
+ return i;
+ // If no zero was found in the sample, then return its whole size.
+ return size;
+ }
+}
+
+/**
* Load an Apple IIGS AGI sample resource from the given stream and
* create an AudioStream out of it.
*
@@ -215,6 +234,13 @@ Audio::AudioStream *makeIIgsSampleStream(Common::SeekableReadStream &stream, int
byte *sampleData = (byte *) malloc(header.sampleSize);
uint32 readBytes = stream.read(sampleData, header.sampleSize);
if (readBytes == header.sampleSize) { // Check that we got all the data we requested
+ // Calculate true sample size (A zero byte ends the sample prematurely)
+ uint trueSampleSize = calcTrueSampleSize(sampleData, header.sampleSize);
+ if (trueSampleSize != header.sampleSize) {
+ debugC(3, kDebugLevelSound, "Apple IIGS sample (%d): Size changed from %d to %d (Zero byte encountered)",
+ resnum, header.sampleSize, trueSampleSize);
+ }
+ header.sampleSize = (uint16) trueSampleSize; // Set the true sample size
// Make an audio stream from the mono, 8 bit, unsigned input data
byte flags = Audio::Mixer::FLAG_AUTOFREE | Audio::Mixer::FLAG_UNSIGNED;
int rate = (int) (1076 * pow(SEMITONE, header.pitch));