aboutsummaryrefslogtreecommitdiff
path: root/engines/sky/music/musicbase.cpp
diff options
context:
space:
mode:
authorMax Horn2006-02-11 22:45:04 +0000
committerMax Horn2006-02-11 22:45:04 +0000
commit26ee630756ebdd7c96bccede0881a8c8b98e8f2b (patch)
tree26e378d5cf990a2b81c2c96e9e683a7f333b62e8 /engines/sky/music/musicbase.cpp
parent2a9a0d4211b1ea5723f1409d91cb95de8984429e (diff)
downloadscummvm-rg350-26ee630756ebdd7c96bccede0881a8c8b98e8f2b.tar.gz
scummvm-rg350-26ee630756ebdd7c96bccede0881a8c8b98e8f2b.tar.bz2
scummvm-rg350-26ee630756ebdd7c96bccede0881a8c8b98e8f2b.zip
Moved engines to the new engines/ directory
svn-id: r20582
Diffstat (limited to 'engines/sky/music/musicbase.cpp')
-rw-r--r--engines/sky/music/musicbase.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/engines/sky/music/musicbase.cpp b/engines/sky/music/musicbase.cpp
new file mode 100644
index 0000000000..9d308ebc7f
--- /dev/null
+++ b/engines/sky/music/musicbase.cpp
@@ -0,0 +1,148 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2003-2006 The ScummVM project
+ *
+ * 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 "sky/music/musicbase.h"
+#include "sky/disk.h"
+#include "common/util.h"
+
+namespace Sky {
+
+MusicBase::MusicBase(Disk *pDisk) {
+
+ _musicData = NULL;
+ _allowedCommands = 0;
+ _skyDisk = pDisk;
+ _currentMusic = 0;
+ _musicVolume = 127;
+ _numberOfChannels = _currentMusic = 0;
+}
+
+MusicBase::~MusicBase(void) {
+
+ stopMusic();
+ if (_musicData)
+ free(_musicData);
+}
+
+void MusicBase::loadSection(uint8 pSection) {
+
+ _mutex.lock();
+ if (_currentMusic)
+ stopMusic();
+ if (_musicData)
+ free(_musicData);
+ _currentSection = pSection;
+ _musicData = _skyDisk->loadFile(_driverFileBase + FILES_PER_SECTION * pSection);
+ _allowedCommands = 0;
+ _musicTempo0 = 0x78; // init constants taken from idb file, area ~0x1060
+ _musicTempo1 = 0xC0;
+ _onNextPoll.doReInit = false;
+ _onNextPoll.doStopMusic = false;
+ _onNextPoll.musicToProcess = 0;
+ _tempo = _aktTime = 0x10001;
+ _numberOfChannels = _currentMusic = 0;
+ setupPointers();
+ startDriver();
+ _mutex.unlock();
+}
+
+bool MusicBase::musicIsPlaying(void) {
+
+ for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++)
+ if (_channels[cnt]->isActive())
+ return true;
+ return false;
+}
+
+void MusicBase::setVolume(uint16 param) {
+
+ _musicVolume = param;
+ for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++)
+ _channels[cnt]->updateVolume(_musicVolume);
+}
+
+void MusicBase::stopMusic(void) {
+
+ for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++) {
+ _channels[cnt]->stopNote();
+ delete _channels[cnt];
+ }
+ _numberOfChannels = 0;
+}
+
+void MusicBase::updateTempo(void) {
+
+ uint16 tempoMul = _musicTempo0 * _musicTempo1;
+ uint16 divisor = 0x4446390/ 23864;
+ _tempo = (tempoMul / divisor) << 16;
+ _tempo |= (((tempoMul%divisor) << 16) | (tempoMul / divisor)) / divisor;
+}
+
+void MusicBase::loadNewMusic(void) {
+
+ uint16 musicPos;
+ if (_onNextPoll.musicToProcess > _musicData[_musicDataLoc]) {
+ error("Music %d requested but doesn't exist in file.", _onNextPoll.musicToProcess);
+ return;
+ }
+ if (_currentMusic != 0)
+ stopMusic();
+
+ _currentMusic = _onNextPoll.musicToProcess;
+
+ if (_currentMusic != 0) {
+ musicPos = (_musicData[_musicDataLoc + 2] << 8) | _musicData[_musicDataLoc+1];
+ musicPos += _musicDataLoc+((_currentMusic-1) << 1);
+ musicPos = ((_musicData[musicPos+1] << 8) | _musicData[musicPos]) + _musicDataLoc;
+
+ _musicTempo0 = _musicData[musicPos];
+ _musicTempo1 = _musicData[musicPos+1];
+
+ setupChannels(_musicData + musicPos + 2);
+
+ updateTempo();
+ }
+}
+
+void MusicBase::pollMusic(void) {
+
+ _mutex.lock();
+ uint8 newTempo;
+ if (_onNextPoll.doReInit) startDriver();
+ if (_onNextPoll.doStopMusic) stopMusic();
+ if (_onNextPoll.musicToProcess != _currentMusic)
+ loadNewMusic();
+
+ _aktTime += _tempo;
+
+ for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++) {
+ newTempo = _channels[cnt]->process((uint16)(_aktTime >> 16));
+ if (newTempo) {
+ _musicTempo1 = newTempo;
+ updateTempo();
+ }
+ }
+ _mutex.unlock();
+ _aktTime &= 0xFFFF;
+}
+
+} // End of namespace Sky