[Scummvm-cvs-logs] SF.net SVN: scummvm:[43703] scummvm/trunk
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Mon Aug 24 22:31:01 CEST 2009
Revision: 43703
http://scummvm.svn.sourceforge.net/scummvm/?rev=43703&view=rev
Author: lordhoto
Date: 2009-08-24 20:31:01 +0000 (Mon, 24 Aug 2009)
Log Message:
-----------
Merge the gsoc2009-mods branch into trunk (along with some svn:mergeinfo property removals).
Modified Paths:
--------------
scummvm/trunk/README
scummvm/trunk/engines/kyra/kyra_lok.cpp
scummvm/trunk/engines/kyra/kyra_lok.h
scummvm/trunk/engines/kyra/kyra_v1.cpp
scummvm/trunk/engines/kyra/module.mk
scummvm/trunk/engines/kyra/seqplayer.cpp
scummvm/trunk/engines/kyra/sequences_lok.cpp
scummvm/trunk/engines/kyra/sound.cpp
scummvm/trunk/engines/kyra/sound.h
scummvm/trunk/engines/kyra/sound_intern.h
scummvm/trunk/engines/kyra/staticres.cpp
scummvm/trunk/engines/scumm/module.mk
scummvm/trunk/engines/scumm/music.h
scummvm/trunk/engines/scumm/scumm.cpp
scummvm/trunk/engines/scumm/scumm.h
scummvm/trunk/engines/scumm/sound.cpp
scummvm/trunk/sound/mods/paula.cpp
scummvm/trunk/sound/mods/paula.h
scummvm/trunk/sound/mods/soundfx.cpp
scummvm/trunk/sound/module.mk
Added Paths:
-----------
scummvm/trunk/engines/kyra/sound_amiga.cpp
scummvm/trunk/engines/scumm/player_v4a.cpp
scummvm/trunk/engines/scumm/player_v4a.h
scummvm/trunk/sound/mods/maxtrax.cpp
scummvm/trunk/sound/mods/maxtrax.h
scummvm/trunk/sound/mods/tfmx.cpp
scummvm/trunk/sound/mods/tfmx.h
Property Changed:
----------------
scummvm/trunk/backends/fs/ds/
scummvm/trunk/backends/platform/ds/
scummvm/trunk/backends/platform/iphone/osys_main.cpp
scummvm/trunk/backends/platform/iphone/osys_main.h
scummvm/trunk/backends/platform/wii/wii.mk
scummvm/trunk/engines/parallaction/sound_ns.cpp
scummvm/trunk/engines/sci/
scummvm/trunk/engines/sci/decompressor.cpp
scummvm/trunk/engines/sci/decompressor.h
scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp
scummvm/trunk/engines/sci/gfx/picfill.cpp
scummvm/trunk/engines/sci/gfx/res_cursor.cpp
scummvm/trunk/engines/sci/gfx/res_font.cpp
scummvm/trunk/engines/sci/gfx/res_pal.cpp
scummvm/trunk/engines/sci/gfx/res_pic.cpp
scummvm/trunk/engines/sci/gfx/res_view.cpp
scummvm/trunk/engines/sci/module.mk
scummvm/trunk/engines/sci/resource.cpp
scummvm/trunk/engines/sci/resource.h
scummvm/trunk/engines/sci/sfx/softseq/adlib.cpp
scummvm/trunk/engines/sci/sfx/softseq/pcjr.cpp
scummvm/trunk/engines/sci/vocabulary.cpp
scummvm/trunk/engines/sci/vocabulary.h
scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp
scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h
scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp
scummvm/trunk/graphics/video/coktelvideo/indeo3.h
scummvm/trunk/graphics/video/dxa_decoder.cpp
scummvm/trunk/graphics/video/dxa_decoder.h
scummvm/trunk/graphics/video/flic_decoder.cpp
scummvm/trunk/graphics/video/flic_decoder.h
scummvm/trunk/graphics/video/smk_decoder.cpp
scummvm/trunk/graphics/video/smk_decoder.h
scummvm/trunk/gui/GuiManager.cpp
scummvm/trunk/gui/GuiManager.h
scummvm/trunk/sound/iff_sound.cpp
scummvm/trunk/sound/iff_sound.h
scummvm/trunk/sound/vag.cpp
scummvm/trunk/sound/vag.h
Modified: scummvm/trunk/README
===================================================================
--- scummvm/trunk/README 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/README 2009-08-24 20:31:01 UTC (rev 43703)
@@ -779,7 +779,7 @@
original game.
The Legend of Kyrandia:
- - No music or sound effects in the Amiga and Macintosh floppy versions.
+ - No music or sound effects in the Macintosh floppy versions.
- Macintosh CD is using included DOS music and sound effects.
- PC-9821 version lacks support for sound effects.
Property changes on: scummvm/trunk/backends/fs/ds
___________________________________________________________________
Deleted: svn:mergeinfo
- /scummvm/branches/branch-0-13-0/backends/fs/ds:35922-39517
Property changes on: scummvm/trunk/backends/platform/ds
___________________________________________________________________
Deleted: svn:mergeinfo
- /scummvm/branches/branch-0-13-0/backends/platform/ds:35922-39516
Property changes on: scummvm/trunk/backends/platform/iphone/osys_main.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/backends/platform/iphone/osys_main.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/backends/platform/wii/wii.mk
___________________________________________________________________
Deleted: svn:mergeinfo
-
Modified: scummvm/trunk/engines/kyra/kyra_lok.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra_lok.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/kyra_lok.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -183,8 +183,13 @@
_sound->setSoundList(&_soundData[kMusicIntro]);
- _trackMap = _dosTrackMap;
- _trackMapSize = _dosTrackMapSize;
+ if (_flags.platform == Common::kPlatformAmiga) {
+ _trackMap = _amigaTrackMap;
+ _trackMapSize = _amigaTrackMapSize;
+ } else {
+ _trackMap = _dosTrackMap;
+ _trackMapSize = _dosTrackMapSize;
+ }
if (!_sound->init())
error("Couldn't init sound");
Modified: scummvm/trunk/engines/kyra/kyra_lok.h
===================================================================
--- scummvm/trunk/engines/kyra/kyra_lok.h 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/kyra_lok.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -507,6 +507,9 @@
static const int8 _dosTrackMap[];
static const int _dosTrackMapSize;
+ static const int8 _amigaTrackMap[];
+ static const int _amigaTrackMapSize;
+
// TODO: get rid of all variables having pointers to the static resources if possible
// i.e. let them directly use the _staticres functions
void initStaticResource();
Modified: scummvm/trunk/engines/kyra/kyra_v1.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra_v1.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/kyra_v1.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -50,7 +50,10 @@
_emc = 0;
_debugger = 0;
- _gameSpeed = 60;
+ if (_flags.platform == Common::kPlatformAmiga)
+ _gameSpeed = 50;
+ else
+ _gameSpeed = 60;
_tickLength = (uint8)(1000.0 / _gameSpeed);
_trackMap = 0;
@@ -114,6 +117,8 @@
_sound = new SoundPC98(this, _mixer);
else
_sound = new SoundTownsPC98_v2(this, _mixer);
+ } else if (_flags.platform == Common::kPlatformAmiga) {
+ _sound = new SoundAmiga(this, _mixer);
} else if (midiDriver == MD_ADLIB) {
_sound = new SoundAdlibPC(this, _mixer);
} else {
Modified: scummvm/trunk/engines/kyra/module.mk
===================================================================
--- scummvm/trunk/engines/kyra/module.mk 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/module.mk 2009-08-24 20:31:01 UTC (rev 43703)
@@ -50,6 +50,7 @@
sequences_hof.o \
sequences_mr.o \
sound_adlib.o \
+ sound_amiga.o \
sound_digital.o \
sound_midi.o \
sound_pcspk.o \
Modified: scummvm/trunk/engines/kyra/seqplayer.cpp
===================================================================
--- scummvm/trunk/engines/kyra/seqplayer.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/seqplayer.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -414,8 +414,6 @@
void SeqPlayer::s1_playEffect() {
uint8 track = *_seqData++;
- if (_vm->gameFlags().platform == Common::kPlatformAmiga)
- return;
_vm->delay(3 * _vm->tickLength());
_sound->playSoundEffect(track);
}
@@ -423,9 +421,6 @@
void SeqPlayer::s1_playTrack() {
uint8 msg = *_seqData++;
- if (_vm->gameFlags().platform == Common::kPlatformAmiga)
- return;
-
if (msg == 1) {
_sound->beginFadeOut();
} else {
Modified: scummvm/trunk/engines/kyra/sequences_lok.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sequences_lok.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/sequences_lok.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -110,7 +110,7 @@
_seq->setCopyViewOffs(true);
_screen->setFont(Screen::FID_8_FNT);
- if (_flags.platform != Common::kPlatformFMTowns && _flags.platform != Common::kPlatformPC98)
+ if (_flags.platform != Common::kPlatformFMTowns && _flags.platform != Common::kPlatformPC98 && _flags.platform != Common::kPlatformAmiga)
snd_playTheme(0, 2);
_text->setTalkCoords(144);
@@ -994,6 +994,14 @@
snd_playWanderScoreViaMap(50, 1);
setupPanPages();
+ if (_flags.platform == Common::kPlatformAmiga) {
+ _sound->loadSoundFile(kMusicFinale);
+
+ // The original started song 0 directly here. Since our player
+ // uses 0, 1 for stop and fade we start song 0 with 2
+ _sound->playTrack(2);
+ }
+
_finalA = createWSAMovie();
assert(_finalA);
_finalA->open("finala.wsa", 1, 0);
Modified: scummvm/trunk/engines/kyra/sound.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/sound.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -215,6 +215,13 @@
_sound->playTrack(command);
}
}
+ } else if (_flags.platform == Common::kPlatformAmiga) {
+ if (_curMusicTheme != 1)
+ snd_playTheme(1, -1);
+
+ assert(command < _trackMapSize);
+ if (_trackMap[_lastMusicCommand] != _trackMap[command])
+ _sound->playTrack(_trackMap[command]);
}
_lastMusicCommand = command;
Modified: scummvm/trunk/engines/kyra/sound.h
===================================================================
--- scummvm/trunk/engines/kyra/sound.h 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/sound.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -55,7 +55,8 @@
kMidiGM,
kTowns,
kPC98,
- kPCSpkr
+ kPCSpkr,
+ kAmiga
};
virtual kType getMusicType() const = 0;
Copied: scummvm/trunk/engines/kyra/sound_amiga.cpp (from rev 43702, scummvm/branches/gsoc2009-mods/engines/kyra/sound_amiga.cpp)
===================================================================
--- scummvm/trunk/engines/kyra/sound_amiga.cpp (rev 0)
+++ scummvm/trunk/engines/kyra/sound_amiga.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -0,0 +1,239 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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/system.h"
+#include "common/mutex.h"
+#include "kyra/resource.h"
+#include "kyra/sound_intern.h"
+
+#include "sound/mixer.h"
+#include "sound/mods/maxtrax.h"
+#include "sound/audiostream.h"
+
+namespace {
+
+FORCEINLINE uint8 sfxTableGetNote(const byte* address) {
+ return (uint8)address[0];
+}
+FORCEINLINE uint8 sfxTableGetPatch(const byte* address) {
+ return (uint8)address[1];
+}
+FORCEINLINE uint16 sfxTableGetDuration(const byte* address) {
+ return READ_BE_UINT16(&address[4]);
+}
+FORCEINLINE int8 sfxTableGetVolume(const byte* address) {
+ return (int8)address[6];
+}
+FORCEINLINE int8 sfxTableGetPan(const byte* address) {
+ return (int8)address[7];
+}
+
+} // end of namespace
+
+namespace Kyra {
+
+SoundAmiga::SoundAmiga(KyraEngine_v1 *vm, Audio::Mixer *mixer)
+ : Sound(vm, mixer),
+ _driver(0),
+ _musicHandle(),
+ _fileLoaded(kFileNone),
+ _tableSfxIntro(),
+ _tableSfxGame() {
+}
+
+SoundAmiga::~SoundAmiga() {
+ _mixer->stopHandle(_musicHandle);
+ delete _driver;
+}
+
+extern const byte LoKAmigaSfxIntro[];
+extern const byte LoKAmigaSfxGame[];
+
+bool SoundAmiga::init() {
+ _driver = new Audio::MaxTrax(_mixer->getOutputRate(), true);
+ _tableSfxIntro = LoKAmigaSfxIntro;
+ _tableSfxGame = LoKAmigaSfxGame;
+
+ return _driver != 0 && _tableSfxIntro && _tableSfxGame;
+}
+
+void SoundAmiga::loadSoundFile(uint file) {
+ debugC(5, kDebugLevelSound, "SoundAmiga::loadSoundFile(%d)", file);
+
+ static const char *const tableFilenames[3][2] = {
+ { "introscr.mx", "introinst.mx" },
+ { "kyramusic.mx", 0 },
+ { "finalescr.mx", "introinst.mx" }
+ };
+ assert(file < ARRAYSIZE(tableFilenames));
+ if (_fileLoaded == (FileType)file)
+ return;
+ const char* scoreName = tableFilenames[file][0];
+ const char* sampleName = tableFilenames[file][1];
+ bool loaded = false;
+
+ Common::SeekableReadStream *scoreIn = _vm->resource()->createReadStream(scoreName);
+ if (sampleName) {
+ Common::SeekableReadStream *sampleIn = _vm->resource()->createReadStream(sampleName);
+ if (scoreIn && sampleIn) {
+ _fileLoaded = kFileNone;
+ loaded = _driver->load(*scoreIn, true, false);
+ loaded = loaded && _driver->load(*sampleIn, false, true);
+ } else
+ warning("SoundAmiga: missing atleast one of those music files: %s, %s", scoreName, sampleName);
+ delete sampleIn;
+ } else {
+ if (scoreIn) {
+ _fileLoaded = kFileNone;
+ loaded = _driver->load(*scoreIn);
+ } else
+ warning("SoundAmiga: missing music file: %s", scoreName);
+ }
+ delete scoreIn;
+
+ if (loaded)
+ _fileLoaded = (FileType)file;
+}
+
+void SoundAmiga::playTrack(uint8 track) {
+ debugC(5, kDebugLevelSound, "SoundAmiga::playTrack(%d)", track);
+
+ static const byte tempoIntro[] = { 0x46, 0x55, 0x3C, 0x41 };
+ static const byte tempoFinal[] = { 0x78, 0x50 };
+ static const byte tempoIngame[] = {
+ 0x64, 0x64, 0x64, 0x64, 0x64, 0x73, 0x4B, 0x64,
+ 0x64, 0x64, 0x55, 0x9C, 0x6E, 0x91, 0x78, 0x84,
+ 0x32, 0x64, 0x64, 0x6E, 0x3C, 0xD8, 0xAF
+ };
+ static const byte loopIngame[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00
+ };
+
+ int score = -1;
+ bool loop = false;
+ byte volume = 0x40;
+ byte tempo = 0;
+
+
+ switch (_fileLoaded) {
+ case kFileIntro:
+ if (track >= 2 && track < ARRAYSIZE(tempoIntro) + 2) {
+ score = track - 2;
+ tempo = tempoIntro[score];
+ }
+ break;
+
+ case kFileGame:
+ if (track >= 11 && track < ARRAYSIZE(tempoIngame) + 11) {
+ score = track - 11;
+ loop = loopIngame[score] != 0;
+ tempo = tempoIngame[score];
+ }
+ break;
+
+ case kFileFinal:
+ // score 0 gets started immediately after loading the music-files with different tempo.
+ // we need to define a track-value for the fake call of this function
+ if (track >= 2 && track < ARRAYSIZE(tempoFinal) + 2) {
+ score = track - 2;
+ loop = true;
+ tempo = tempoFinal[score];
+ }
+ break;
+
+ default:
+ return;
+ }
+
+ if (score >= 0) {
+ if (_musicEnabled && _driver->playSong(score, loop)) {
+ _driver->setVolume(volume);
+ _driver->setTempo(tempo << 4);
+ if (!_mixer->isSoundHandleActive(_musicHandle))
+ _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
+ }
+ } else if (track == 0)
+ _driver->stopMusic();
+ else if (track == 1)
+ beginFadeOut();
+}
+
+void SoundAmiga::haltTrack() {
+ debugC(5, kDebugLevelSound, "SoundAmiga::haltTrack()");
+ _driver->stopMusic();
+}
+
+void SoundAmiga::beginFadeOut() {
+ debugC(5, kDebugLevelSound, "SoundAmiga::beginFadeOut()");
+ for (int i = 0x3F; i >= 0; --i) {
+ _driver->setVolume((byte)i);
+ _vm->delay(_vm->tickLength());
+ }
+
+ _driver->stopMusic();
+ _vm->delay(_vm->tickLength());
+ _driver->setVolume(0x40);
+}
+
+void SoundAmiga::playSoundEffect(uint8 track) {
+ debugC(5, kDebugLevelSound, "SoundAmiga::playSoundEffect(%d)", track);
+ const byte* tableEntry = 0;
+ bool pan = false;
+
+ switch (_fileLoaded) {
+ case kFileFinal:
+ case kFileIntro:
+ // We only allow playing of sound effects, which are included in the table.
+ if (track < 40) {
+ tableEntry = &_tableSfxIntro[track * 8];
+ pan = (sfxTableGetPan(tableEntry) != 0);
+ }
+ break;
+
+ case kFileGame:
+ if (0x61 <= track && track <= 0x63)
+ playTrack(track - 0x4F);
+
+ assert(track < 120);
+ if (sfxTableGetNote(&_tableSfxGame[track * 8])) {
+ tableEntry = &_tableSfxGame[track * 8];
+ pan = (sfxTableGetPan(tableEntry) != 0) && (sfxTableGetPan(tableEntry) != 2);
+ }
+ break;
+ default:
+ ;
+ }
+
+ if (_sfxEnabled && tableEntry) {
+ const bool success = _driver->playNote(sfxTableGetNote(tableEntry), sfxTableGetPatch(tableEntry), sfxTableGetDuration(tableEntry), sfxTableGetVolume(tableEntry), pan);
+ if (success && !_mixer->isSoundHandleActive(_musicHandle))
+ _mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_musicHandle, _driver, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
+ }
+}
+
+} // end of namespace Kyra
+
Modified: scummvm/trunk/engines/kyra/sound_intern.h
===================================================================
--- scummvm/trunk/engines/kyra/sound_intern.h 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/sound_intern.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -37,6 +37,7 @@
namespace Audio {
class PCSpeaker;
+class MaxTrax;
} // end of namespace Audio
namespace Kyra {
@@ -284,7 +285,34 @@
static const uint8 _noteTable2[];
};
+class SoundAmiga : public Sound {
+public:
+ SoundAmiga(KyraEngine_v1 *vm, Audio::Mixer *mixer);
+ ~SoundAmiga();
+
+ virtual kType getMusicType() const { return kAmiga; } //FIXME
+
+ bool init();
+
+ void process() {}
+ void loadSoundFile(uint file);
+ void loadSoundFile(Common::String) {}
+
+ void playTrack(uint8 track);
+ void haltTrack();
+ void beginFadeOut();
+
+ int32 voicePlay(const char *file, Audio::SoundHandle *handle, uint8 volume, bool isSfx) { return -1; }
+ void playSoundEffect(uint8);
+
+protected:
+ Audio::MaxTrax *_driver;
+ Audio::SoundHandle _musicHandle;
+ enum FileType { kFileNone = -1, kFileIntro = 0, kFileGame = 1, kFileFinal = 2 } _fileLoaded;
+ const byte *_tableSfxIntro;
+ const byte *_tableSfxGame;
+};
+
} // end of namespace Kyra
#endif
-
Modified: scummvm/trunk/engines/kyra/staticres.cpp
===================================================================
--- scummvm/trunk/engines/kyra/staticres.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/kyra/staticres.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -2356,6 +2356,18 @@
const int KyraEngine_LoK::_dosTrackMapSize = ARRAYSIZE(KyraEngine_LoK::_dosTrackMap);
+const int8 KyraEngine_LoK::_amigaTrackMap[] = {
+ 0, 1, 32, 26, 31, 30, 33, 33,
+ 32, 17, 27, 32, 25, 29, 25, 24,
+ 23, 26, 26, 30, 28, 21, 21, 15,
+ 3, 15, 23, 25, 33, 21, 30, 22,
+ 15, 3, 33, 11, 12, 13, 14, 22,
+ 22, 22, 3, 3, 3, 23, 3, 3,
+ 23, 3, 3, 3, 3, 3, 3, 33
+};
+
+const int KyraEngine_LoK::_amigaTrackMapSize = ARRAYSIZE(KyraEngine_LoK::_amigaTrackMap);
+
// kyra engine v2 static data
const int GUI_v2::_sliderBarsPosition[] = {
@@ -3378,4 +3390,172 @@
#endif // ENABLE_LOL
+// TODO: fileoffset = 0x32D5C, len = 40 * 8
+extern const byte LoKAmigaSfxIntro[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x6E, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x6E, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x6E, 0x00,
+ 0x3C, 0x13, 0x00, 0x00, 0x1B, 0x91, 0x6E, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x16, 0x00, 0x00, 0x26, 0x77, 0x6E, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x17, 0x00, 0x00, 0x11, 0x98, 0x6E, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x6E, 0x00,
+ 0x3C, 0x18, 0x00, 0x00, 0x22, 0xD1, 0x6E, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x6E, 0x00,
+ 0x45, 0x03, 0x00, 0x00, 0x02, 0x24, 0x6E, 0x00,
+ 0x3C, 0x16, 0x00, 0x00, 0x26, 0x77, 0x6E, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+// TODO: fileoffset = 0x2C55E, len = 120 * 8
+extern const byte LoKAmigaSfxGame[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x13, 0x00, 0x00, 0x01, 0x56, 0x78, 0x02,
+ 0x3C, 0x14, 0x00, 0x00, 0x27, 0x2C, 0x78, 0x02,
+ 0x3C, 0x15, 0x00, 0x00, 0x1B, 0x91, 0x78, 0x02,
+ 0x3C, 0x16, 0x00, 0x00, 0x1E, 0x97, 0x78, 0x02,
+ 0x3C, 0x17, 0x00, 0x00, 0x12, 0x2B, 0x78, 0x02,
+ 0x3C, 0x16, 0x00, 0x00, 0x1E, 0x97, 0x78, 0x02,
+ 0x45, 0x03, 0x00, 0x00, 0x02, 0x24, 0x78, 0x02,
+ 0x3C, 0x16, 0x00, 0x00, 0x1E, 0x97, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x2C, 0x04, 0x00, 0x00, 0x09, 0x10, 0x78, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x3C, 0x1A, 0x00, 0x00, 0x3A, 0xEB, 0x78, 0x02,
+ 0x25, 0x1B, 0x00, 0x00, 0x13, 0x8B, 0x78, 0x02,
+ 0x18, 0x03, 0x00, 0x00, 0x0F, 0x52, 0x78, 0x02,
+ 0x3E, 0x1C, 0x00, 0x00, 0x06, 0x22, 0x78, 0x02,
+ 0x3B, 0x1C, 0x00, 0x00, 0x07, 0x54, 0x78, 0x02,
+ 0x16, 0x03, 0x00, 0x00, 0x20, 0x6F, 0x78, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x3C, 0x1D, 0x00, 0x00, 0x09, 0xEA, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x14, 0x00, 0x00, 0x27, 0x2C, 0x78, 0x02,
+ 0x3C, 0x1E, 0x00, 0x00, 0x03, 0x6E, 0x78, 0x02,
+ 0x3C, 0x17, 0x00, 0x00, 0x12, 0x2B, 0x78, 0x02,
+ 0x4E, 0x0B, 0x00, 0x00, 0x09, 0x91, 0x78, 0x02,
+ 0x47, 0x1B, 0x00, 0x00, 0x02, 0xBC, 0x78, 0x02,
+ 0x4C, 0x1B, 0x00, 0x00, 0x02, 0x11, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x13, 0x00, 0x00, 0x01, 0x56, 0x78, 0x02,
+ 0x3C, 0x13, 0x00, 0x00, 0x01, 0x56, 0x78, 0x02,
+ 0x3C, 0x1F, 0x00, 0x00, 0x0E, 0x9E, 0x78, 0x02,
+ 0x3C, 0x20, 0x00, 0x00, 0x01, 0x0C, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x3C, 0x21, 0x00, 0x00, 0x0F, 0x7C, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x2A, 0x0B, 0x00, 0x00, 0x4C, 0x47, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x1B, 0x00, 0x00, 0x05, 0x28, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x2C, 0x04, 0x00, 0x00, 0x09, 0x10, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x22, 0x00, 0x00, 0x0A, 0xEE, 0x78, 0x02,
+ 0x3C, 0x16, 0x00, 0x00, 0x1E, 0x97, 0x78, 0x02,
+ 0x3C, 0x15, 0x00, 0x00, 0x1B, 0x91, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x14, 0x00, 0x00, 0x27, 0x2C, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x22, 0x00, 0x00, 0x0A, 0xEE, 0x78, 0x02,
+ 0x3C, 0x14, 0x00, 0x00, 0x27, 0x2C, 0x78, 0x02,
+ 0x32, 0x23, 0x00, 0x00, 0x14, 0x19, 0x9C, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x17, 0x1C, 0x78, 0x02,
+ 0x3C, 0x14, 0x00, 0x00, 0x27, 0x2C, 0x78, 0x02,
+ 0x3E, 0x1C, 0x00, 0x00, 0x06, 0x22, 0x78, 0x02,
+ 0x43, 0x13, 0x00, 0x00, 0x02, 0x01, 0x78, 0x02,
+ 0x3C, 0x24, 0x00, 0x00, 0x12, 0x43, 0x5A, 0x02,
+ 0x3E, 0x20, 0x00, 0x00, 0x00, 0xEE, 0x78, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x29, 0x04, 0x00, 0x00, 0x19, 0xEA, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x20, 0x00, 0x00, 0x01, 0x0C, 0x78, 0x02,
+ 0x3C, 0x25, 0x00, 0x00, 0x30, 0xB6, 0x78, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x16, 0x00, 0x00, 0x1E, 0x97, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x1A, 0x00, 0x00, 0x3A, 0xEB, 0x78, 0x02,
+ 0x1B, 0x04, 0x00, 0x00, 0x39, 0xF3, 0x78, 0x02,
+ 0x30, 0x23, 0x00, 0x00, 0x16, 0x99, 0x50, 0x02,
+ 0x3C, 0x15, 0x00, 0x00, 0x1B, 0x91, 0x78, 0x02,
+ 0x29, 0x06, 0x00, 0x00, 0x19, 0xEA, 0x50, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x1A, 0x00, 0x00, 0x3A, 0xEB, 0x78, 0x02,
+ 0x3C, 0x19, 0x00, 0x00, 0x25, 0x2C, 0x78, 0x02,
+ 0x3C, 0x26, 0x00, 0x00, 0x07, 0x13, 0x78, 0x02,
+ 0x3C, 0x26, 0x00, 0x00, 0x07, 0x13, 0x78, 0x02,
+ 0x3C, 0x14, 0x00, 0x00, 0x27, 0x2C, 0x78, 0x02,
+ 0x30, 0x23, 0x00, 0x00, 0x16, 0x99, 0x50, 0x02,
+ 0x30, 0x23, 0x00, 0x00, 0x16, 0x99, 0x50, 0x02,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3C, 0x13, 0x00, 0x00, 0x01, 0x56, 0x78, 0x02
+};
+
} // End of namespace Kyra
Property changes on: scummvm/trunk/engines/parallaction/sound_ns.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/decompressor.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/decompressor.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/gfx_resmgr.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/picfill.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/res_cursor.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/res_font.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/res_pal.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/res_pic.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/gfx/res_view.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/module.mk
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/resource.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/resource.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/sfx/softseq/adlib.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/sfx/softseq/pcjr.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/vocabulary.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/engines/sci/vocabulary.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Modified: scummvm/trunk/engines/scumm/module.mk
===================================================================
--- scummvm/trunk/engines/scumm/module.mk 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/scumm/module.mk 2009-08-24 20:31:01 UTC (rev 43703)
@@ -40,6 +40,7 @@
player_v2a.o \
player_v2cms.o \
player_v3a.o \
+ player_v4a.o \
resource_v2.o \
resource_v3.o \
resource_v4.o \
Modified: scummvm/trunk/engines/scumm/music.h
===================================================================
--- scummvm/trunk/engines/scumm/music.h 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/scumm/music.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -81,12 +81,6 @@
* @return the music timer
*/
virtual int getMusicTimer() const { return 0; }
-
- /**
- * Terminate the music engine. Called just before the music engine
- * is deleted.
- */
- virtual void terminate() {}
};
} // End of namespace Scumm
Copied: scummvm/trunk/engines/scumm/player_v4a.cpp (from rev 43702, scummvm/branches/gsoc2009-mods/engines/scumm/player_v4a.cpp)
===================================================================
--- scummvm/trunk/engines/scumm/player_v4a.cpp (rev 0)
+++ scummvm/trunk/engines/scumm/player_v4a.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -0,0 +1,193 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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 "engines/engine.h"
+#include "scumm/player_v4a.h"
+#include "scumm/scumm.h"
+
+#include "common/file.h"
+
+namespace Scumm {
+
+Player_V4A::Player_V4A(ScummEngine *scumm, Audio::Mixer *mixer)
+ : _vm(scumm),
+ _mixer(mixer),
+ _tfmxMusic(_mixer->getOutputRate(), true),
+ _tfmxSfx(_mixer->getOutputRate(), true),
+ _musicHandle(),
+ _sfxHandle(),
+ _musicId(),
+ _sfxSlots(),
+ _initState(0),
+ _signal(0) {
+
+ assert(scumm);
+ assert(mixer);
+ assert(_vm->_game.id == GID_MONKEY_VGA);
+ _tfmxMusic.setSignalPtr(&_signal, 1);
+}
+
+bool Player_V4A::init() {
+ if (_vm->_game.id != GID_MONKEY_VGA)
+ error("player_v4a - unknown game");
+
+ Common::File fileMdat, fileSample;
+
+ if (fileMdat.open("music.dat") && fileSample.open("sample.dat")) {
+ // explicitly request that no instance delets the resources automatically
+ if (_tfmxMusic.load(fileMdat, fileSample, false)) {
+ _tfmxSfx.setModuleData(_tfmxMusic);
+ return true;
+ }
+ } else
+ warning("player_v4a: couldnt load one of the music resources: music.dat, sample.dat");
+
+ return false;
+}
+
+Player_V4A::~Player_V4A() {
+ _mixer->stopHandle(_musicHandle);
+ _mixer->stopHandle(_sfxHandle);
+ _tfmxMusic.freeResources();
+}
+
+void Player_V4A::setMusicVolume(int vol) {
+ debug(5, "player_v4a: setMusicVolume %i", vol);
+}
+
+void Player_V4A::stopAllSounds() {
+ debug(5, "player_v4a: stopAllSounds");
+ if (_initState > 0) {
+ _tfmxMusic.stopSong();
+ _signal = 0;
+ _musicId = 0;
+
+ _tfmxSfx.stopSong();
+ clearSfxSlots();
+ } else
+ _mixer->stopHandle(_musicHandle);
+}
+
+void Player_V4A::stopSound(int nr) {
+ debug(5, "player_v4a: stopSound %d", nr);
+ if (nr == 0)
+ return;
+ if (nr == _musicId) {
+ _musicId = 0;
+ if (_initState > 0)
+ _tfmxMusic.stopSong();
+ else
+ _mixer->stopHandle(_musicHandle);
+ _signal = 0;
+ } else {
+ const int chan = getSfxChan(nr);
+ if (chan != -1) {
+ setSfxSlot(chan, 0);
+ _tfmxSfx.stopMacroEffect(chan);
+ }
+ }
+}
+
+void Player_V4A::startSound(int nr) {
+ static const int8 monkeyCommands[52] = {
+ -1, -2, -3, -4, -5, -6, -7, -8,
+ -9, -10, -11, -12, -13, -14, 18, 17,
+ -17, -18, -19, -20, -21, -22, -23, -24,
+ -25, -26, -27, -28, -29, -30, -31, -32,
+ -33, 16, -35, 0, 1, 2, 3, 7,
+ 8, 10, 11, 4, 5, 14, 15, 12,
+ 6, 13, 9, 19
+ };
+
+ const byte *ptr = _vm->getResourceAddress(rtSound, nr);
+ assert(ptr);
+
+ const int val = ptr[9];
+ if (val < 0 || val >= ARRAYSIZE(monkeyCommands)) {
+ warning("player_v4a: illegal Songnumber %i", val);
+ return;
+ }
+
+ if (!_initState)
+ _initState = init() ? 1 : -1;
+
+ if (_initState < 0)
+ return;
+
+ int index = monkeyCommands[val];
+ const byte type = ptr[6];
+ if (index < 0) { // SoundFX
+ index = -index - 1;
+ debug(3, "player_v4a: play %d: custom %i - %02X", nr, index, type);
+
+ // start an empty Song so timing is setup
+ if (_tfmxSfx.getSongIndex() < 0)
+ _tfmxSfx.doSong(0x18);
+
+ const int chan = _tfmxSfx.doSfx((uint16)index);
+ if (chan >= 0 && chan < ARRAYSIZE(_sfxSlots))
+ setSfxSlot(chan, nr, type);
+ else
+ warning("player_v4a: custom %i is not of required type", index);
+
+ // the Tfmx-player never "ends" the output by itself, so this should be threadsafe
+ if (!_mixer->isSoundHandleActive(_sfxHandle))
+ _mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, &_tfmxSfx, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
+
+ } else { // Song
+ debug(3, "player_v4a: play %d: song %i - %02X", nr, index, type);
+ if (ptr[6] != 0x7F)
+ warning("player_v4a: Song has wrong type");
+
+ _tfmxMusic.doSong(index);
+ _signal = 2;
+
+ // the Tfmx-player never "ends" the output by itself, so this should be threadsafe
+ if (!_mixer->isSoundHandleActive(_musicHandle))
+ _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, &_tfmxMusic, -1, Audio::Mixer::kMaxChannelVolume, 0, false);
+ _musicId = nr;
+ }
+}
+
+int Player_V4A::getMusicTimer() const {
+ // A workaround if the modplayer couldnt load the datafiles - just return a number big enough to pass all tests
+ if (_initState < 0)
+ return 2000;
+ if (_musicId) {
+ // The titlesong (and a few others) is running with ~70 ticks per second and the scale seems to be based on that.
+ // The Game itself doesnt get the timing from the Tfmx Player however, so we just use the elapsed time
+ // 357 ~ 1000 * 25 * (1 / 70)
+ return _mixer->getSoundElapsedTime(_musicHandle) / 357;
+ }
+ return 0;
+}
+
+int Player_V4A::getSoundStatus(int nr) const {
+ // For music the game queues a variable the Tfmx Player sets through a special command.
+ // For sfx there seems to be no way to queue them, and the game doesnt try to.
+ return (nr == _musicId) ? _signal : 0;
+}
+
+} // End of namespace Scumm
Copied: scummvm/trunk/engines/scumm/player_v4a.h (from rev 43702, scummvm/branches/gsoc2009-mods/engines/scumm/player_v4a.h)
===================================================================
--- scummvm/trunk/engines/scumm/player_v4a.h (rev 0)
+++ scummvm/trunk/engines/scumm/player_v4a.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -0,0 +1,98 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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$
+ *
+ */
+
+#ifndef SCUMM_PLAYER_V4A_H
+#define SCUMM_PLAYER_V4A_H
+
+#include "common/scummsys.h"
+#include "scumm/music.h"
+#include "sound/mixer.h"
+#include "sound/mods/tfmx.h"
+
+class Mixer;
+
+namespace Scumm {
+
+class ScummEngine;
+
+/**
+ * Scumm V4 Amiga sound/music driver.
+ */
+class Player_V4A : public MusicEngine {
+public:
+ Player_V4A(ScummEngine *scumm, Audio::Mixer *mixer);
+ virtual ~Player_V4A();
+
+ virtual void setMusicVolume(int vol);
+ virtual void startSound(int sound);
+ virtual void stopSound(int sound);
+ virtual void stopAllSounds();
+ virtual int getMusicTimer() const;
+ virtual int getSoundStatus(int sound) const;
+
+private:
+ ScummEngine *const _vm;
+ Audio::Mixer *const _mixer;
+
+ Audio::Tfmx _tfmxMusic;
+ Audio::Tfmx _tfmxSfx;
+ Audio::SoundHandle _musicHandle;
+ Audio::SoundHandle _sfxHandle;
+
+ int _musicId;
+ uint16 _signal;
+
+ struct SfxChan {
+ int id;
+// byte type;
+ } _sfxSlots[4];
+
+ int8 _initState; // < 0: failed, 0: uninitialised, > 0: initialised
+
+ int getSfxChan(int id) const {
+ for (int i = 0; i < ARRAYSIZE(_sfxSlots); ++i)
+ if (_sfxSlots[i].id == id)
+ return i;
+ return -1;
+ }
+
+ void setSfxSlot(int channel, int id, byte type = 0) {
+ _sfxSlots[channel].id = id;
+// _sfxSlots[channel].type = type;
+ }
+
+ void clearSfxSlots() {
+ for (int i = 0; i < ARRAYSIZE(_sfxSlots); ++i){
+ _sfxSlots[i].id = 0;
+// _sfxSlots[i].type = 0;
+ }
+ }
+
+ bool init();
+};
+
+} // End of namespace Scumm
+
+#endif
Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/scumm/scumm.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -56,6 +56,7 @@
#include "scumm/player_v2.h"
#include "scumm/player_v2a.h"
#include "scumm/player_v3a.h"
+#include "scumm/player_v4a.h"
#include "scumm/he/resource_he.h"
#include "scumm/scumm_v0.h"
#include "scumm/scumm_v8.h"
@@ -284,7 +285,6 @@
_useTalkAnims = false;
_defaultTalkDelay = 0;
_musicType = MDT_NONE;
- _tempMusic = 0;
_saveSound = 0;
memset(_extraBoxFlags, 0, sizeof(_extraBoxFlags));
memset(_scaleSlots, 0, sizeof(_scaleSlots));
@@ -554,10 +554,7 @@
ScummEngine::~ScummEngine() {
Common::clearAllDebugChannels();
- if (_musicEngine) {
- _musicEngine->terminate();
- delete _musicEngine;
- }
+ delete _musicEngine;
_mixer->stopAll();
@@ -1296,7 +1293,6 @@
void ScummEngine::resetScumm() {
int i;
- _tempMusic = 0;
debug(9, "resetScumm");
if (_game.version == 0) {
@@ -1698,7 +1694,7 @@
} else if (_game.platform == Common::kPlatformPCEngine && _game.version == 3) {
// TODO: Add support for music format
} else if (_game.platform == Common::kPlatformAmiga && _game.version <= 4) {
- // TODO: Add support for music format
+ _musicEngine = new Player_V4A(this, _mixer);
} else if (_game.id == GID_MANIAC && _game.version == 1) {
_musicEngine = new Player_V1(this, _mixer, midiDriver != MD_PCSPK);
} else if (_game.version <= 2) {
@@ -1909,17 +1905,6 @@
if (_musicEngine) {
// The music engine generates the timer data for us.
VAR(VAR_MUSIC_TIMER) = _musicEngine->getMusicTimer();
- } else {
- // Used for Money Island 1 (Amiga)
- // TODO: The music delay (given in milliseconds) might have to be tuned a little
- // to get it correct for all games. Without the ability to watch/listen to the
- // original games, I can't do that myself.
- const int MUSIC_DELAY = 350;
- _tempMusic += delta * 1000 / 60; // Convert delta to milliseconds
- if (_tempMusic >= MUSIC_DELAY) {
- _tempMusic -= MUSIC_DELAY;
- VAR(VAR_MUSIC_TIMER) += 1;
- }
}
}
Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/scumm/scumm.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -1139,7 +1139,6 @@
bool _haveActorSpeechMsg;
bool _useTalkAnims;
uint16 _defaultTalkDelay;
- int _tempMusic;
int _saveSound;
bool _native_mt32;
bool _enable_gs;
Modified: scummvm/trunk/engines/scumm/sound.cpp
===================================================================
--- scummvm/trunk/engines/scumm/sound.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/engines/scumm/sound.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -436,26 +436,6 @@
if (_vm->_game.id == GID_MONKEY_VGA || _vm->_game.id == GID_MONKEY_EGA
|| (_vm->_game.id == GID_MONKEY && _vm->_game.platform == Common::kPlatformMacintosh)) {
- // Sound is currently not supported at all in the amiga versions of these games
- if (_vm->_game.platform == Common::kPlatformAmiga) {
- int track = -1;
- if (soundID == 50)
- track = 17;
- else if (ptr[6] == 0x7F && ptr[7] == 0x00 && ptr[8] == 0x80) {
- static const char tracks[16] = {13,14,10,3,4,9,16,5,1,8,2,15,6,7,11,12};
- if (ptr[9] == 0x0E)
- track = 18;
- else
- track = tracks[ptr[9] - 0x23];
- }
- if (track != -1) {
- playCDTrack(track,((track < 5) || (track > 16)) ? 1 : -1,0,0);
- stopCDTimer();
- _currentCDSound = soundID;
- }
- return;
- }
-
// Works around the fact that in some places in MonkeyEGA/VGA,
// the music is never explicitly stopped.
// Rather it seems that starting a new music is supposed to
Property changes on: scummvm/trunk/graphics/video/coktelvideo/coktelvideo.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/coktelvideo/coktelvideo.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/coktelvideo/indeo3.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/coktelvideo/indeo3.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/dxa_decoder.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/dxa_decoder.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/flic_decoder.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/flic_decoder.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/smk_decoder.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/graphics/video/smk_decoder.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/gui/GuiManager.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/gui/GuiManager.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/sound/iff_sound.cpp
___________________________________________________________________
Deleted: svn:mergeinfo
-
Property changes on: scummvm/trunk/sound/iff_sound.h
___________________________________________________________________
Deleted: svn:mergeinfo
-
Copied: scummvm/trunk/sound/mods/maxtrax.cpp (from rev 43702, scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.cpp)
===================================================================
--- scummvm/trunk/sound/mods/maxtrax.cpp (rev 0)
+++ scummvm/trunk/sound/mods/maxtrax.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -0,0 +1,1038 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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/scummsys.h"
+#include "common/endian.h"
+#include "common/stream.h"
+#include "common/util.h"
+#include "common/debug.h"
+
+#include "sound/mods/maxtrax.h"
+
+// test for engines using this class.
+#if defined(SOUND_MODS_MAXTRAX_H)
+
+namespace {
+
+enum { K_VALUE = 0x9fd77, PREF_PERIOD = 0x8fd77, PERIOD_LIMIT = 0x6f73d };
+enum { NO_BEND = 64 << 7, MAX_BEND_RANGE = 24 };
+
+int32 precalcNote(byte baseNote, int16 tune, byte octave) {
+ return K_VALUE + 0x3C000 - ((baseNote << 14) + (tune << 11) / 3) / 3 - (octave << 16);
+}
+
+int32 calcVolumeDelta(int32 delta, uint16 time, uint16 vBlankFreq) {
+ const int32 div = time * vBlankFreq;
+ // div <= 1000 means time to small (or even 0)
+ return (div <= 1000) ? delta : (1000 * delta) / div;
+}
+
+int32 calcTempo(const uint16 tempo, uint16 vBlankFreq) {
+ return (int32)(((uint32)(tempo & 0xFFF0) << 8) / (uint16)(5 * vBlankFreq));
+}
+
+void nullFunc(int) {}
+
+// Function to calculate 2^x, where x is a fixedpoint number with 16 fraction bits
+// using exp would be more accurate and needs less space if mathlibrary is already linked
+// but this function should be faster and doesnt use floats
+#if 1
+inline uint32 pow2Fixed(int32 val) {
+ static const uint16 tablePow2[] = {
+ 0, 178, 356, 535, 714, 893, 1073, 1254, 1435, 1617, 1799, 1981, 2164, 2348, 2532, 2716,
+ 2902, 3087, 3273, 3460, 3647, 3834, 4022, 4211, 4400, 4590, 4780, 4971, 5162, 5353, 5546, 5738,
+ 5932, 6125, 6320, 6514, 6710, 6906, 7102, 7299, 7496, 7694, 7893, 8092, 8292, 8492, 8693, 8894,
+ 9096, 9298, 9501, 9704, 9908, 10113, 10318, 10524, 10730, 10937, 11144, 11352, 11560, 11769, 11979, 12189,
+ 12400, 12611, 12823, 13036, 13249, 13462, 13676, 13891, 14106, 14322, 14539, 14756, 14974, 15192, 15411, 15630,
+ 15850, 16071, 16292, 16514, 16737, 16960, 17183, 17408, 17633, 17858, 18084, 18311, 18538, 18766, 18995, 19224,
+ 19454, 19684, 19915, 20147, 20379, 20612, 20846, 21080, 21315, 21550, 21786, 22023, 22260, 22498, 22737, 22977,
+ 23216, 23457, 23698, 23940, 24183, 24426, 24670, 24915, 25160, 25406, 25652, 25900, 26148, 26396, 26645, 26895,
+ 27146, 27397, 27649, 27902, 28155, 28409, 28664, 28919, 29175, 29432, 29690, 29948, 30207, 30466, 30727, 30988,
+ 31249, 31512, 31775, 32039, 32303, 32568, 32834, 33101, 33369, 33637, 33906, 34175, 34446, 34717, 34988, 35261,
+ 35534, 35808, 36083, 36359, 36635, 36912, 37190, 37468, 37747, 38028, 38308, 38590, 38872, 39155, 39439, 39724,
+ 40009, 40295, 40582, 40870, 41158, 41448, 41738, 42029, 42320, 42613, 42906, 43200, 43495, 43790, 44087, 44384,
+ 44682, 44981, 45280, 45581, 45882, 46184, 46487, 46791, 47095, 47401, 47707, 48014, 48322, 48631, 48940, 49251,
+ 49562, 49874, 50187, 50500, 50815, 51131, 51447, 51764, 52082, 52401, 52721, 53041, 53363, 53685, 54008, 54333,
+ 54658, 54983, 55310, 55638, 55966, 56296, 56626, 56957, 57289, 57622, 57956, 58291, 58627, 58964, 59301, 59640,
+ 59979, 60319, 60661, 61003, 61346, 61690, 62035, 62381, 62727, 63075, 63424, 63774, 64124, 64476, 64828, 65182,
+ 0
+ };
+ const uint16 whole = val >> 16;
+ const uint8 index = (uint8)(val >> 8);
+ // calculate fractional part.
+ const uint16 base = tablePow2[index];
+ // linear interpolation and add 1.0
+ uint32 exponent = ((uint32)(uint16)(tablePow2[index + 1] - base) * (uint8)val) + ((uint32)base << 8) + (1 << 24);
+
+ if (whole < 24) {
+ // shift away all but the last fractional bit which is used for rounding,
+ // then round to nearest integer
+ exponent = ((exponent >> (23 - whole)) + 1) >> 1;
+ } else if (whole < 32) {
+ // no need to round here
+ exponent <<= whole - 24;
+ } else if (val > 0) {
+ // overflow
+ exponent = 0xFFFFFFFF;
+ } else {
+ // negative integer, test if >= -0.5
+ exponent = (val >= -0x8000) ? 1 : 0;
+ }
+ return exponent;
+}
+#else
+inline uint32 pow2Fixed(int32 val) {
+ return (uint32)(expf((float)val * (float)(0.69314718055994530942 / (1 << 16))) + 0.5f);
+}
+#endif
+
+} // End of namespace
+
+namespace Audio {
+
+MaxTrax::MaxTrax(int rate, bool stereo, uint16 vBlankFreq, uint16 maxScores)
+ : Paula(stereo, rate, rate / vBlankFreq),
+ _patch(),
+ _scores(),
+ _numScores() {
+ _playerCtx.maxScoreNum = maxScores;
+ _playerCtx.vBlankFreq = vBlankFreq;
+ _playerCtx.frameUnit = (uint16)((1000 << 8) / vBlankFreq);
+ _playerCtx.scoreIndex = -1;
+ _playerCtx.volume = 0x40;
+
+ _playerCtx.tempo = 120;
+ _playerCtx.tempoTime = 0;
+ _playerCtx.filterOn = true;
+ _playerCtx.syncCallBack = &nullFunc;
+
+ resetPlayer();
+ for (int i = 0; i < ARRAYSIZE(_channelCtx); ++i)
+ _channelCtx[i].regParamNumber = 0;
+}
+
+MaxTrax::~MaxTrax() {
+ stopMusic();
+ freePatches();
+ freeScores();
+}
+
+void MaxTrax::interrupt() {
+ // a5 - maxtraxm a4 . globaldata
+
+ // TODO
+ // test for changes in shared struct and make changes
+ // specifically all used channels get marked altered
+
+ _playerCtx.ticks += _playerCtx.tickUnit;
+ const int32 millis = _playerCtx.ticks >> 8; // d4
+
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
+ VoiceContext &voice = _voiceCtx[i];
+ if (voice.stopEventTime >= 0) {
+ assert(voice.channel);
+ voice.stopEventTime -= (voice.channel < &_channelCtx[kNumChannels]) ? _playerCtx.tickUnit : _playerCtx.frameUnit;
+ if (voice.stopEventTime <= 0 && voice.status > VoiceContext::kStatusRelease) {
+ if ((voice.channel->flags & ChannelContext::kFlagDamper) != 0)
+ voice.hasDamper = true;
+ else
+ voice.status = VoiceContext::kStatusRelease;
+ }
+ }
+ }
+
+ if (_playerCtx.scoreIndex >= 0) {
+ const Event *curEvent = _playerCtx.nextEvent;
+ int32 eventDelta = _playerCtx.nextEventTime - millis;
+ for (; eventDelta <= 0; eventDelta += (++curEvent)->startTime) {
+ const byte cmd = curEvent->command;
+ ChannelContext &channel = _channelCtx[curEvent->parameter & 0x0F];
+
+ // outPutEvent(*curEvent);
+ // debug("CurTime, EventDelta, NextDelta: %d, %d, %d", millis, eventDelta, eventDelta + curEvent[1].startTime );
+
+ if (cmd < 0x80) { // Note
+ const int8 voiceIndex = noteOn(channel, cmd, (curEvent->parameter & 0xF0) >> 1, kPriorityScore);
+ if (voiceIndex >= 0)
+ _voiceCtx[voiceIndex].stopEventTime = MAX(0, (eventDelta + curEvent->stopTime) << 8);
+
+ } else {
+ switch (cmd) {
+
+ case 0x80: // TEMPO
+ if ((_playerCtx.tickUnit >> 8) > curEvent->stopTime) {
+ _playerCtx.tickUnit = calcTempo(curEvent->parameter << 4, _playerCtx.vBlankFreq);
+ _playerCtx.tempoTime = 0;
+ } else {
+ _playerCtx.tempoStart = _playerCtx.tempo;
+ _playerCtx.tempoDelta = (curEvent->parameter << 4) - _playerCtx.tempoStart;
+ _playerCtx.tempoTime = (curEvent->stopTime << 8);
+ _playerCtx.tempoTicks = 0;
+ }
+ break;
+
+ case 0xC0: // PROGRAM
+ channel.patch = &_patch[curEvent->stopTime & (kNumPatches - 1)];
+ break;
+
+ case 0xE0: // BEND
+ channel.pitchBend = ((curEvent->stopTime & 0x7F00) >> 1) | (curEvent->stopTime & 0x7f);
+ channel.pitchReal = (((int32)channel.pitchBendRange * channel.pitchBend) >> 5) - (channel.pitchBendRange << 8);
+ channel.isAltered = true;
+ break;
+
+ case 0xFF: // END
+ if (_playerCtx.musicLoop) {
+ curEvent = _scores[_playerCtx.scoreIndex].events;
+ eventDelta = curEvent->startTime - millis;
+ _playerCtx.ticks = 0;
+ } else
+ _playerCtx.scoreIndex = -1;
+ // stop processing for this tick
+ goto endOfEventLoop;
+
+ case 0xA0: // SPECIAL
+ switch (curEvent->stopTime >> 8){
+ case 0x01: // SPECIAL_SYNC
+ _playerCtx.syncCallBack(curEvent->stopTime & 0xFF);
+ break;
+ case 0x02: // SPECIAL_BEGINREP
+ // we allow a depth of 4 loops
+ for (int i = 0; i < ARRAYSIZE(_playerCtx.repeatPoint); ++i) {
+ if (!_playerCtx.repeatPoint[i]) {
+ _playerCtx.repeatPoint[i] = curEvent;
+ _playerCtx.repeatCount[i] = curEvent->stopTime & 0xFF;
+ break;
+ }
+ }
+ break;
+ case 0x03: // SPECIAL_ENDREP
+ for (int i = ARRAYSIZE(_playerCtx.repeatPoint) - 1; i >= 0; --i) {
+ if (_playerCtx.repeatPoint[i]) {
+ if (_playerCtx.repeatCount[i]--)
+ curEvent = _playerCtx.repeatPoint[i]; // gets incremented by 1 at end of loop
+ else
+ _playerCtx.repeatPoint[i] = 0;
+ break;
+ }
+ }
+ break;
+ }
+ break;
+
+ case 0xB0: // CONTROL
+ controlCh(channel, (byte)(curEvent->stopTime >> 8), (byte)curEvent->stopTime);
+ break;
+
+ default:
+ debug("Unhandled Command");
+ outPutEvent(*curEvent);
+ }
+ }
+ }
+endOfEventLoop:
+ _playerCtx.nextEvent = curEvent;
+ _playerCtx.nextEventTime = eventDelta + millis;
+
+ // tempoEffect
+ if (_playerCtx.tempoTime) {
+ _playerCtx.tempoTicks += _playerCtx.tickUnit;
+ uint16 newTempo = _playerCtx.tempoStart;
+ if (_playerCtx.tempoTicks < _playerCtx.tempoTime) {
+ newTempo += (uint16)((_playerCtx.tempoTicks * _playerCtx.tempoDelta) / _playerCtx.tempoTime);
+ } else {
+ _playerCtx.tempoTime = 0;
+ newTempo += _playerCtx.tempoDelta;
+ }
+ _playerCtx.tickUnit = calcTempo(newTempo, _playerCtx.vBlankFreq);
+ }
+ }
+
+ // Handling of Envelopes and Portamento
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
+ VoiceContext &voice = _voiceCtx[i];
+ if (!voice.channel)
+ continue;
+ const ChannelContext &channel = *voice.channel;
+ const Patch &patch = *voice.patch;
+
+ switch (voice.status) {
+ case VoiceContext::kStatusSustain:
+ // we need to check if some voices have no sustainSample.
+ // in that case they are finished after the attackSample is done
+ if (voice.dmaOff && Paula::getChannelDmaCount((byte)i) >= voice.dmaOff ) {
+ voice.dmaOff = 0;
+ voice.isBlocked = 0;
+ voice.priority = 0;
+ // disable it in next tick
+ voice.stopEventTime = 0;
+ }
+ if (!channel.isAltered && !voice.hasPortamento && !channel.modulation)
+ continue;
+ // Update Volume and Period
+ break;
+
+ case VoiceContext::kStatusHalt:
+ killVoice((byte)i);
+ continue;
+
+ case VoiceContext::kStatusStart:
+ if (patch.attackLen) {
+ voice.envelope = patch.attackPtr;
+ const uint16 duration = voice.envelope->duration;
+ voice.envelopeLeft = patch.attackLen;
+ voice.ticksLeft = duration << 8;
+ voice.status = VoiceContext::kStatusAttack;
+ voice.incrVolume = calcVolumeDelta((int32)voice.envelope->volume, duration, _playerCtx.vBlankFreq);
+ // Process Envelope
+ } else {
+ voice.status = VoiceContext::kStatusSustain;
+ voice.baseVolume = patch.volume;
+ // Update Volume and Period
+ }
+ break;
+
+ case VoiceContext::kStatusRelease:
+ if (patch.releaseLen) {
+ voice.envelope = patch.attackPtr + patch.attackLen;
+ const uint16 duration = voice.envelope->duration;
+ voice.envelopeLeft = patch.releaseLen;
+ voice.ticksLeft = duration << 8;
+ voice.status = VoiceContext::kStatusDecay;
+ voice.incrVolume = calcVolumeDelta((int32)voice.envelope->volume - voice.baseVolume, duration, _playerCtx.vBlankFreq);
+ // Process Envelope
+ } else {
+ voice.status = VoiceContext::kStatusHalt;
+ voice.lastVolume = 0;
+ // Send Audio Packet
+ }
+ voice.stopEventTime = -1;
+ break;
+ }
+
+ // Process Envelope
+ const uint16 envUnit = _playerCtx.frameUnit;
+ if (voice.envelope) {
+ if (voice.ticksLeft > envUnit) { // envelope still active
+ voice.baseVolume = (uint16)MIN(MAX(0, voice.baseVolume + voice.incrVolume), 0x8000);
+ voice.ticksLeft -= envUnit;
+ // Update Volume and Period
+
+ } else { // next or last Envelope
+ voice.baseVolume = voice.envelope->volume;
+ assert(voice.envelopeLeft > 0);
+ if (--voice.envelopeLeft) {
+ ++voice.envelope;
+ const uint16 duration = voice.envelope->duration;
+ voice.ticksLeft = duration << 8;
+ voice.incrVolume = calcVolumeDelta((int32)voice.envelope->volume - voice.baseVolume, duration, _playerCtx.vBlankFreq);
+ // Update Volume and Period
+ } else if (voice.status == VoiceContext::kStatusDecay) {
+ voice.status = VoiceContext::kStatusHalt;
+ voice.envelope = 0;
+ voice.lastVolume = 0;
+ // Send Audio Packet
+ } else {
+ assert(voice.status == VoiceContext::kStatusAttack);
+ voice.status = VoiceContext::kStatusSustain;
+ voice.envelope = 0;
+ // Update Volume and Period
+ }
+ }
+ }
+
+ // Update Volume and Period
+ if (voice.status >= VoiceContext::kStatusDecay) {
+ // Calc volume
+ uint16 vol = (voice.noteVolume < (1 << 7)) ? (voice.noteVolume * _playerCtx.volume) >> 7 : _playerCtx.volume;
+ if (voice.baseVolume < (1 << 15))
+ vol = (uint16)(((uint32)vol * voice.baseVolume) >> 15);
+ if (voice.channel->volume < (1 << 7))
+ vol = (vol * voice.channel->volume) >> 7;
+ voice.lastVolume = (byte)MIN(vol, (uint16)0x64);
+
+ // Calc Period
+ if (voice.hasPortamento) {
+ voice.portaTicks += envUnit;
+ if ((uint16)(voice.portaTicks >> 8) >= channel.portamentoTime) {
+ voice.hasPortamento = false;
+ voice.baseNote = voice.endNote;
+ voice.preCalcNote = precalcNote(voice.baseNote, patch.tune, voice.octave);
+ }
+ voice.lastPeriod = calcNote(voice);
+ } else if (channel.isAltered || channel.modulation)
+ voice.lastPeriod = calcNote(voice);
+ }
+
+ // Send Audio Packet
+ Paula::setChannelPeriod((byte)i, (voice.lastPeriod) ? voice.lastPeriod : 1000);
+ Paula::setChannelVolume((byte)i, (voice.lastPeriod) ? voice.lastVolume : 0);
+ }
+ for (ChannelContext *c = _channelCtx; c != &_channelCtx[ARRAYSIZE(_channelCtx)]; ++c)
+ c->isAltered = false;
+
+#ifdef MAXTRAX_HAS_MODULATION
+ // original player had _playerCtx.sineValue = _playerCtx.frameUnit >> 2
+ // this should fit the comments that modtime=1000 is one second ?
+ _playerCtx.sineValue += _playerCtx.frameUnit;
+#endif
+}
+
+void MaxTrax::controlCh(ChannelContext &channel, const byte command, const byte data) {
+ switch (command) {
+ case 0x01: // modulation level MSB
+ channel.modulation = data << 8;
+ break;
+ case 0x21: // modulation level LSB
+ channel.modulation = (channel.modulation & 0xFF00) || ((data * 2) & 0xFF);
+ break;
+ case 0x05: // portamento time MSB
+ channel.portamentoTime = data << 7;
+ break;
+ case 0x25: // portamento time LSB
+ channel.portamentoTime = (channel.portamentoTime & 0x3f80) || data;
+ break;
+ case 0x06: // data entry MSB
+ if (channel.regParamNumber == 0) {
+ channel.pitchBendRange = (int8)MIN((uint8)MAX_BEND_RANGE, (uint8)data);
+ channel.pitchReal = (((int32)channel.pitchBendRange * channel.pitchBend) >> 5) - (channel.pitchBendRange << 8);
+ channel.isAltered = true;
+ }
+ break;
+ case 0x07: // Main Volume MSB
+ channel.volume = (data == 0) ? 0 : data + 1;
+ channel.isAltered = true;
+ break;
+ case 0x0A: // Pan
+ if (data > 0x40 || (data == 0x40 && ((&channel - _channelCtx) & 1) != 0))
+ channel.flags |= ChannelContext::kFlagRightChannel;
+ else
+ channel.flags &= ~ChannelContext::kFlagRightChannel;
+ break;
+ case 0x10: // GPC as Modulation Time MSB
+ channel.modulationTime = data << 7;
+ break;
+ case 0x30: // GPC as Modulation Time LSB
+ channel.modulationTime = (channel.modulationTime & 0x3f80) || data;
+ break;
+ case 0x11: // GPC as Microtonal Set MSB
+ channel.microtonal = data << 8;
+ break;
+ case 0x31: // GPC as Microtonal Set LSB
+ channel.microtonal = (channel.microtonal & 0xFF00) || ((data * 2) & 0xFF);
+ break;
+ case 0x40: // Damper Pedal
+ if ((data & 0x40) != 0)
+ channel.flags |= ChannelContext::kFlagDamper;
+ else {
+ channel.flags &= ~ChannelContext::kFlagDamper;
+ // release all dampered voices on this channel
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
+ if (_voiceCtx[i].channel == &channel && _voiceCtx[i].hasDamper) {
+ _voiceCtx[i].hasDamper = false;
+ _voiceCtx[i].status = VoiceContext::kStatusRelease;
+ }
+ }
+ }
+ break;
+ case 0x41: // Portamento off/on
+ if ((data & 0x40) != 0)
+ channel.flags |= ChannelContext::kFlagPortamento;
+ else
+ channel.flags &= ~ChannelContext::kFlagPortamento;
+ break;
+ case 0x50: // Microtonal off/on
+ if ((data & 0x40) != 0)
+ channel.flags |= ChannelContext::kFlagMicrotonal;
+ else
+ channel.flags &= ~ChannelContext::kFlagMicrotonal;
+ break;
+ case 0x51: // Audio Filter off/on
+ Paula::setAudioFilter(data > 0x40 || (data == 0x40 && _playerCtx.filterOn));
+ break;
+ case 0x65: // RPN MSB
+ channel.regParamNumber = (data << 8) || (channel.regParamNumber & 0xFF);
+ break;
+ case 0x64: // RPN LSB
+ channel.regParamNumber = (channel.regParamNumber & 0xFF00) || data;
+ break;
+ case 0x79: // Reset All Controllers
+ resetChannel(channel, ((&channel - _channelCtx) & 1) != 0);
+ break;
+ case 0x7E: // MONO mode
+ channel.flags |= ChannelContext::kFlagMono;
+ goto allNotesOff;
+ case 0x7F: // POLY mode
+ channel.flags &= ~ChannelContext::kFlagMono;
+ // Fallthrough
+ case 0x7B: // All Notes Off
+allNotesOff:
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
+ if (_voiceCtx[i].channel == &channel) {
+ if ((channel.flags & ChannelContext::kFlagDamper) != 0)
+ _voiceCtx[i].hasDamper = true;
+ else
+ _voiceCtx[i].status = VoiceContext::kStatusRelease;
+ }
+ }
+ break;
+ case 0x78: // All Sounds Off
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
+ if (_voiceCtx[i].channel == &channel)
+ killVoice((byte)i);
+ }
+ break;
+ }
+}
+
+void MaxTrax::setTempo(const uint16 tempo) {
+ Common::StackLock lock(_mutex);
+ _playerCtx.tickUnit = calcTempo(tempo, _playerCtx.vBlankFreq);
+}
+
+void MaxTrax::resetPlayer() {
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i)
+ killVoice((byte)i);
+
+ for (int i = 0; i < ARRAYSIZE(_channelCtx); ++i) {
+ _channelCtx[i].flags = 0;
+ _channelCtx[i].lastNote = (uint8)-1;
+ resetChannel(_channelCtx[i], (i & 1) != 0);
+ _channelCtx[i].patch = (i < kNumChannels) ? &_patch[i] : 0;
+ }
+
+#ifdef MAXTRAX_HAS_MICROTONAL
+ for (int i = 0; i < ARRAYSIZE(_microtonal); ++i)
+ _microtonal[i] = (int16)(i << 8);
+#endif
+}
+
+void MaxTrax::stopMusic() {
+ Common::StackLock lock(_mutex);
+ _playerCtx.scoreIndex = -1;
+ for (int i = 0; i < ARRAYSIZE(_voiceCtx); ++i) {
+ if (_voiceCtx[i].channel < &_channelCtx[kNumChannels])
+ killVoice((byte)i);
+ }
+}
+
+bool MaxTrax::playSong(int songIndex, bool loop) {
+ if (songIndex < 0 || songIndex >= _numScores)
+ return false;
+ Common::StackLock lock(_mutex);
+ _playerCtx.scoreIndex = -1;
+ resetPlayer();
+ for (int i = 0; i < ARRAYSIZE(_playerCtx.repeatPoint); ++i)
+ _playerCtx.repeatPoint[i] = 0;
+
+ setTempo(_playerCtx.tempoInitial << 4);
+ Paula::setAudioFilter(_playerCtx.filterOn);
+ _playerCtx.musicLoop = loop;
+ _playerCtx.tempoTime = 0;
+ _playerCtx.scoreIndex = songIndex;
+ _playerCtx.ticks = 0;
+
+ _playerCtx.nextEvent = _scores[songIndex].events;;
+ _playerCtx.nextEventTime = _playerCtx.nextEvent->startTime;
+
+ Paula::startPaula();
+ return true;
+}
+
+void MaxTrax::advanceSong(int advance) {
+ Common::StackLock lock(_mutex);
+ if (_playerCtx.scoreIndex >= 0) {
+ const Event *cev = _playerCtx.nextEvent;
+ if (cev) {
+ for (; advance > 0; --advance) {
+ // TODO - check for boundaries
+ for (; cev->command != 0xFF && (cev->command != 0xA0 || (cev->stopTime >> 8) != 0x00); ++cev)
+ ; // no end_command or special_command + end
+ }
+ _playerCtx.nextEvent = cev;
+ }
+ }
+}
+
+void MaxTrax::killVoice(byte num) {
+ VoiceContext &voice = _voiceCtx[num];
+ voice.channel = 0;
+ voice.envelope = 0;
+ voice.status = VoiceContext::kStatusFree;
+ voice.isBlocked = 0;
+ voice.hasDamper = false;
+ voice.hasPortamento = false;
+ voice.priority = 0;
+ voice.stopEventTime = -1;
+ voice.dmaOff = 0;
+ voice.lastVolume = 0;
+ voice.tieBreak = 0;
+ //voice.uinqueId = 0;
+
+ // "stop" voice, set period to 1, vol to 0
+ Paula::disableChannel(num);
+ Paula::setChannelPeriod(num, 1);
+ Paula::setChannelVolume(num, 0);
+}
+
+int8 MaxTrax::pickvoice(uint pick, int16 pri) {
+ enum { kPrioFlagFixedSide = 1 << 3 };
+ pick &= 3;
+ if ((pri & (kPrioFlagFixedSide)) == 0) {
+ const bool leftSide = (uint)(pick - 1) > 1;
+ const int leftBest = MIN(_voiceCtx[0].status, _voiceCtx[3].status);
+ const int rightBest = MIN(_voiceCtx[1].status, _voiceCtx[2].status);
+ const int sameSide = (leftSide) ? leftBest : rightBest;
+ const int otherSide = leftBest + rightBest - sameSide;
+
+ if (sameSide > VoiceContext::kStatusRelease && otherSide <= VoiceContext::kStatusRelease)
+ pick ^= 1; // switches sides
+ }
+ pri &= ~kPrioFlagFixedSide;
+
+ for (int i = 2; i > 0; --i) {
+ VoiceContext *voice = &_voiceCtx[pick];
+ VoiceContext *alternate = &_voiceCtx[pick ^ 3];
+
+ const uint16 voiceVal = voice->status << 8 | voice->lastVolume;
+ const uint16 altVal = alternate->status << 8 | alternate->lastVolume;
+
+ if (voiceVal + voice->tieBreak > altVal
+ || voice->isBlocked > alternate->isBlocked) {
+
+ // this is somewhat different to the original player,
+ // but has a similar result
+ voice->tieBreak = 0;
+ alternate->tieBreak = 1;
+
+ pick ^= 3; // switch channels
+ VoiceContext *tmp = voice;
+ voice = alternate;
+ alternate = tmp;
+ }
+
+ if (voice->isBlocked || voice->priority > pri) {
+ // if not already done, switch sides and try again
+ pick ^= 1;
+ continue;
+ }
+ // succeded
+ return (int8)pick;
+ }
+ // failed
+ debug(5, "MaxTrax: could not find channel for note");
+ return -1;
+}
+
+uint16 MaxTrax::calcNote(const VoiceContext &voice) {
+ const ChannelContext &channel = *voice.channel;
+ int16 bend = channel.pitchReal;
+
+#ifdef MAXTRAX_HAS_MICROTONAL
+ if (voice.hasPortamento) {
+ if ((channel.flags & ChannelContext::kFlagMicrotonal) != 0)
+ bend += (int16)(((_microtonal[voice.endNote] - _microtonal[voice.baseNote]) * voice.portaTicks) >> 8) / channel.portamentoTime;
+ else
+ bend += (int16)(((int8)(voice.endNote - voice.baseNote)) * voice.portaTicks) / channel.portamentoTime;
+ }
+
+ if ((channel.flags & ChannelContext::kFlagMicrotonal) != 0)
+ bend += _microtonal[voice.baseNote];
+#else
+ if (voice.hasPortamento)
+ bend += (int16)(((int8)(voice.endNote - voice.baseNote)) * voice.portaTicks) / channel.portamentoTime;
+#endif
+
+#ifdef MAXTRAX_HAS_MODULATION
+ static const uint8 tableSine[] = {
+ 0, 5, 12, 18, 24, 30, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91,
+ 97, 103, 108, 114, 120, 125, 131, 136, 141, 146, 151, 156, 161, 166, 171, 176,
+ 180, 184, 189, 193, 197, 201, 205, 208, 212, 215, 219, 222, 225, 228, 230, 233,
+ 236, 238, 240, 242, 244, 246, 247, 249, 250, 251, 252, 253, 254, 254, 255, 255,
+ 255, 255, 255, 254, 254, 253, 252, 251, 250, 249, 247, 246, 244, 242, 240, 238,
+ 236, 233, 230, 228, 225, 222, 219, 215, 212, 208, 205, 201, 197, 193, 189, 184,
+ 180, 176, 171, 166, 161, 156, 151, 146, 141, 136, 131, 125, 120, 114, 108, 103,
+ 97, 91, 85, 79, 73, 67, 61, 55, 49, 43, 37, 30, 24, 18, 12, 5
+ };
+ if (channel.modulation) {
+ if ((channel.flags & ChannelContext::kFlagModVolume) == 0) {
+ const uint8 sineByte = _playerCtx.sineValue / channel.modulationTime;
+ const uint8 sineIndex = sineByte & 0x7F;
+ const int16 modVal = ((uint32)(uint16)(tableSine[sineIndex] + (sineIndex ? 1 : 0)) * channel.modulation) >> 8;
+ bend = (sineByte < 0x80) ? bend + modVal : bend - modVal;
+ }
+ }
+#endif
+
+ // tone = voice.baseNote << 8 + microtonal
+ // bend = channelPitch + porta + modulation
+
+ const int32 tone = voice.preCalcNote + (bend << 6) / 3;
+
+ return (tone >= PERIOD_LIMIT) ? (uint16)pow2Fixed(tone) : 0;
+}
+
+int8 MaxTrax::noteOn(ChannelContext &channel, const byte note, uint16 volume, uint16 pri) {
+#ifdef MAXTRAX_HAS_MICROTONAL
+ if (channel.microtonal >= 0)
+ _microtonal[note % 127] = channel.microtonal;
+#endif
+
+ if (!volume)
+ return -1;
+
+ const Patch &patch = *channel.patch;
+ if (!patch.samplePtr || patch.sampleTotalLen == 0)
+ return -1;
+ int8 voiceNum = -1;
+ if ((channel.flags & ChannelContext::kFlagMono) == 0) {
+ voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri);
+ } else {
+ VoiceContext *voice = _voiceCtx + ARRAYSIZE(_voiceCtx) - 1;
+ for (voiceNum = ARRAYSIZE(_voiceCtx) - 1; voiceNum >= 0 && voice->channel != &channel; --voiceNum, --voice)
+ ;
+ if (voiceNum < 0)
+ voiceNum = pickvoice((channel.flags & ChannelContext::kFlagRightChannel) != 0 ? 1 : 0, pri);
+ else if (voice->status >= VoiceContext::kStatusSustain && (channel.flags & ChannelContext::kFlagPortamento) != 0) {
+ // reset previous porta
+ if (voice->hasPortamento)
+ voice->baseNote = voice->endNote;
+ voice->preCalcNote = precalcNote(voice->baseNote, patch.tune, voice->octave);
+ voice->noteVolume = (_playerCtx.handleVolume) ? volume + 1 : 128;
+ voice->portaTicks = 0;
+ voice->hasPortamento = true;
+ voice->endNote = channel.lastNote = note;
+ return voiceNum;
+ }
+ }
+
+ if (voiceNum >= 0) {
+ VoiceContext &voice = _voiceCtx[voiceNum];
+ voice.hasDamper = false;
+ voice.isBlocked = 0;
+ voice.hasPortamento = false;
+ if (voice.channel)
+ killVoice(voiceNum);
+ voice.channel = &channel;
+ voice.patch = &patch;
+ voice.baseNote = note;
+
+ // always base octave on the note in the command, regardless of porta
+ const int32 plainNote = precalcNote(note, patch.tune, 0);
+ // calculate which sample to use
+ const int useOctave = (plainNote <= PREF_PERIOD) ? 0 : MIN<int32>((plainNote + 0xFFFF - PREF_PERIOD) >> 16, patch.sampleOctaves - 1);
+ voice.octave = (byte)useOctave;
+ // adjust precalculated value
+ voice.preCalcNote = plainNote - (useOctave << 16);
+
+ // next calculate the actual period which depends on wether porta is enabled
+ if (&channel < &_channelCtx[kNumChannels] && (channel.flags & ChannelContext::kFlagPortamento) != 0) {
+ if ((channel.flags & ChannelContext::kFlagMono) != 0 && channel.lastNote < 0x80 && channel.lastNote != note) {
+ voice.portaTicks = 0;
+ voice.baseNote = channel.lastNote;
+ voice.endNote = note;
+ voice.hasPortamento = true;
+ voice.preCalcNote = precalcNote(voice.baseNote, patch.tune, voice.octave);
+ }
+ channel.lastNote = note;
+ }
+
+ voice.lastPeriod = calcNote(voice);
+
+ voice.priority = (byte)pri;
+ voice.status = VoiceContext::kStatusStart;
+
+ voice.noteVolume = (_playerCtx.handleVolume) ? volume + 1 : 128;
+ voice.baseVolume = 0;
+
+ // TODO: since the original player is using the OS-functions, more than 1 sample could be queued up already
+ // get samplestart for the given octave
+ const int8 *samplePtr = patch.samplePtr + (patch.sampleTotalLen << useOctave) - patch.sampleTotalLen;
+ if (patch.sampleAttackLen) {
+ Paula::setChannelSampleStart(voiceNum, samplePtr);
+ Paula::setChannelSampleLen(voiceNum, (patch.sampleAttackLen << useOctave) / 2);
+
+ Paula::enableChannel(voiceNum);
+ // wait for dma-clear
+ }
+
+ if (patch.sampleTotalLen > patch.sampleAttackLen) {
+ Paula::setChannelSampleStart(voiceNum, samplePtr + (patch.sampleAttackLen << useOctave));
+ Paula::setChannelSampleLen(voiceNum, ((patch.sampleTotalLen - patch.sampleAttackLen) << useOctave) / 2);
+ if (!patch.sampleAttackLen)
+ Paula::enableChannel(voiceNum); // need to enable channel
+ // another pointless wait for DMA-Clear???
+
+ } else { // no sustain sample
+ // this means we must stop playback after the attacksample finished
+ // so we queue up an "empty" sample and note that we need to kill the sample after dma finished
+ Paula::setChannelSampleStart(voiceNum, 0);
+ Paula::setChannelSampleLen(voiceNum, 0);
+ Paula::setChannelDmaCount(voiceNum);
+ voice.dmaOff = 1;
+ }
+
+ Paula::setChannelPeriod(voiceNum, (voice.lastPeriod) ? voice.lastPeriod : 1000);
+ Paula::setChannelVolume(voiceNum, 0);
+ }
+ return voiceNum;
+}
+
+void MaxTrax::resetChannel(ChannelContext &chan, bool rightChannel) {
+ chan.modulation = 0;
+ chan.modulationTime = 1000;
+ chan.microtonal = -1;
+ chan.portamentoTime = 500;
+ chan.pitchBend = NO_BEND;
+ chan.pitchReal = 0;
+ chan.pitchBendRange = MAX_BEND_RANGE;
+ chan.volume = 128;
+ chan.flags &= ~(ChannelContext::kFlagPortamento | ChannelContext::kFlagMicrotonal | ChannelContext::kFlagRightChannel);
+ chan.isAltered = true;
+ if (rightChannel)
+ chan.flags |= ChannelContext::kFlagRightChannel;
+}
+
+void MaxTrax::freeScores() {
+ if (_scores) {
+ for (int i = 0; i < _numScores; ++i)
+ delete[] _scores[i].events;
+ delete[] _scores;
+ _scores = 0;
+ }
+ _numScores = 0;
+ _playerCtx.tempo = 120;
+ _playerCtx.filterOn = true;
+}
+
+void MaxTrax::freePatches() {
+ for (int i = 0; i < ARRAYSIZE(_patch); ++i) {
+ delete[] _patch[i].samplePtr;
+ delete[] _patch[i].attackPtr;
+ }
+ memset(_patch, 0, sizeof(_patch));
+}
+
+void MaxTrax::setSignalCallback(void (*callback) (int)) {
+ Common::StackLock lock(_mutex);
+ _playerCtx.syncCallBack = (callback == 0) ? nullFunc : callback;
+}
+
+int MaxTrax::playNote(byte note, byte patch, uint16 duration, uint16 volume, bool rightSide) {
+ Common::StackLock lock(_mutex);
+ assert(patch < ARRAYSIZE(_patch));
+
+ ChannelContext &channel = _channelCtx[kNumChannels];
+ channel.flags = (rightSide) ? ChannelContext::kFlagRightChannel : 0;
+ channel.isAltered = false;
+ channel.patch = &_patch[patch];
+ const int8 voiceIndex = noteOn(channel, note, (byte)volume, kPriorityNote);
+ if (voiceIndex >= 0)
+ _voiceCtx[voiceIndex].stopEventTime = duration << 8;
+ return voiceIndex;
+}
+
+bool MaxTrax::load(Common::SeekableReadStream &musicData, bool loadScores, bool loadSamples) {
+ Common::StackLock lock(_mutex);
+ stopMusic();
+ if (loadSamples)
+ freePatches();
+ if (loadScores)
+ freeScores();
+ const char *errorMsg = 0;
+ // 0x0000: 4 Bytes Header "MXTX"
+ // 0x0004: uint16 tempo
+ // 0x0006: uint16 flags. bit0 = lowpassfilter, bit1 = attackvolume, bit15 = microtonal
+ if (musicData.size() < 10 || musicData.readUint32BE() != 0x4D585458) {
+ warning("Maxtrax: File is not a Maxtrax Module");
+ return false;
+ }
+ const uint16 songTempo = musicData.readUint16BE();
+ const uint16 flags = musicData.readUint16BE();
+ if (loadScores) {
+ _playerCtx.tempoInitial = songTempo;
+ _playerCtx.filterOn = (flags & 1) != 0;
+ _playerCtx.handleVolume = (flags & 2) != 0;
+ }
+
+ if (flags & (1 << 15)) {
+ debug(5, "Maxtrax: Song has microtonal");
+#ifdef MAXTRAX_HAS_MICROTONAL
+ if (loadScores) {
+ for (int i = 0; i < ARRAYSIZE(_microtonal); ++i)
+ _microtonal[i] = musicData.readUint16BE();
+ } else
+ musicData.skip(128 * 2);
+#else
+ musicData.skip(128 * 2);
+#endif
+ }
+
+ int scoresLoaded = 0;
+ // uint16 number of Scores
+ const uint16 scoresInFile = musicData.readUint16BE();
+
+ if (musicData.err() || musicData.eos())
+ goto ioError;
+
+ if (loadScores) {
+ const uint16 tempScores = MIN(scoresInFile, _playerCtx.maxScoreNum);
+ Score *curScore = new Score[tempScores];
+ if (!curScore)
+ goto allocError;
+ _scores = curScore;
+
+ for (scoresLoaded = 0; scoresLoaded < tempScores; ++scoresLoaded, ++curScore) {
+ const uint32 numEvents = musicData.readUint32BE();
+ Event *curEvent = new Event[numEvents];
+ if (!curEvent)
+ goto allocError;
+ curScore->events = curEvent;
+ for (int j = numEvents; j > 0; --j, ++curEvent) {
+ curEvent->command = musicData.readByte();
+ curEvent->parameter = musicData.readByte();
+ curEvent->startTime = musicData.readUint16BE();
+ curEvent->stopTime = musicData.readUint16BE();
+ }
+ curScore->numEvents = numEvents;
+ }
+ _numScores = scoresLoaded;
+ }
+
+ if (loadSamples) {
+ // skip over remaining scores in file
+ for (int i = scoresInFile - scoresLoaded; i > 0; --i)
+ musicData.skip(musicData.readUint32BE() * 6);
+
+ // uint16 number of Samples
+ const uint16 wavesInFile = musicData.readUint16BE();
+ for (int i = wavesInFile; i > 0; --i) {
+ // load disksample structure
+ const uint16 number = musicData.readUint16BE();
+ assert(number < ARRAYSIZE(_patch));
+
+ Patch &curPatch = _patch[number];
+ if (curPatch.attackPtr || curPatch.samplePtr) {
+ delete curPatch.attackPtr;
+ curPatch.attackPtr = 0;
+ delete curPatch.samplePtr;
+ curPatch.samplePtr = 0;
+ }
+ curPatch.tune = musicData.readSint16BE();
+ curPatch.volume = musicData.readUint16BE();
+ curPatch.sampleOctaves = musicData.readUint16BE();
+ curPatch.sampleAttackLen = musicData.readUint32BE();
+ const uint32 sustainLen = musicData.readUint32BE();
+ curPatch.sampleTotalLen = curPatch.sampleAttackLen + sustainLen;
+ // each octave the number of samples doubles.
+ const uint32 totalSamples = curPatch.sampleTotalLen * ((1 << curPatch.sampleOctaves) - 1);
+ curPatch.attackLen = musicData.readUint16BE();
+ curPatch.releaseLen = musicData.readUint16BE();
+ const uint32 totalEnvs = curPatch.attackLen + curPatch.releaseLen;
+
+ // Allocate space for both attack and release Segment.
+ Envelope *envPtr = new Envelope[totalEnvs];
+ if (!envPtr)
+ goto allocError;
+ // Attack Segment
+ curPatch.attackPtr = envPtr;
+ // Release Segment
+ // curPatch.releasePtr = envPtr + curPatch.attackLen;
+
+ // Read Attack and Release Segments
+ for (int j = totalEnvs; j > 0; --j, ++envPtr) {
+ envPtr->duration = musicData.readUint16BE();
+ envPtr->volume = musicData.readUint16BE();
+ }
+
+ // read Samples
+ int8 *allocSamples = new int8[totalSamples];
+ if (!allocSamples)
+ goto allocError;
+ curPatch.samplePtr = allocSamples;
+ musicData.read(allocSamples, totalSamples);
+ }
+ }
+ if (!musicData.err() && !musicData.eos())
+ return true;
+ioError:
+ errorMsg = "Maxtrax: Encountered IO-Error";
+allocError:
+ if (!errorMsg)
+ errorMsg = "Maxtrax: Could not allocate Memory";
+
+ warning("%s", errorMsg);
+ if (loadSamples)
+ freePatches();
+ if (loadScores)
+ freeScores();
+ return false;
+}
+
+#if !defined(NDEBUG) && 0
+void MaxTrax::outPutEvent(const Event &ev, int num) {
+ struct {
+ byte cmd;
+ const char *name;
+ const char *param;
+ } COMMANDS[] = {
+ {0x80, "TEMPO ", "TEMPO, N/A "},
+ {0xa0, "SPECIAL ", "CHAN, SPEC # | VAL"},
+ {0xb0, "CONTROL ", "CHAN, CTRL # | VAL"},
+ {0xc0, "PROGRAM ", "CHANNEL, PROG # "},
+ {0xe0, "BEND ", "CHANNEL, BEND VALUE"},
+ {0xf0, "SYSEX ", "TYPE, SIZE "},
+ {0xf8, "REALTIME", "REALTIME, N/A "},
+ {0xff, "END ", "N/A, N/A "},
+ {0xff, "NOTE ", "VOL | CHAN, STOP"},
+ };
+
+ int i = 0;
+ for (; i < ARRAYSIZE(COMMANDS) - 1 && ev.command != COMMANDS[i].cmd; ++i)
+ ;
+
+ if (num == -1)
+ debug("Event : %02X %s %s %02X %04X %04X", ev.command, COMMANDS[i].name, COMMANDS[i].param, ev.parameter, ev.startTime, ev.stopTime);
+ else
+ debug("Event %3d: %02X %s %s %02X %04X %04X", num, ev.command, COMMANDS[i].name, COMMANDS[i].param, ev.parameter, ev.startTime, ev.stopTime);
+}
+
+void MaxTrax::outPutScore(const Score &sc, int num) {
+ if (num == -1)
+ debug("score : %i Events", sc.numEvents);
+ else
+ debug("score %2d: %i Events", num, sc.numEvents);
+ for (uint i = 0; i < sc.numEvents; ++i)
+ outPutEvent(sc.events[i], i);
+ debug("");
+}
+#else
+void MaxTrax::outPutEvent(const Event &ev, int num) {}
+void MaxTrax::outPutScore(const Score &sc, int num) {}
+#endif // #ifndef NDEBUG
+
+} // End of namespace Audio
+
+#endif // #if defined(SOUND_MODS_MAXTRAX_H)
Copied: scummvm/trunk/sound/mods/maxtrax.h (from rev 43702, scummvm/branches/gsoc2009-mods/sound/mods/maxtrax.h)
===================================================================
--- scummvm/trunk/sound/mods/maxtrax.h (rev 0)
+++ scummvm/trunk/sound/mods/maxtrax.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -0,0 +1,225 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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$
+ *
+ */
+
+// see if all engines using this class are DISABLED
+#if !defined(ENABLE_KYRA)
+
+// normal Header Guard
+#elif !defined SOUND_MODS_MAXTRAX_H
+#define SOUND_MODS_MAXTRAX_H
+
+// #define MAXTRAX_HAS_MODULATION
+// #define MAXTRAX_HAS_MICROTONAL
+
+#include "sound/mods/paula.h"
+
+namespace Audio {
+
+class MaxTrax : public Paula {
+public:
+ MaxTrax(int rate, bool stereo, uint16 vBlankFreq = 50, uint16 maxScores = 128);
+ virtual ~MaxTrax();
+
+ bool load(Common::SeekableReadStream &musicData, bool loadScores = true, bool loadSamples = true);
+ bool playSong(int songIndex, bool loop = false);
+ void advanceSong(int advance = 1);
+ int playNote(byte note, byte patch, uint16 duration, uint16 volume, bool rightSide);
+ void setVolume(const byte volume) { Common::StackLock lock(_mutex); _playerCtx.volume = volume; }
+ void setTempo(const uint16 tempo);
+ void stopMusic();
+ /**
+ * Set a callback function for sync-events.
+ * @param callback Callback function, will be called synchronously, so DONT modify the player
+ * directly in response
+ */
+ void setSignalCallback(void (*callback) (int));
+
+protected:
+ void interrupt();
+
+private:
+ enum { kNumPatches = 64, kNumVoices = 4, kNumChannels = 16, kNumExtraChannels = 1 };
+ enum { kPriorityScore, kPriorityNote, kPrioritySound };
+
+#ifdef MAXTRAX_HAS_MICROTONAL
+ int16 _microtonal[128];
+#endif
+
+ struct Event {
+ uint16 startTime;
+ uint16 stopTime;
+ byte command;
+ byte parameter;
+ };
+
+ const struct Score {
+ const Event *events;
+ uint32 numEvents;
+ } *_scores;
+
+ int _numScores;
+
+ struct {
+ uint32 sineValue;
+ uint16 vBlankFreq;
+ int32 ticks;
+ int32 tickUnit;
+ uint16 frameUnit;
+
+ uint16 maxScoreNum;
+ uint16 tempo;
+ uint16 tempoInitial;
+ uint16 tempoStart;
+ int16 tempoDelta;
+ int32 tempoTime;
+ int32 tempoTicks;
+
+ byte volume;
+
+ bool filterOn;
+ bool handleVolume;
+ bool musicLoop;
+
+ int scoreIndex;
+ const Event *nextEvent;
+ int32 nextEventTime;
+
+ void (*syncCallBack) (int);
+ const Event *repeatPoint[4];
+ byte repeatCount[4];
+ } _playerCtx;
+
+ struct Envelope {
+ uint16 duration;
+ uint16 volume;
+ };
+
+ struct Patch {
+ const Envelope *attackPtr;
+ //Envelope *releasePtr;
+ uint16 attackLen;
+ uint16 releaseLen;
+
+ int16 tune;
+ uint16 volume;
+
+ // this was the SampleData struct in the assembler source
+ const int8 *samplePtr;
+ uint32 sampleTotalLen;
+ uint32 sampleAttackLen;
+ uint16 sampleOctaves;
+ } _patch[kNumPatches];
+
+ struct ChannelContext {
+ const Patch *patch;
+ uint16 regParamNumber;
+
+ uint16 modulation;
+ uint16 modulationTime;
+
+ int16 microtonal;
+
+ uint16 portamentoTime;
+
+ int16 pitchBend;
+ int16 pitchReal;
+ int8 pitchBendRange;
+
+ uint8 volume;
+// uint8 voicesActive;
+
+ enum {
+ kFlagRightChannel = 1 << 0,
+ kFlagPortamento = 1 << 1,
+ kFlagDamper = 1 << 2,
+ kFlagMono = 1 << 3,
+ kFlagMicrotonal = 1 << 4,
+ kFlagModVolume = 1 << 5
+ };
+ byte flags;
+ bool isAltered;
+
+ uint8 lastNote;
+// uint8 program;
+
+ } _channelCtx[kNumChannels + kNumExtraChannels];
+
+ struct VoiceContext {
+ ChannelContext *channel;
+ const Patch *patch;
+ const Envelope *envelope;
+// uint32 uinqueId;
+ int32 preCalcNote;
+ uint32 ticksLeft;
+ int32 portaTicks;
+ int32 incrVolume;
+// int32 periodOffset;
+ uint16 envelopeLeft;
+ uint16 noteVolume;
+ uint16 baseVolume;
+ uint16 lastPeriod;
+ byte baseNote;
+ byte endNote;
+ byte octave;
+// byte number;
+// byte link;
+ enum {
+ kStatusFree,
+ kStatusHalt,
+ kStatusDecay,
+ kStatusRelease,
+ kStatusSustain,
+ kStatusAttack,
+ kStatusStart
+ };
+ uint8 isBlocked;
+ uint8 priority;
+ byte status;
+ byte lastVolume;
+ byte tieBreak;
+ bool hasDamper;
+ bool hasPortamento;
+ byte dmaOff;
+
+ int32 stopEventTime;
+ } _voiceCtx[kNumVoices];
+
+ void controlCh(ChannelContext &channel, byte command, byte data);
+ void freePatches();
+ void freeScores();
+ void resetChannel(ChannelContext &chan, bool rightChannel);
+ void resetPlayer();
+
+ int8 pickvoice(uint pick, int16 pri);
+ uint16 calcNote(const VoiceContext &voice);
+ int8 noteOn(ChannelContext &channel, byte note, uint16 volume, uint16 pri);
+ void killVoice(byte num);
+
+ static void outPutEvent(const Event &ev, int num = -1);
+ static void outPutScore(const Score &sc, int num = -1);
+};
+} // End of namespace Audio
+
+#endif // !defined SOUND_MODS_MAXTRAX_H
Modified: scummvm/trunk/sound/mods/paula.cpp
===================================================================
--- scummvm/trunk/sound/mods/paula.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/sound/mods/paula.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -27,19 +27,20 @@
namespace Audio {
-Paula::Paula(bool stereo, int rate, int interruptFreq) :
- _stereo(stereo), _rate(rate), _intFreq(interruptFreq) {
+Paula::Paula(bool stereo, int rate, uint interruptFreq) :
+ _stereo(stereo), _rate(rate), _periodScale((double)kPalPaulaClock / rate), _intFreq(interruptFreq) {
clearVoices();
- _voice[0].panning = 63;
- _voice[1].panning = 191;
- _voice[2].panning = 191;
- _voice[3].panning = 63;
+ _voice[0].panning = 191;
+ _voice[1].panning = 63;
+ _voice[2].panning = 63;
+ _voice[3].panning = 191;
- if (_intFreq <= 0)
+ if (_intFreq == 0)
_intFreq = _rate;
- _curInt = _intFreq;
+ _curInt = 0;
+ _timerBase = 1;
_playing = false;
_end = true;
}
@@ -57,6 +58,7 @@
_voice[voice].period = 0;
_voice[voice].volume = 0;
_voice[voice].offset = 0;
+ _voice[voice].dmaCount = 0;
}
int Paula::readBuffer(int16 *buffer, const int numSamples) {
@@ -95,18 +97,17 @@
// Handle 'interrupts'. This gives subclasses the chance to adjust the channel data
// (e.g. insert new samples, do pitch bending, whatever).
- if (_curInt == _intFreq) {
+ if (_curInt == 0) {
+ _curInt = _intFreq;
interrupt();
- _curInt = 0;
}
// Compute how many samples to generate: at most the requested number of samples,
// of course, but we may stop earlier when an 'interrupt' is expected.
- const int nSamples = MIN(samples, _intFreq - _curInt);
+ const uint nSamples = MIN((uint)samples, _curInt);
// Loop over the four channels of the emulated Paula chip
for (int voice = 0; voice < NUM_VOICES; voice++) {
-
// No data, or paused -> skip channel
if (!_voice[voice].data || (_voice[voice].period <= 0))
continue;
@@ -115,8 +116,7 @@
// the requested output sampling rate (typicall 44.1 kHz or 22.05 kHz)
// as well as the "period" of the channel we are processing right now,
// to compute the correct output 'rate'.
- const double frequency = (7093789.2 / 2.0) / _voice[voice].period;
- frac_t rate = doubleToFrac(frequency / _rate);
+ frac_t rate = doubleToFrac(_periodScale / _voice[voice].period);
// Cap the volume
_voice[voice].volume = MIN((byte) 0x40, _voice[voice].volume);
@@ -126,50 +126,67 @@
frac_t offset = _voice[voice].offset;
frac_t sLen = intToFrac(_voice[voice].length);
const int8 *data = _voice[voice].data;
+ int dmaCount = _voice[voice].dmaCount;
int16 *p = buffer;
int end = 0;
int neededSamples = nSamples;
+ assert(offset < sLen);
// Compute the number of samples to generate; that is, either generate
// just as many as were requested, or until the buffer is used up.
// Note that dividing two frac_t yields an integer (as the denominators
// cancel out each other).
// Note that 'end' could be 0 here. No harm in that :-).
- end = MIN(neededSamples, (int)((sLen - offset + rate - 1) / rate));
+ const int leftSamples = (int)((sLen - offset + rate - 1) / rate);
+ end = MIN(neededSamples, leftSamples);
mixBuffer<stereo>(p, data, offset, rate, end, _voice[voice].volume, _voice[voice].panning);
neededSamples -= end;
+ if (leftSamples > 0 && end == leftSamples) {
+ dmaCount++;
+ data = _voice[voice].data = _voice[voice].dataRepeat;
+ _voice[voice].length = _voice[voice].lengthRepeat;
+ // TODO: offset -= sLen; but make sure there is no way offset >= 2*sLen
+ offset &= FRAC_LO_MASK;
+ }
+
// If we have not yet generated enough samples, and looping is active: loop!
- if (neededSamples > 0 && _voice[voice].lengthRepeat > 2) {
-
- // At this point we know that we have used up all samples in the buffer, so reset it.
- _voice[voice].data = data = _voice[voice].dataRepeat;
- _voice[voice].length = _voice[voice].lengthRepeat;
+ if (neededSamples > 0 && _voice[voice].length > 2) {
sLen = intToFrac(_voice[voice].length);
// If the "rate" exceeds the sample rate, we would have to perform constant
// wrap arounds. So, apply the first step of the euclidean algorithm to
// achieve the same more efficiently: Take rate modulo sLen
+ // TODO: This messes up dmaCount and shouldnt happen?
if (sLen < rate)
- rate %= sLen;
+ warning("Paula: length %d is lesser than rate", _voice[voice].length);
+// rate %= sLen;
// Repeat as long as necessary.
while (neededSamples > 0) {
- offset = 0;
-
+ // TODO: offset -= sLen; but make sure there is no way offset >= 2*sLen
+ offset &= FRAC_LO_MASK;
+ dmaCount++;
// Compute the number of samples to generate (see above) and mix 'em.
end = MIN(neededSamples, (int)((sLen - offset + rate - 1) / rate));
mixBuffer<stereo>(p, data, offset, rate, end, _voice[voice].volume, _voice[voice].panning);
neededSamples -= end;
}
+
+ if (offset < sLen)
+ dmaCount--;
+ else
+ offset &= FRAC_LO_MASK;
+
}
// Write back the cached data
_voice[voice].offset = offset;
+ _voice[voice].dmaCount = dmaCount;
}
buffer += _stereo ? nSamples * 2 : nSamples;
- _curInt += nSamples;
+ _curInt -= nSamples;
samples -= nSamples;
}
return numSamples;
Modified: scummvm/trunk/sound/mods/paula.h
===================================================================
--- scummvm/trunk/sound/mods/paula.h 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/sound/mods/paula.h 2009-08-24 20:31:01 UTC (rev 43703)
@@ -40,12 +40,29 @@
class Paula : public AudioStream {
public:
static const int NUM_VOICES = 4;
+ enum {
+ kPalSystemClock = 7093790,
+ kNtscSystemClock = 7159090,
+ kPalCiaClock = kPalSystemClock / 10,
+ kNtscCiaClock = kNtscSystemClock / 10,
+ kPalPaulaClock = kPalSystemClock / 2,
+ kNtscPauleClock = kNtscSystemClock / 2
+ };
- Paula(bool stereo = false, int rate = 44100, int interruptFreq = 0);
+ Paula(bool stereo = false, int rate = 44100, uint interruptFreq = 0);
~Paula();
bool playing() const { return _playing; }
- void setInterruptFreq(int freq) { _curInt = _intFreq = freq; }
+ void setTimerBaseValue( uint32 ticksPerSecond ) { _timerBase = ticksPerSecond; }
+ uint32 getTimerBaseValue() { return _timerBase; }
+ void setSingleInterrupt(uint sampleDelay) { assert(sampleDelay < _intFreq); _curInt = sampleDelay; }
+ void setSingleInterruptUnscaled(uint timerDelay) {
+ setSingleInterrupt((uint)(((double)timerDelay * getRate()) / _timerBase));
+ }
+ void setInterruptFreq(uint sampleDelay) { _intFreq = sampleDelay; _curInt = 0; }
+ void setInterruptFreqUnscaled(uint timerDelay) {
+ setInterruptFreq((uint)(((double)timerDelay * getRate()) / _timerBase));
+ }
void clearVoice(byte voice);
void clearVoices() { for (int i = 0; i < NUM_VOICES; ++i) clearVoice(i); }
void startPlay(void) { _playing = true; }
@@ -68,6 +85,7 @@
byte volume;
frac_t offset;
byte panning; // For stereo mixing: 0 = far left, 255 = far right
+ int dmaCount;
};
bool _end;
@@ -90,6 +108,21 @@
_voice[channel].panning = panning;
}
+ void disableChannel(byte channel) {
+ assert(channel < NUM_VOICES);
+ _voice[channel].data = 0;
+ }
+
+ void enableChannel(byte channel) {
+ assert(channel < NUM_VOICES);
+ Channel &ch = _voice[channel];
+ ch.data = ch.dataRepeat;
+ ch.length = ch.lengthRepeat;
+ // actually first 2 bytes are dropped?
+ ch.offset = intToFrac(0);
+ // ch.period = ch.periodRepeat;
+ }
+
void setChannelPeriod(byte channel, int16 period) {
assert(channel < NUM_VOICES);
_voice[channel].period = period;
@@ -100,6 +133,17 @@
_voice[channel].volume = volume;
}
+ void setChannelSampleStart(byte channel, const int8 *data) {
+ assert(channel < NUM_VOICES);
+ _voice[channel].dataRepeat = data;
+ }
+
+ void setChannelSampleLen(byte channel, uint32 length) {
+ assert(channel < NUM_VOICES);
+ assert(length < 32768/2);
+ _voice[channel].lengthRepeat = 2 * length;
+ }
+
void setChannelData(uint8 channel, const int8 *data, const int8 *dataRepeat, uint32 length, uint32 lengthRepeat, int32 offset = 0) {
assert(channel < NUM_VOICES);
@@ -110,11 +154,14 @@
assert(lengthRepeat < 32768);
Channel &ch = _voice[channel];
- ch.data = data;
+
+ ch.dataRepeat = data;
+ ch.lengthRepeat = length;
+ enableChannel(channel);
+ ch.offset = intToFrac(offset);
+
ch.dataRepeat = dataRepeat;
- ch.length = length;
ch.lengthRepeat = lengthRepeat;
- ch.offset = intToFrac(offset);
}
void setChannelOffset(byte channel, frac_t offset) {
@@ -128,13 +175,29 @@
return _voice[channel].offset;
}
+ int getChannelDmaCount(byte channel) {
+ assert(channel < NUM_VOICES);
+ return _voice[channel].dmaCount;
+ }
+
+ void setChannelDmaCount(byte channel, int dmaVal = 0) {
+ assert(channel < NUM_VOICES);
+ _voice[channel].dmaCount = dmaVal;
+ }
+
+ void setAudioFilter(bool enable) {
+ // TODO: implement
+ }
+
private:
Channel _voice[NUM_VOICES];
const bool _stereo;
const int _rate;
- int _intFreq;
- int _curInt;
+ const double _periodScale;
+ uint _intFreq;
+ uint _curInt;
+ uint32 _timerBase;
bool _playing;
template<bool stereo>
Modified: scummvm/trunk/sound/mods/soundfx.cpp
===================================================================
--- scummvm/trunk/sound/mods/soundfx.cpp 2009-08-24 18:54:23 UTC (rev 43702)
+++ scummvm/trunk/sound/mods/soundfx.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -46,8 +46,7 @@
enum {
NUM_CHANNELS = 4,
- NUM_INSTRUMENTS = 15,
- CIA_FREQ = 715909
+ NUM_INSTRUMENTS = 15
};
SoundFx(int rate, bool stereo);
@@ -75,12 +74,12 @@
uint16 _curPos;
uint8 _ordersTable[128];
uint8 *_patternData;
- int _eventsFreq;
uint16 _effects[NUM_CHANNELS];
};
SoundFx::SoundFx(int rate, bool stereo)
: Paula(stereo, rate) {
+ setTimerBaseValue(kPalCiaClock);
_ticks = 0;
_delay = 0;
memset(_instruments, 0, sizeof(_instruments));
@@ -89,7 +88,6 @@
_curPos = 0;
memset(_ordersTable, 0, sizeof(_ordersTable));
_patternData = 0;
- _eventsFreq = 0;
memset(_effects, 0, sizeof(_effects));
}
@@ -167,8 +165,7 @@
_curPos = 0;
_curOrder = 0;
_ticks = 0;
- _eventsFreq = CIA_FREQ / _delay;
- setInterruptFreq(getRate() / _eventsFreq);
+ setInterruptFreqUnscaled(_delay);
startPaula();
}
@@ -252,7 +249,7 @@
}
void SoundFx::disablePaulaChannel(uint8 channel) {
- setChannelPeriod(channel, 0);
+ disableChannel(channel);
}
void SoundFx::setupPaulaChannel(uint8 channel, const int8 *data, uint16 len, uint16 repeatPos, uint16 repeatLen) {
Copied: scummvm/trunk/sound/mods/tfmx.cpp (from rev 43702, scummvm/branches/gsoc2009-mods/sound/mods/tfmx.cpp)
===================================================================
--- scummvm/trunk/sound/mods/tfmx.cpp (rev 0)
+++ scummvm/trunk/sound/mods/tfmx.cpp 2009-08-24 20:31:01 UTC (rev 43703)
@@ -0,0 +1,1189 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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/scummsys.h"
+#include "common/endian.h"
+#include "common/stream.h"
+#include "common/util.h"
+#include "common/debug.h"
+
+#include "sound/mods/tfmx.h"
+
+// test for engines using this class.
+#if defined(SOUND_MODS_TFMX_H)
+
+// couple debug-functions
+namespace {
+ void displayPatternstep(const void *const vptr);
+ void displayMacroStep(const void *const vptr);
+
+ const uint16 noteIntervalls[64] = {
+ 1710, 1614, 1524, 1438, 1357, 1281, 1209, 1141, 1077, 1017, 960, 908,
+ 856, 810, 764, 720, 680, 642, 606, 571, 539, 509, 480, 454,
+ 428, 404, 381, 360, 340, 320, 303, 286, 270, 254, 240, 227,
+ 214, 202, 191, 180, 170, 160, 151, 143, 135, 127, 120, 113,
+ 214, 202, 191, 180, 170, 160, 151, 143, 135, 127, 120, 113,
+ 214, 202, 191, 180 };
+}
+
+namespace Audio {
+
+Tfmx::Tfmx(int rate, bool stereo)
+ : Paula(stereo, rate),
+ _resource(),
+ _resourceSample(),
+ _playerCtx(),
+ _deleteResource(false) {
+
+ _playerCtx.stopWithLastPattern = false;
+
+ for (int i = 0; i < kNumVoices; ++i)
+ _channelCtx[i].paulaChannel = (byte)i;
+
+ _playerCtx.volume = 0x40;
+ _playerCtx.patternSkip = 6;
+ stopSongImpl();
+
+ setTimerBaseValue(kPalCiaClock);
+ setInterruptFreqUnscaled(kPalDefaultCiaVal);
+}
+
+Tfmx::~Tfmx() {
+ freeResourceDataImpl();
+}
+
+void Tfmx::interrupt() {
+ assert(!_end);
+ ++_playerCtx.tickCount;
+
+ for (int i = 0; i < kNumVoices; ++i) {
+ if (_channelCtx[i].dmaIntCount) {
+ // wait for DMA Interupts to happen
+ int doneDma = getChannelDmaCount(i);
+ if (doneDma >= _channelCtx[i].dmaIntCount) {
+ _channelCtx[i].dmaIntCount = 0;
+ _channelCtx[i].macroRun = true;
+ }
+ }
+ }
+
+ for (int i = 0; i < kNumVoices; ++i) {
+ ChannelContext &channel = _channelCtx[i];
+
+ if (channel.sfxLockTime >= 0)
+ --channel.sfxLockTime;
+ else {
+ channel.sfxLocked = false;
+ channel.customMacroPrio = 0;
+ }
+
+ // externally queued macros
+ if (channel.customMacro) {
+ const byte *const noteCmd = (const byte *)&channel.customMacro;
+ channel.sfxLocked = false;
+ noteCommand(noteCmd[0], noteCmd[1], (noteCmd[2] & 0xF0) | (uint8)i, noteCmd[3]);
+ channel.customMacro = 0;
+ channel.sfxLocked = (channel.customMacroPrio != 0);
+ }
+
+ // apply timebased effects on Parameters
+ if (channel.macroSfxRun > 0)
+ effects(channel);
+
+ // see if we have to run the macro-program
+ if (channel.macroRun) {
+ if (!channel.macroWait)
+ macroRun(channel);
+ else
+ --channel.macroWait;
+ }
+
+ Paula::setChannelPeriod(i, channel.period);
+ if (channel.macroSfxRun >= 0)
+ channel.macroSfxRun = 1;
+
+ // TODO: handling pending DMAOff?
+ }
+
+ // Patterns are only processed each _playerCtx.timerCount + 1 tick
+ if (_playerCtx.song >= 0 && !_playerCtx.patternCount--) {
+ _playerCtx.patternCount = _playerCtx.patternSkip;
+ advancePatterns();
+ }
+}
+
+void Tfmx::effects(ChannelContext &channel) {
+ // addBegin
+ if (channel.addBeginLength) {
+ channel.sampleStart += channel.addBeginDelta;
+ Paula::setChannelSampleStart(channel.paulaChannel, getSamplePtr(channel.sampleStart));
+ if (!(--channel.addBeginCount)) {
+ channel.addBeginCount = channel.addBeginLength;
+ channel.addBeginDelta = -channel.addBeginDelta;
+ }
+ }
+
+ // vibrato
+ if (channel.vibLength) {
+ channel.vibValue += channel.vibDelta;
+ if (--channel.vibCount == 0) {
+ channel.vibCount = channel.vibLength;
+ channel.vibDelta = -channel.vibDelta;
+ }
+ if (!channel.portaDelta) {
+ // 16x16 bit multiplication, casts needed for the right results
+ channel.period = (uint16)(((uint32)channel.refPeriod * (uint16)((1 << 11) + channel.vibValue)) >> 11);
+ }
+ }
+
+ // portamento
+ if (channel.portaDelta && !(--channel.portaCount)) {
+ channel.portaCount = channel.portaSkip;
+
+ bool resetPorta = true;
+ const uint16 period = channel.refPeriod;
+ uint16 portaVal = channel.portaValue;
+
+ if (period > portaVal) {
+ portaVal = ((uint32)portaVal * (uint16)((1 << 8) + channel.portaDelta)) >> 8;
+ resetPorta = (period <= portaVal);
+
+ } else if (period < portaVal) {
+ portaVal = ((uint32)portaVal * (uint16)((1 << 8) - channel.portaDelta)) >> 8;
+ resetPorta = (period >= portaVal);
+ }
+
+ if (resetPorta) {
+ channel.portaDelta = 0;
+ channel.portaValue = period & 0x7FF;
+ } else
+ channel.period = channel.portaValue = portaVal & 0x7FF;
+ }
+
+ // envelope
+ if (channel.envSkip && !channel.envCount--) {
+ channel.envCount = channel.envSkip;
+
+ const int8 endVol = channel.envEndVolume;
+ int8 volume = channel.volume;
+ bool resetEnv = true;
+
+ if (endVol > volume) {
+ volume += channel.envDelta;
+ resetEnv = endVol <= volume;
+ } else {
+ volume -= channel.envDelta;
@@ Diff output truncated at 100000 characters. @@
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list