2010-01-23 22:50:24 +00:00
|
|
|
/* 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.
|
2007-06-22 12:30:18 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2007-06-22 12:30:18 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LURE_SOUND_H
|
|
|
|
#define LURE_SOUND_H
|
|
|
|
|
|
|
|
#include "lure/luredefs.h"
|
2007-08-12 11:08:44 +00:00
|
|
|
#include "lure/disk.h"
|
|
|
|
#include "lure/memory.h"
|
2007-09-16 04:06:49 +00:00
|
|
|
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "common/mutex.h"
|
2007-06-22 12:30:18 +00:00
|
|
|
#include "common/singleton.h"
|
2008-04-06 11:12:42 +00:00
|
|
|
#include "common/ptr.h"
|
2011-08-05 12:33:42 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/mididrv.h"
|
2007-09-16 04:06:49 +00:00
|
|
|
|
|
|
|
class MidiParser;
|
2011-08-05 12:33:42 +00:00
|
|
|
class MidiChannel;
|
2007-06-22 12:30:18 +00:00
|
|
|
|
|
|
|
namespace Lure {
|
|
|
|
|
2008-03-19 10:37:33 +00:00
|
|
|
#define NUM_CHANNELS 16
|
2007-09-16 04:06:49 +00:00
|
|
|
|
|
|
|
struct ChannelEntry {
|
|
|
|
MidiChannel *midiChannel;
|
2007-12-16 08:19:56 +00:00
|
|
|
uint8 volume;
|
2007-09-16 04:06:49 +00:00
|
|
|
};
|
|
|
|
|
2011-03-23 14:23:26 +00:00
|
|
|
class MidiMusic: public MidiDriver_BASE {
|
2007-09-16 04:06:49 +00:00
|
|
|
private:
|
|
|
|
uint8 _soundNumber;
|
|
|
|
uint8 _channelNumber;
|
|
|
|
uint8 _numChannels;
|
|
|
|
byte _volume;
|
|
|
|
MemoryBlock *_decompressedSound;
|
|
|
|
uint8 *_soundData;
|
|
|
|
uint8 _soundSize;
|
|
|
|
MidiDriver *_driver;
|
|
|
|
MidiParser *_parser;
|
|
|
|
ChannelEntry *_channels;
|
2008-03-19 10:37:33 +00:00
|
|
|
bool _isMusic;
|
2007-09-16 04:06:49 +00:00
|
|
|
bool _isPlaying;
|
|
|
|
|
|
|
|
void queueUpdatePos();
|
|
|
|
uint8 randomQueuePos();
|
|
|
|
uint32 songOffset(uint16 songNum) const;
|
|
|
|
uint32 songLength(uint16 songNum) const;
|
|
|
|
|
|
|
|
public:
|
2008-03-19 10:37:33 +00:00
|
|
|
MidiMusic(MidiDriver *driver, ChannelEntry channels[NUM_CHANNELS],
|
2008-06-30 23:06:38 +00:00
|
|
|
uint8 channelNum, uint8 soundNum, bool isMus, uint8 numChannels, void *soundData, uint32 size);
|
2007-09-16 04:06:49 +00:00
|
|
|
~MidiMusic();
|
|
|
|
void setVolume(int volume);
|
2011-03-23 16:07:48 +00:00
|
|
|
int getVolume() const { return _volume; }
|
2007-09-16 04:06:49 +00:00
|
|
|
|
|
|
|
void playSong(uint16 songNum);
|
|
|
|
void stopSong() { stopMusic(); }
|
|
|
|
void playMusic();
|
|
|
|
void stopMusic();
|
|
|
|
void queueTuneList(int16 tuneList);
|
|
|
|
bool queueSong(uint16 songNum);
|
|
|
|
void toggleVChange();
|
|
|
|
|
2011-03-23 15:14:39 +00:00
|
|
|
// MidiDriver_BASE interface implementation
|
|
|
|
virtual void send(uint32 b);
|
|
|
|
virtual void metaEvent(byte type, byte *data, uint16 length);
|
2007-09-16 04:06:49 +00:00
|
|
|
|
2011-03-23 15:14:39 +00:00
|
|
|
void onTimer();
|
2007-09-16 04:06:49 +00:00
|
|
|
|
2011-03-23 16:07:48 +00:00
|
|
|
uint8 channelNumber() const { return _channelNumber; }
|
|
|
|
uint8 soundNumber() const { return _soundNumber; }
|
|
|
|
bool isPlaying() const { return _isPlaying; }
|
|
|
|
bool isMusic() const { return _isMusic; }
|
2007-09-16 04:06:49 +00:00
|
|
|
};
|
2007-08-12 11:08:44 +00:00
|
|
|
|
2010-07-21 20:12:35 +00:00
|
|
|
class SoundManager : public Common::Singleton<SoundManager> {
|
2007-08-12 11:08:44 +00:00
|
|
|
private:
|
2007-09-16 04:06:49 +00:00
|
|
|
// Outer sound interface properties
|
2007-08-12 11:08:44 +00:00
|
|
|
MemoryBlock *_descs;
|
2007-09-16 04:06:49 +00:00
|
|
|
MemoryBlock *_soundData;
|
|
|
|
uint8 _soundsTotal;
|
2007-08-12 11:08:44 +00:00
|
|
|
int _numDescs;
|
|
|
|
SoundDescResource *soundDescs() { return (SoundDescResource *) _descs->data(); }
|
2007-09-16 04:06:49 +00:00
|
|
|
MidiDriver *_driver;
|
2008-04-06 11:12:42 +00:00
|
|
|
typedef Common::List<Common::SharedPtr<SoundDescResource> > SoundList;
|
|
|
|
typedef SoundList::iterator SoundListIterator;
|
|
|
|
SoundList _activeSounds;
|
|
|
|
typedef Common::List<Common::SharedPtr<MidiMusic> > MusicList;
|
|
|
|
typedef MusicList::iterator MusicListIterator;
|
|
|
|
MusicList _playingSounds;
|
2008-03-19 10:37:33 +00:00
|
|
|
ChannelEntry _channelsInner[NUM_CHANNELS];
|
|
|
|
bool _channelsInUse[NUM_CHANNELS];
|
2007-09-16 04:06:49 +00:00
|
|
|
bool _isPlaying;
|
|
|
|
bool _nativeMT32;
|
2007-12-16 08:19:56 +00:00
|
|
|
bool _isRoland;
|
2007-09-28 07:55:02 +00:00
|
|
|
Common::MutexRef _soundMutex;
|
2007-10-28 03:32:13 +00:00
|
|
|
bool _paused;
|
2007-08-12 11:08:44 +00:00
|
|
|
|
2010-07-21 20:12:35 +00:00
|
|
|
uint _musicVolume;
|
|
|
|
uint _sfxVolume;
|
|
|
|
|
2007-09-16 04:06:49 +00:00
|
|
|
// Internal support methods
|
2007-08-12 11:08:44 +00:00
|
|
|
void bellsBodge();
|
2007-09-16 04:06:49 +00:00
|
|
|
void musicInterface_TidySounds();
|
|
|
|
static void onTimer(void *data);
|
2007-09-28 07:55:02 +00:00
|
|
|
void doTimer();
|
2010-07-21 20:12:35 +00:00
|
|
|
|
2007-06-22 12:30:18 +00:00
|
|
|
public:
|
2007-08-12 11:08:44 +00:00
|
|
|
SoundManager();
|
2007-09-16 04:06:49 +00:00
|
|
|
~SoundManager();
|
2007-08-12 11:08:44 +00:00
|
|
|
|
2010-01-19 23:48:55 +00:00
|
|
|
void saveToStream(Common::WriteStream *stream);
|
|
|
|
void loadFromStream(Common::ReadStream *stream);
|
2007-10-28 03:32:13 +00:00
|
|
|
|
2007-09-16 04:06:49 +00:00
|
|
|
void loadSection(uint16 sectionId);
|
2007-08-12 11:08:44 +00:00
|
|
|
void killSounds();
|
|
|
|
void addSound(uint8 soundIndex, bool tidyFlag = true);
|
|
|
|
void addSound2(uint8 soundIndex);
|
|
|
|
void stopSound(uint8 soundIndex);
|
|
|
|
void killSound(uint8 soundNumber);
|
|
|
|
void setVolume(uint8 soundNumber, uint8 volume);
|
2008-07-15 22:54:39 +00:00
|
|
|
void syncSounds();
|
2007-08-12 11:08:44 +00:00
|
|
|
void tidySounds();
|
2007-10-28 03:32:13 +00:00
|
|
|
uint8 descIndexOf(uint8 soundNumber);
|
2007-08-12 11:08:44 +00:00
|
|
|
SoundDescResource *findSound(uint8 soundNumber);
|
|
|
|
void removeSounds();
|
|
|
|
void restoreSounds();
|
2007-09-16 04:06:49 +00:00
|
|
|
void fadeOut();
|
2007-10-28 03:32:13 +00:00
|
|
|
void pause() { _paused = true; }
|
|
|
|
void resume() { _paused = false; }
|
2010-07-21 20:12:35 +00:00
|
|
|
bool getPaused() const { return _paused; }
|
|
|
|
bool hasNativeMT32() const { return _nativeMT32; }
|
|
|
|
bool isRoland() const { return _isRoland; }
|
|
|
|
uint musicVolume() const { return _musicVolume; }
|
|
|
|
uint sfxVolume() const { return _sfxVolume; }
|
2007-08-12 11:08:44 +00:00
|
|
|
|
|
|
|
// The following methods implement the external sound player module
|
2011-05-25 15:17:11 +00:00
|
|
|
void musicInterface_Initialize();
|
2008-03-19 10:37:33 +00:00
|
|
|
void musicInterface_Play(uint8 soundNumber, uint8 channelNumber, uint8 numChannels = 4);
|
2007-08-12 11:08:44 +00:00
|
|
|
void musicInterface_Stop(uint8 soundNumber);
|
|
|
|
bool musicInterface_CheckPlaying(uint8 soundNumber);
|
|
|
|
void musicInterface_SetVolume(uint8 channelNum, uint8 volume);
|
|
|
|
void musicInterface_KillAll();
|
|
|
|
void musicInterface_ContinuePlaying();
|
|
|
|
void musicInterface_TrashReverb();
|
2007-06-22 12:30:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Lure
|
|
|
|
|
|
|
|
#define Sound (::Lure::SoundManager::instance())
|
|
|
|
|
|
|
|
#endif
|