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 (!strcmp (argv[1], "panic")) {
if (_s->_imuse)
_s->_imuse->stop_all_sounds();
_s->_imuse->stopAllSounds();
if (_s->_playerV2)
_s->_playerV2->stopAllSounds();
Debug_Printf ("AAAIIIEEEEEE!\n");
@ -399,9 +399,7 @@ bool ScummDebugger::Cmd_IMuse (int argc, const char **argv) {
if (_s->_imuse)
_s->_imuse->startSound(sound);
if (_s->_playerV2) {
byte *ptr = _s->getResourceAddress(rtSound, sound);
if (ptr)
_s->_playerV2->startSound (sound, ptr);
_s->_playerV2->startSound(sound);
}
Debug_Printf ("Attempted to start music %d.\n", sound);
@ -413,7 +411,7 @@ bool ScummDebugger::Cmd_IMuse (int argc, const char **argv) {
if (argc > 2 && (!strcmp (argv[2], "all") || atoi (argv[2]) != 0)) {
if (!strcmp (argv[2], "all")) {
if (_s->_imuse)
_s->_imuse->stop_all_sounds();
_s->_imuse->stopAllSounds();
if (_s->_playerV2)
_s->_playerV2->stopAllSounds();
Debug_Printf ("Shutting down all music tracks.\n");

View file

@ -299,7 +299,7 @@ int IMuseInternal::stopSound(int sound) {
return r;
}
int IMuseInternal::stop_all_sounds() {
int IMuseInternal::stopAllSounds() {
Player *player = _players;
int i;
@ -610,7 +610,7 @@ int IMuseInternal::get_master_volume() {
}
int IMuseInternal::terminate() {
stop_all_sounds();
stopAllSounds();
if (_midi_adlib) {
_midi_adlib->close();
@ -699,9 +699,9 @@ int32 IMuseInternal::doCommand (int numargs, int a[]) {
case 9:
return stopSound(a[1]);
case 10: // FIXME: Sam and Max - Not sure if this is correct
return stop_all_sounds();
return stopAllSounds();
case 11:
return stop_all_sounds();
return stopAllSounds();
case 12:
// Sam & Max: Player-scope commands
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::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; }
bool IMuse::startSound(int sound) { in(); bool ret = _target->startSound(sound); out(); return ret; }
int IMuse::stopSound(int sound) { in(); int ret = _target->stopSound(sound); out(); return ret; }
int IMuse::stop_all_sounds() { in(); int ret = _target->stop_all_sounds(); out(); return ret; }
void IMuse::startSound(int sound) { in(); _target->startSound(sound); out(); }
void IMuse::stopSound(int sound) { in(); _target->stopSound(sound); out(); }
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; }
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; }

View file

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

View file

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

View file

@ -461,7 +461,7 @@ public:
int get_master_volume();
bool startSound(int sound);
int stopSound(int sound);
int stop_all_sounds();
int stopAllSounds();
int getSoundStatus(int sound, bool ignoreFadeouts = true);
int getMusicTimer();
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();
}
void Player_V1::startSound(int nr, byte *data) {
void Player_V1::startSound(int nr) {
byte *data = _scumm->getResourceAddress(rtSound, nr);
assert(data);
mutex_up();
int offset = _pcjr ? READ_LE_UINT16(data+4) : 6;

View file

@ -47,7 +47,7 @@ public:
Player_V1(Scumm *scumm);
~Player_V1();
void startSound(int nr, byte *data);
void startSound(int nr);
void stopAllSounds();
void stopSound(int nr);
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.
_isV3Game = (scumm->_version >= 3);
_scumm = scumm;
_system = scumm->_system;
_mixer = scumm->_mixer;
_sample_rate = _system->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
@ -479,8 +480,10 @@ void Player_V2::stopSound(int nr) {
mutex_down();
}
void Player_V2::startSound(int nr, byte *data) {
void Player_V2::startSound(int nr) {
byte *data = _scumm->getResourceAddress(rtSound, nr);
assert(data);
mutex_up();
int cprio = _current_data ? *(_current_data + _header_len) : 0;

View file

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

View file

@ -79,13 +79,14 @@ void Player_V3A::stopAllSounds() {
_songData = NULL;
_songPtr = 0;
_songDelay = 0;
for (int i = 0; i < V3A_MAXCHANS; i++)
for (int i = 0; i < V3A_MAXCHANS; i++) {
if (_soundID[i]) {
_mixer->stopID(_soundID[i]);
_soundID[i] = 0;
_timeleft[i] = 0;
}
}
}
void Player_V3A::stopSound(int nr) {
int i;
@ -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);
}
void Player_V3A::startSound(int nr, byte *data) {
void Player_V3A::startSound(int nr) {
byte *data = _scumm->getResourceAddress(rtSound, nr);
assert(data);
if (!_isinit) {
int i;
if (_scumm->_gameId == GID_INDY3) {
@ -191,7 +195,8 @@ void Player_V3A::startSound(int nr, byte *data) {
}
_wavetable[i] = NULL;
}
else error("player_v3a - unknown game!");
else
error("player_v3a - unknown game!");
_isinit = true;
}

View file

@ -25,20 +25,21 @@
#include "common/scummsys.h"
#include "common/system.h"
#include "scumm/music.h"
#define V3A_MAXCHANS 8
class Scumm;
class SoundMixer;
class Player_V3A {
class Player_V3A : public MusicEngine {
public:
Player_V3A(Scumm *scumm);
virtual ~Player_V3A();
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 stopAllSounds();
virtual int getMusicTimer() const;

View file

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

View file

@ -692,16 +692,17 @@ Scumm::Scumm (GameDetector *detector, OSystem *syst)
_imuseDigital = NULL;
_playerV2 = NULL;
_playerV3A = NULL;
_musicEngine = NULL;
if (_features & GF_DIGI_IMUSE) {
_imuseDigital = new IMuseDigital(this);
_musicEngine = _imuseDigital = new IMuseDigital(this);
} 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)) {
_playerV2 = NULL;
} 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) {
_imuse = IMuse::create (syst, _mixer, detector->createMidi());
_musicEngine = _imuse = IMuse::create(syst, _mixer, detector->createMidi());
if (_imuse) {
if (detector->_gameTempo != 0)
_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?
return;
}
if (READ_UINT32(ptr) == MKID('iMUS')){
assert(_scumm->_imuseDigital);
_scumm->_imuseDigital->startSound(soundID);
@ -478,16 +479,16 @@ void Sound::playSound(int soundID) {
// automatically stop the old song.
if (_scumm->_imuse) {
if (READ_UINT32(ptr) != MKID('ASFX'))
_scumm->_imuse->stop_all_sounds();
_scumm->_imuse->stopAllSounds();
}
}
if (_scumm->_playerV2) {
_scumm->_playerV2->startSound(soundID, ptr);
_scumm->_playerV2->startSound(soundID);
}
if (_scumm->_playerV3A)
_scumm->_playerV3A->startSound(soundID, ptr);
_scumm->_playerV3A->startSound(soundID);
if (_scumm->_imuse) {
_scumm->_imuse->startSound(soundID);
@ -780,7 +781,7 @@ void Sound::stopAllSounds() {
}
if (_scumm->_imuse) {
_scumm->_imuse->stop_all_sounds();
_scumm->_imuse->stopAllSounds();
_scumm->_imuse->clear_queue();
} else if (_scumm->_playerV2) {
_scumm->_playerV2->stopAllSounds();