added common base class MusicEngine for iMuse/iMuseDigital/Player_V123 (initial stab, more work to follow)

svn-id: r10066
This commit is contained in:
Max Horn 2003-09-07 16:16:19 +00:00
parent 6a438b86a9
commit 0012f7fa96
15 changed files with 98 additions and 41 deletions

View file

@ -373,7 +373,7 @@ bool ScummDebugger::Cmd_IMuse (int argc, const char **argv) {
if (argc > 1) { if (argc > 1) {
if (!strcmp (argv[1], "panic")) { if (!strcmp (argv[1], "panic")) {
if (_s->_imuse) if (_s->_imuse)
_s->_imuse->stop_all_sounds(); _s->_imuse->stopAllSounds();
if (_s->_playerV2) if (_s->_playerV2)
_s->_playerV2->stopAllSounds(); _s->_playerV2->stopAllSounds();
Debug_Printf ("AAAIIIEEEEEE!\n"); Debug_Printf ("AAAIIIEEEEEE!\n");
@ -395,13 +395,11 @@ bool ScummDebugger::Cmd_IMuse (int argc, const char **argv) {
Debug_Printf ("Selecting from %d songs...\n", _s->getNumSounds()); Debug_Printf ("Selecting from %d songs...\n", _s->getNumSounds());
sound = _s->_rnd.getRandomNumber (_s->getNumSounds()); sound = _s->_rnd.getRandomNumber (_s->getNumSounds());
} }
_s->ensureResourceLoaded (rtSound, sound); _s->ensureResourceLoaded(rtSound, sound);
if (_s->_imuse) if (_s->_imuse)
_s->_imuse->startSound (sound); _s->_imuse->startSound(sound);
if (_s->_playerV2) { if (_s->_playerV2) {
byte *ptr = _s->getResourceAddress(rtSound, sound); _s->_playerV2->startSound(sound);
if (ptr)
_s->_playerV2->startSound (sound, ptr);
} }
Debug_Printf ("Attempted to start music %d.\n", sound); Debug_Printf ("Attempted to start music %d.\n", sound);
@ -413,15 +411,15 @@ bool ScummDebugger::Cmd_IMuse (int argc, const char **argv) {
if (argc > 2 && (!strcmp (argv[2], "all") || atoi (argv[2]) != 0)) { if (argc > 2 && (!strcmp (argv[2], "all") || atoi (argv[2]) != 0)) {
if (!strcmp (argv[2], "all")) { if (!strcmp (argv[2], "all")) {
if (_s->_imuse) if (_s->_imuse)
_s->_imuse->stop_all_sounds(); _s->_imuse->stopAllSounds();
if (_s->_playerV2) if (_s->_playerV2)
_s->_playerV2->stopAllSounds(); _s->_playerV2->stopAllSounds();
Debug_Printf ("Shutting down all music tracks.\n"); Debug_Printf ("Shutting down all music tracks.\n");
} else { } else {
if (_s->_imuse) if (_s->_imuse)
_s->_imuse->stopSound (atoi (argv[2])); _s->_imuse->stopSound(atoi (argv[2]));
if (_s->_playerV2) if (_s->_playerV2)
_s->_playerV2->stopSound (atoi (argv[2])); _s->_playerV2->stopSound(atoi (argv[2]));
Debug_Printf ("Attempted to stop music %d.\n", atoi (argv[2])); Debug_Printf ("Attempted to stop music %d.\n", atoi (argv[2]));
} }
} else { } else {

View file

@ -299,7 +299,7 @@ int IMuseInternal::stopSound(int sound) {
return r; return r;
} }
int IMuseInternal::stop_all_sounds() { int IMuseInternal::stopAllSounds() {
Player *player = _players; Player *player = _players;
int i; int i;
@ -610,7 +610,7 @@ int IMuseInternal::get_master_volume() {
} }
int IMuseInternal::terminate() { int IMuseInternal::terminate() {
stop_all_sounds(); stopAllSounds();
if (_midi_adlib) { if (_midi_adlib) {
_midi_adlib->close(); _midi_adlib->close();
@ -699,9 +699,9 @@ int32 IMuseInternal::doCommand (int numargs, int a[]) {
case 9: case 9:
return stopSound(a[1]); return stopSound(a[1]);
case 10: // FIXME: Sam and Max - Not sure if this is correct case 10: // FIXME: Sam and Max - Not sure if this is correct
return stop_all_sounds(); return stopAllSounds();
case 11: case 11:
return stop_all_sounds(); return stopAllSounds();
case 12: case 12:
// Sam & Max: Player-scope commands // Sam & Max: Player-scope commands
player = findActivePlayer(a[1]); player = findActivePlayer(a[1]);
@ -1756,9 +1756,9 @@ int IMuse::set_music_volume(uint vol) { in(); int ret = _target->set_music_volum
int IMuse::get_music_volume() { in(); int ret = _target->get_music_volume(); out(); return ret; } int IMuse::get_music_volume() { in(); int ret = _target->get_music_volume(); out(); return ret; }
int IMuse::set_master_volume(uint vol) { in(); int ret = _target->set_master_volume(vol); out(); return ret; } int IMuse::set_master_volume(uint vol) { in(); int ret = _target->set_master_volume(vol); out(); return ret; }
int IMuse::get_master_volume() { in(); int ret = _target->get_master_volume(); out(); return ret; } int IMuse::get_master_volume() { in(); int ret = _target->get_master_volume(); out(); return ret; }
bool IMuse::startSound(int sound) { in(); bool ret = _target->startSound(sound); out(); return ret; } void IMuse::startSound(int sound) { in(); _target->startSound(sound); out(); }
int IMuse::stopSound(int sound) { in(); int ret = _target->stopSound(sound); out(); return ret; } void IMuse::stopSound(int sound) { in(); _target->stopSound(sound); out(); }
int IMuse::stop_all_sounds() { in(); int ret = _target->stop_all_sounds(); out(); return ret; } int IMuse::stopAllSounds() { in(); int ret = _target->stopAllSounds(); out(); return ret; }
int IMuse::getSoundStatus(int sound) { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; } int IMuse::getSoundStatus(int sound) { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; }
bool IMuse::get_sound_active(int sound) { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; } bool IMuse::get_sound_active(int sound) { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; }
int IMuse::getMusicTimer() { in(); int ret = _target->getMusicTimer(); out(); return ret; } int IMuse::getMusicTimer() { in(); int ret = _target->getMusicTimer(); out(); return ret; }

View file

@ -25,6 +25,7 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/system.h" #include "common/system.h"
#include "scumm/music.h"
class IMuseInternal; class IMuseInternal;
class MidiDriver; class MidiDriver;
@ -33,7 +34,7 @@ class Scumm;
class Serializer; class Serializer;
class SoundMixer; class SoundMixer;
class IMuse { class IMuse : public MusicEngine {
private: private:
OSystem *_system; OSystem *_system;
IMuseInternal *_target; IMuseInternal *_target;
@ -62,9 +63,9 @@ public:
int get_music_volume(); int get_music_volume();
int set_master_volume(uint vol); int set_master_volume(uint vol);
int get_master_volume(); int get_master_volume();
bool startSound(int sound); void startSound(int sound);
int stopSound(int sound); void stopSound(int sound);
int stop_all_sounds(); int stopAllSounds();
int getSoundStatus(int sound); int getSoundStatus(int sound);
bool get_sound_active(int sound); bool get_sound_active(int sound);
int getMusicTimer(); int getMusicTimer();

View file

@ -24,6 +24,7 @@
#define IMUSE_DIGI_H #define IMUSE_DIGI_H
#include "common/scummsys.h" #include "common/scummsys.h"
#include "scumm/music.h"
#include "sound/mixer.h" #include "sound/mixer.h"
#define MAX_DIGITAL_CHANNELS 8 #define MAX_DIGITAL_CHANNELS 8
@ -32,7 +33,7 @@
class Scumm; class Scumm;
class IMuseDigital { class IMuseDigital : public MusicEngine {
private: private:
struct Channel { struct Channel {

View file

@ -461,7 +461,7 @@ public:
int get_master_volume(); int get_master_volume();
bool startSound(int sound); bool startSound(int sound);
int stopSound(int sound); int stopSound(int sound);
int stop_all_sounds(); int stopAllSounds();
int getSoundStatus(int sound, bool ignoreFadeouts = true); int getSoundStatus(int sound, bool ignoreFadeouts = true);
int getMusicTimer(); int getMusicTimer();
int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h); int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h);

39
scumm/music.h Normal file
View file

@ -0,0 +1,39 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001 Ludvig Strigeus
* Copyright (C) 2001-2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* /scummvm/scummvm/scumm/player_v3a.h
*
*/
#ifndef SCUMM_MUSIC_H
#define SCUMM_MUSIC_H
#include "common/scummsys.h"
#include "common/system.h"
class MusicEngine {
public:
virtual ~MusicEngine() {}
virtual void startSound(int sound) = 0;
virtual void stopSound(int sound) = 0;
// virtual void stopAllSounds() = 0;
// virtual int getSoundStatus(int sound) = 0;
};
#endif

View file

@ -63,7 +63,10 @@ void Player_V1::chainSound(int nr, byte *data) {
parseSpeakerChunk(); parseSpeakerChunk();
} }
void Player_V1::startSound(int nr, byte *data) { void Player_V1::startSound(int nr) {
byte *data = _scumm->getResourceAddress(rtSound, nr);
assert(data);
mutex_up(); mutex_up();
int offset = _pcjr ? READ_LE_UINT16(data+4) : 6; int offset = _pcjr ? READ_LE_UINT16(data+4) : 6;

View file

@ -47,7 +47,7 @@ public:
Player_V1(Scumm *scumm); Player_V1(Scumm *scumm);
~Player_V1(); ~Player_V1();
void startSound(int nr, byte *data); void startSound(int nr);
void stopAllSounds(); void stopAllSounds();
void stopSound(int nr); void stopSound(int nr);
int getMusicTimer() const; int getMusicTimer() const;

View file

@ -335,6 +335,7 @@ Player_V2::Player_V2(Scumm *scumm) {
// by the 8253 (square wave generator) and a low-band filter. // by the 8253 (square wave generator) and a low-band filter.
_isV3Game = (scumm->_version >= 3); _isV3Game = (scumm->_version >= 3);
_scumm = scumm;
_system = scumm->_system; _system = scumm->_system;
_mixer = scumm->_mixer; _mixer = scumm->_mixer;
_sample_rate = _system->property(OSystem::PROP_GET_SAMPLE_RATE, 0); _sample_rate = _system->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
@ -479,8 +480,10 @@ void Player_V2::stopSound(int nr) {
mutex_down(); mutex_down();
} }
void Player_V2::startSound(int nr, byte *data) { void Player_V2::startSound(int nr) {
byte *data = _scumm->getResourceAddress(rtSound, nr);
assert(data); assert(data);
mutex_up(); mutex_up();
int cprio = _current_data ? *(_current_data + _header_len) : 0; int cprio = _current_data ? *(_current_data + _header_len) : 0;

View file

@ -25,6 +25,7 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/system.h" #include "common/system.h"
#include "scumm/music.h"
#if !defined(__GNUC__) #if !defined(__GNUC__)
#pragma START_PACK_STRUCTS #pragma START_PACK_STRUCTS
@ -70,14 +71,14 @@ class Scumm;
class SoundMixer; class SoundMixer;
class Player_V2 { class Player_V2 : public MusicEngine {
public: public:
Player_V2(Scumm *scumm); Player_V2(Scumm *scumm);
virtual ~Player_V2(); virtual ~Player_V2();
virtual void set_master_volume(int vol); virtual void set_master_volume(int vol);
virtual void startSound(int nr, byte *data); virtual void startSound(int nr);
virtual void stopSound(int nr); virtual void stopSound(int nr);
virtual void stopAllSounds(); virtual void stopAllSounds();
virtual bool getSoundStatus(int nr) const; virtual bool getSoundStatus(int nr) const;
@ -87,6 +88,7 @@ protected:
bool _isV3Game; bool _isV3Game;
SoundMixer *_mixer; SoundMixer *_mixer;
OSystem *_system; OSystem *_system;
Scumm *_scumm;
bool _pcjr; bool _pcjr;
int _header_len; int _header_len;

View file

@ -79,12 +79,13 @@ void Player_V3A::stopAllSounds() {
_songData = NULL; _songData = NULL;
_songPtr = 0; _songPtr = 0;
_songDelay = 0; _songDelay = 0;
for (int i = 0; i < V3A_MAXCHANS; i++) for (int i = 0; i < V3A_MAXCHANS; i++) {
if (_soundID[i]) { if (_soundID[i]) {
_mixer->stopID(_soundID[i]); _mixer->stopID(_soundID[i]);
_soundID[i] = 0; _soundID[i] = 0;
_timeleft[i] = 0; _timeleft[i] = 0;
} }
}
} }
void Player_V3A::stopSound(int nr) { void Player_V3A::stopSound(int nr) {
@ -134,7 +135,10 @@ void Player_V3A::playSound (int nr, char *data, int size, int rate, int vol, int
else _mixer->playRaw(NULL, data, size, rate, SoundMixer::FLAG_AUTOFREE, nr, vol, 0); else _mixer->playRaw(NULL, data, size, rate, SoundMixer::FLAG_AUTOFREE, nr, vol, 0);
} }
void Player_V3A::startSound(int nr, byte *data) { void Player_V3A::startSound(int nr) {
byte *data = _scumm->getResourceAddress(rtSound, nr);
assert(data);
if (!_isinit) { if (!_isinit) {
int i; int i;
if (_scumm->_gameId == GID_INDY3) { if (_scumm->_gameId == GID_INDY3) {
@ -191,7 +195,8 @@ void Player_V3A::startSound(int nr, byte *data) {
} }
_wavetable[i] = NULL; _wavetable[i] = NULL;
} }
else error("player_v3a - unknown game!"); else
error("player_v3a - unknown game!");
_isinit = true; _isinit = true;
} }

View file

@ -25,20 +25,21 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "common/system.h" #include "common/system.h"
#include "scumm/music.h"
#define V3A_MAXCHANS 8 #define V3A_MAXCHANS 8
class Scumm; class Scumm;
class SoundMixer; class SoundMixer;
class Player_V3A { class Player_V3A : public MusicEngine {
public: public:
Player_V3A(Scumm *scumm); Player_V3A(Scumm *scumm);
virtual ~Player_V3A(); virtual ~Player_V3A();
virtual void set_master_volume(int vol); virtual void set_master_volume(int vol);
virtual void startSound(int nr, byte *data); virtual void startSound(int nr);
virtual void stopSound(int nr); virtual void stopSound(int nr);
virtual void stopAllSounds(); virtual void stopAllSounds();
virtual int getMusicTimer() const; virtual int getMusicTimer() const;

View file

@ -29,7 +29,7 @@
#include "common/rect.h" #include "common/rect.h"
#include "common/str.h" #include "common/str.h"
#include "gfx.h" #include "scumm/gfx.h"
class Actor; class Actor;
class BaseCostumeRenderer; class BaseCostumeRenderer;
@ -39,6 +39,7 @@ class Dialog;
class GameDetector; class GameDetector;
class IMuse; class IMuse;
class IMuseDigital; class IMuseDigital;
class MusicEngine;
class NewGui; class NewGui;
class Player_V2; class Player_V2;
class Player_V3A; class Player_V3A;
@ -307,6 +308,7 @@ public:
IMuseDigital *_imuseDigital; IMuseDigital *_imuseDigital;
Player_V2 *_playerV2; Player_V2 *_playerV2;
Player_V3A *_playerV3A; Player_V3A *_playerV3A;
MusicEngine *_musicEngine;
Sound *_sound; Sound *_sound;
VerbSlot *_verbs; VerbSlot *_verbs;

View file

@ -692,16 +692,17 @@ Scumm::Scumm (GameDetector *detector, OSystem *syst)
_imuseDigital = NULL; _imuseDigital = NULL;
_playerV2 = NULL; _playerV2 = NULL;
_playerV3A = NULL; _playerV3A = NULL;
_musicEngine = NULL;
if (_features & GF_DIGI_IMUSE) { if (_features & GF_DIGI_IMUSE) {
_imuseDigital = new IMuseDigital(this); _musicEngine = _imuseDigital = new IMuseDigital(this);
} else if ((_features & GF_AMIGA) && (_version == 3)) { } else if ((_features & GF_AMIGA) && (_version == 3)) {
_playerV3A = new Player_V3A(this); _musicEngine = _playerV3A = new Player_V3A(this);
} else if ((_features & GF_AMIGA) && (_version < 5)) { } else if ((_features & GF_AMIGA) && (_version < 5)) {
_playerV2 = NULL; _playerV2 = NULL;
} else if (((_midiDriver == MD_PCJR) || (_midiDriver == MD_PCSPK)) && ((_version > 2) && (_version < 5))) { } else if (((_midiDriver == MD_PCJR) || (_midiDriver == MD_PCSPK)) && ((_version > 2) && (_version < 5))) {
_playerV2 = new Player_V2(this); _musicEngine = _playerV2 = new Player_V2(this);
} else if (_version > 2) { } else if (_version > 2) {
_imuse = IMuse::create (syst, _mixer, detector->createMidi()); _musicEngine = _imuse = IMuse::create(syst, _mixer, detector->createMidi());
if (_imuse) { if (_imuse) {
if (detector->_gameTempo != 0) if (detector->_gameTempo != 0)
_imuse->property(IMuse::PROP_TEMPO_BASE, detector->_gameTempo); _imuse->property(IMuse::PROP_TEMPO_BASE, detector->_gameTempo);

View file

@ -182,6 +182,7 @@ void Sound::playSound(int soundID) {
// FIXME: Should we replace this by an assert, and/or print an error message? // FIXME: Should we replace this by an assert, and/or print an error message?
return; return;
} }
if (READ_UINT32(ptr) == MKID('iMUS')){ if (READ_UINT32(ptr) == MKID('iMUS')){
assert(_scumm->_imuseDigital); assert(_scumm->_imuseDigital);
_scumm->_imuseDigital->startSound(soundID); _scumm->_imuseDigital->startSound(soundID);
@ -478,16 +479,16 @@ void Sound::playSound(int soundID) {
// automatically stop the old song. // automatically stop the old song.
if (_scumm->_imuse) { if (_scumm->_imuse) {
if (READ_UINT32(ptr) != MKID('ASFX')) if (READ_UINT32(ptr) != MKID('ASFX'))
_scumm->_imuse->stop_all_sounds(); _scumm->_imuse->stopAllSounds();
} }
} }
if (_scumm->_playerV2) { if (_scumm->_playerV2) {
_scumm->_playerV2->startSound(soundID, ptr); _scumm->_playerV2->startSound(soundID);
} }
if (_scumm->_playerV3A) if (_scumm->_playerV3A)
_scumm->_playerV3A->startSound(soundID, ptr); _scumm->_playerV3A->startSound(soundID);
if (_scumm->_imuse) { if (_scumm->_imuse) {
_scumm->_imuse->startSound(soundID); _scumm->_imuse->startSound(soundID);
@ -780,7 +781,7 @@ void Sound::stopAllSounds() {
} }
if (_scumm->_imuse) { if (_scumm->_imuse) {
_scumm->_imuse->stop_all_sounds(); _scumm->_imuse->stopAllSounds();
_scumm->_imuse->clear_queue(); _scumm->_imuse->clear_queue();
} else if (_scumm->_playerV2) { } else if (_scumm->_playerV2) {
_scumm->_playerV2->stopAllSounds(); _scumm->_playerV2->stopAllSounds();