aboutsummaryrefslogtreecommitdiff
path: root/engines/sky/music
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sky/music')
-rw-r--r--engines/sky/music/adlibmusic.cpp3
-rw-r--r--engines/sky/music/adlibmusic.h2
-rw-r--r--engines/sky/music/gmmusic.cpp2
-rw-r--r--engines/sky/music/gmmusic.h2
-rw-r--r--engines/sky/music/mt32music.cpp2
-rw-r--r--engines/sky/music/mt32music.h2
-rw-r--r--engines/sky/music/musicbase.cpp59
-rw-r--r--engines/sky/music/musicbase.h6
8 files changed, 59 insertions, 19 deletions
diff --git a/engines/sky/music/adlibmusic.cpp b/engines/sky/music/adlibmusic.cpp
index 1b5518fcb1..a41cd6a81d 100644
--- a/engines/sky/music/adlibmusic.cpp
+++ b/engines/sky/music/adlibmusic.cpp
@@ -30,9 +30,8 @@
namespace Sky {
-AdLibMusic::AdLibMusic(Audio::Mixer *pMixer, Disk *pDisk) : MusicBase(pDisk) {
+AdLibMusic::AdLibMusic(Audio::Mixer *pMixer, Disk *pDisk) : MusicBase(pMixer, pDisk) {
_driverFileBase = 60202;
- _mixer = pMixer;
_sampleRate = pMixer->getOutputRate();
_opl = makeAdLibOPL(_sampleRate);
diff --git a/engines/sky/music/adlibmusic.h b/engines/sky/music/adlibmusic.h
index 2782a07be6..2161795b4c 100644
--- a/engines/sky/music/adlibmusic.h
+++ b/engines/sky/music/adlibmusic.h
@@ -26,7 +26,6 @@
#include "sky/music/musicbase.h"
#include "audio/audiostream.h"
#include "audio/fmopl.h"
-#include "audio/mixer.h"
namespace Sky {
@@ -44,7 +43,6 @@ public:
private:
FM_OPL *_opl;
- Audio::Mixer *_mixer;
Audio::SoundHandle _soundHandle;
uint8 *_initSequence;
uint32 _sampleRate, _nextMusicPoll;
diff --git a/engines/sky/music/gmmusic.cpp b/engines/sky/music/gmmusic.cpp
index d0ba1505cb..85240ea82e 100644
--- a/engines/sky/music/gmmusic.cpp
+++ b/engines/sky/music/gmmusic.cpp
@@ -34,7 +34,7 @@ void GmMusic::passTimerFunc(void *param) {
((GmMusic*)param)->timerCall();
}
-GmMusic::GmMusic(MidiDriver *pMidiDrv, Disk *pDisk) : MusicBase(pDisk) {
+GmMusic::GmMusic(MidiDriver *pMidiDrv, Audio::Mixer *pMixer, Disk *pDisk) : MusicBase(pMixer, pDisk) {
_driverFileBase = 60200;
_midiDrv = pMidiDrv;
int midiRes = _midiDrv->open();
diff --git a/engines/sky/music/gmmusic.h b/engines/sky/music/gmmusic.h
index 0f54a930e4..068601ba1f 100644
--- a/engines/sky/music/gmmusic.h
+++ b/engines/sky/music/gmmusic.h
@@ -31,7 +31,7 @@ namespace Sky {
class GmMusic : public MusicBase {
public:
- GmMusic(MidiDriver *pMidiDrv, Disk *pDisk);
+ GmMusic(MidiDriver *pMidiDrv, Audio::Mixer *pMixer, Disk *pDisk);
~GmMusic();
virtual void setVolume(uint16 param);
private:
diff --git a/engines/sky/music/mt32music.cpp b/engines/sky/music/mt32music.cpp
index d068a221b2..18ebf123ff 100644
--- a/engines/sky/music/mt32music.cpp
+++ b/engines/sky/music/mt32music.cpp
@@ -34,7 +34,7 @@ void MT32Music::passTimerFunc(void *param) {
((MT32Music*)param)->timerCall();
}
-MT32Music::MT32Music(MidiDriver *pMidiDrv, Disk *pDisk) : MusicBase(pDisk) {
+MT32Music::MT32Music(MidiDriver *pMidiDrv, Audio::Mixer *pMixer, Disk *pDisk) : MusicBase(pMixer, pDisk) {
_driverFileBase = 60200;
_midiDrv = pMidiDrv;
int midiRes = _midiDrv->open();
diff --git a/engines/sky/music/mt32music.h b/engines/sky/music/mt32music.h
index 74962daac3..8f8e70f51b 100644
--- a/engines/sky/music/mt32music.h
+++ b/engines/sky/music/mt32music.h
@@ -31,7 +31,7 @@ namespace Sky {
class MT32Music : public MusicBase {
public:
- MT32Music(MidiDriver *pMidiDrv, Disk *pDisk);
+ MT32Music(MidiDriver *pMidiDrv, Audio::Mixer *pMixer, Disk *pDisk);
~MT32Music();
private:
static void passTimerFunc(void *param);
diff --git a/engines/sky/music/musicbase.cpp b/engines/sky/music/musicbase.cpp
index 60d0f352e7..018614da98 100644
--- a/engines/sky/music/musicbase.cpp
+++ b/engines/sky/music/musicbase.cpp
@@ -25,11 +25,13 @@
#include "common/util.h"
#include "common/endian.h"
#include "common/textconsole.h"
+#include "audio/audiostream.h"
namespace Sky {
-MusicBase::MusicBase(Disk *pDisk) {
+MusicBase::MusicBase(Audio::Mixer *pMixer, Disk *pDisk) {
_musicData = NULL;
+ _mixer = pMixer;
_skyDisk = pDisk;
_currentMusic = 0;
_musicVolume = 127;
@@ -59,6 +61,8 @@ void MusicBase::loadSection(uint8 pSection) {
}
bool MusicBase::musicIsPlaying() {
+ if (_mixer->isSoundHandleActive(_musicHandle))
+ return true;
for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++)
if (_channels[cnt]->isActive())
return true;
@@ -71,6 +75,8 @@ void MusicBase::stopMusic() {
}
void MusicBase::stopMusicInternal() {
+ _mixer->stopHandle(_musicHandle);
+
for (uint8 cnt = 0; cnt < _numberOfChannels; cnt++)
delete _channels[cnt];
_numberOfChannels = 0;
@@ -94,18 +100,51 @@ void MusicBase::loadNewMusic() {
_currentMusic = _onNextPoll.musicToProcess;
- if (_currentMusic != 0) {
- musicPos = READ_LE_UINT16(_musicData + _musicDataLoc + 1);
- musicPos += _musicDataLoc + ((_currentMusic - 1) << 1);
- musicPos = READ_LE_UINT16(_musicData + musicPos) + _musicDataLoc;
+ if (_currentMusic == 0)
+ return;
+
+ // Try playing digital audio first (from the Music Enhancement Project).
+ // TODO: This always prefers digital music over the MIDI music types!
+ uint8 section = _currentSection;
+ uint8 song = _currentMusic;
+ // handle duplicates
+ if ((section == 2 && song == 1) || (section == 5 && song == 1)) {
+ section = 1;
+ song = 1;
+ } else if ((section == 2 && song == 4) || (section == 5 && song == 4)) {
+ section = 1;
+ song = 4;
+ } else if (section == 5 && song == 6) {
+ section = 4;
+ song = 4;
+ }
+ Common::String trackName = Common::String::format("music_%d%02d", section, song);
+ Audio::SeekableAudioStream *stream = Audio::SeekableAudioStream::openStreamFile(trackName);
+ if (stream) {
+ // not all tracks should loop
+ bool loops = true;
+ if ((section == 1 && song == 1) || (section == 1 && song == 4)
+ || (section == 2 && song == 1) || (section == 2 && song == 4)
+ || (section == 4 && song == 2) || (section == 4 && song == 3)
+ || (section == 4 && song == 5) || (section == 4 && song == 6)
+ || (section == 4 && song == 11) || (section == 5 && song == 1)
+ || (section == 5 && song == 3) || (section == 5 && song == 4))
+ loops = false;
+ _mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, Audio::makeLoopingAudioStream(stream, loops ? 0 : 1));
+ return;
+ }
+
+ // no digital audio, resort to MIDI playback
+ musicPos = READ_LE_UINT16(_musicData + _musicDataLoc + 1);
+ musicPos += _musicDataLoc + ((_currentMusic - 1) << 1);
+ musicPos = READ_LE_UINT16(_musicData + musicPos) + _musicDataLoc;
- _musicTempo0 = _musicData[musicPos];
- _musicTempo1 = _musicData[musicPos+1];
+ _musicTempo0 = _musicData[musicPos];
+ _musicTempo1 = _musicData[musicPos+1];
- setupChannels(_musicData + musicPos + 2);
+ setupChannels(_musicData + musicPos + 2);
- updateTempo();
- }
+ updateTempo();
}
void MusicBase::pollMusic() {
diff --git a/engines/sky/music/musicbase.h b/engines/sky/music/musicbase.h
index c175876380..066ebe593c 100644
--- a/engines/sky/music/musicbase.h
+++ b/engines/sky/music/musicbase.h
@@ -27,6 +27,8 @@
#include "common/scummsys.h"
#include "common/mutex.h"
+#include "audio/mixer.h"
+
namespace Sky {
class Disk;
@@ -48,7 +50,7 @@ private:
class MusicBase {
public:
- MusicBase(Disk *pDisk);
+ MusicBase(Audio::Mixer *pMixer, Disk *pDisk);
virtual ~MusicBase();
void loadSection(uint8 pSection);
void startMusic(uint16 param);
@@ -60,6 +62,7 @@ public:
protected:
+ Audio::Mixer *_mixer;
Disk *_skyDisk;
uint8 *_musicData;
@@ -75,6 +78,7 @@ protected:
Actions _onNextPoll;
ChannelBase *_channels[10];
Common::Mutex _mutex;
+ Audio::SoundHandle _musicHandle;
virtual void setupPointers() = 0;
virtual void setupChannels(uint8 *channelData) = 0;