diff options
Diffstat (limited to 'engines/teenagent')
-rw-r--r-- | engines/teenagent/music.cpp | 19 | ||||
-rw-r--r-- | engines/teenagent/music.h | 27 |
2 files changed, 21 insertions, 25 deletions
diff --git a/engines/teenagent/music.cpp b/engines/teenagent/music.cpp index 1a0b51a6e8..3e9731049f 100644 --- a/engines/teenagent/music.cpp +++ b/engines/teenagent/music.cpp @@ -51,10 +51,7 @@ bool MusicPlayer::load(int id) { stream->read(header, 4); //check header? - memset(_samples, 0, sizeof(_samples)); - // Load the samples - sampleCount = stream->readByte(); debug(0, "sampleCount = %d", sampleCount); @@ -70,25 +67,15 @@ bool MusicPlayer::load(int id) { if (in == 0) { warning("load: invalid sample %d (0x%02x)", sample, sample); - _samples[sample].data = NULL; - _samples[sample].size = 0; + _samples[sample].clear(); continue; } - byte *sampleData = new byte[sampleSize]; - in->read(sampleData, sampleSize); - - // Convert the sample from signed to unsigned - for (uint32 i = 0; i < sampleSize; i++) - *sampleData ^= 0x80; - - delete _samples[sample].data; - _samples[sample].data = sampleData; - _samples[sample].size = sampleSize; + _samples[sample].resize(sampleSize); + in->read(_samples[sample].data, sampleSize); } // Load the music data - _rows.clear(); Row row; diff --git a/engines/teenagent/music.h b/engines/teenagent/music.h index 5a8caba9d7..56f3db602e 100644 --- a/engines/teenagent/music.h +++ b/engines/teenagent/music.h @@ -54,18 +54,27 @@ protected: } channels[3]; }; - struct { - const byte *data; - uint32 size; + struct Sample { + byte *data; + uint size; + Sample(): data(0), size(0) {} + ~Sample() { delete[] data; } + + void resize(uint s) { + if (s != size) { + delete[] data; + data = new byte[s]; + size = s; + } + } + void clear() { + delete[] data; + data = 0; + size = 0; + } } _samples[256]; byte sampleCount; - struct { - byte volume; - const byte *data; - uint32 size; - } _channels[3]; - Common::Array<Row> _rows; uint _currRow; |