diff options
author | Vladimir Menshakov | 2010-01-07 12:01:33 +0000 |
---|---|---|
committer | Vladimir Menshakov | 2010-01-07 12:01:33 +0000 |
commit | c37e772b8cde4c120064e4854f06d1e113bd7a39 (patch) | |
tree | 42ba1aa646f6b8758b88f5645e937eb14091acae /engines/teenagent | |
parent | 58aab46f06834db23acbd75747b4df48b11f2a4c (diff) | |
download | scummvm-rg350-c37e772b8cde4c120064e4854f06d1e113bd7a39.tar.gz scummvm-rg350-c37e772b8cde4c120064e4854f06d1e113bd7a39.tar.bz2 scummvm-rg350-c37e772b8cde4c120064e4854f06d1e113bd7a39.zip |
cleaned up player, fixed invalid delete's and memory leaks
svn-id: r47106
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; |