2006-10-16 22:20:46 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2006 The ScummVM project
|
|
|
|
* Based on code by madmoose
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
|
|
|
|
#include "sound/mods/module.h"
|
|
|
|
|
2006-10-23 01:37:59 +00:00
|
|
|
#include "common/util.h"
|
2006-10-16 22:20:46 +00:00
|
|
|
|
2006-10-23 01:37:59 +00:00
|
|
|
namespace Modules {
|
2006-10-19 05:37:22 +00:00
|
|
|
|
2006-10-23 01:37:59 +00:00
|
|
|
bool Module::load(Common::ReadStream &st) {
|
2006-10-16 22:20:46 +00:00
|
|
|
st.read(songname, 20);
|
2006-10-23 01:37:59 +00:00
|
|
|
songname[20] = '\0';
|
2006-10-16 22:20:46 +00:00
|
|
|
|
2007-01-27 00:11:15 +00:00
|
|
|
for (int i = 0; i < NUM_SAMPLES; ++i) {
|
2006-10-16 22:20:46 +00:00
|
|
|
st.read(sample[i].name, 22);
|
|
|
|
sample[i].name[22] = '\0';
|
|
|
|
sample[i].len = 2 * st.readUint16BE();
|
|
|
|
|
|
|
|
sample[i].finetune = st.readByte();
|
|
|
|
assert(sample[i].finetune < 0x10);
|
|
|
|
|
|
|
|
sample[i].vol = st.readByte();
|
|
|
|
sample[i].repeat = 2 * st.readUint16BE();
|
|
|
|
sample[i].replen = 2 * st.readUint16BE();
|
|
|
|
}
|
|
|
|
|
2007-01-27 00:33:38 +00:00
|
|
|
songlen = st.readByte();
|
|
|
|
undef = st.readByte();
|
2006-10-16 22:20:46 +00:00
|
|
|
|
|
|
|
st.read(songpos, 128);
|
2006-10-23 01:37:59 +00:00
|
|
|
st.read(sig, 4);
|
|
|
|
if (memcmp(sig, "M.K.", 4)) {
|
|
|
|
warning("Expected 'M.K.' in protracker module");
|
|
|
|
return false;
|
|
|
|
}
|
2006-10-16 22:20:46 +00:00
|
|
|
|
|
|
|
int maxpattern = 0;
|
|
|
|
for (int i = 0; i < 128; ++i)
|
|
|
|
if (maxpattern < songpos[i])
|
|
|
|
maxpattern = songpos[i];
|
|
|
|
|
|
|
|
pattern = new pattern_t[maxpattern + 1];
|
|
|
|
|
|
|
|
for (int i = 0; i <= maxpattern; ++i) {
|
|
|
|
for (int j = 0; j < 64; ++j) {
|
|
|
|
for (int k = 0; k < 4; ++k) {
|
|
|
|
uint32 note = st.readUint32BE();
|
|
|
|
pattern[i][j][k].sample = (note & 0xf0000000) >> 24 | (note & 0x0000f000) >> 12;
|
|
|
|
pattern[i][j][k].period = (note >> 16) & 0xfff;
|
|
|
|
pattern[i][j][k].effect = note & 0xfff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-27 00:11:15 +00:00
|
|
|
for (int i = 0; i < NUM_SAMPLES; ++i) {
|
2006-10-16 22:20:46 +00:00
|
|
|
if (!sample[i].len)
|
|
|
|
sample[i].data = 0;
|
|
|
|
else {
|
2006-10-23 01:37:59 +00:00
|
|
|
sample[i].data = new int8[sample[i].len];
|
2006-10-16 22:20:46 +00:00
|
|
|
st.read((byte *)sample[i].data, sample[i].len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-23 01:37:59 +00:00
|
|
|
if (!st.eos())
|
|
|
|
warning("Expected EOS on module stream");
|
2006-10-16 22:20:46 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Module::Module() {
|
2006-10-18 18:34:40 +00:00
|
|
|
pattern = 0;
|
2007-01-27 00:11:15 +00:00
|
|
|
for (int i = 0; i < NUM_SAMPLES; ++i) {
|
2006-10-18 18:34:40 +00:00
|
|
|
sample[i].data = 0;
|
2006-10-16 22:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Module::~Module() {
|
|
|
|
delete[] pattern;
|
2007-01-27 00:11:15 +00:00
|
|
|
for (int i = 0; i < NUM_SAMPLES; ++i) {
|
2006-10-16 22:20:46 +00:00
|
|
|
delete[] sample[i].data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Modules
|