2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-08-15 18:04:01 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2005-01-09 16:06:29 +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
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-01-09 16:06:29 +00:00
|
|
|
*
|
2008-05-09 13:33:31 +00:00
|
|
|
* LGPL License
|
2006-08-15 18:04:01 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
2006-02-09 12:19:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-01-09 16:06:29 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-02-20 17:33:54 +00:00
|
|
|
#ifndef KYRA_SOUND_H
|
|
|
|
#define KYRA_SOUND_H
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
#include "kyra/kyra_v1.h"
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
#include "common/scummsys.h"
|
2006-05-17 18:07:02 +00:00
|
|
|
#include "common/file.h"
|
2006-07-26 22:24:33 +00:00
|
|
|
#include "common/mutex.h"
|
2008-04-07 17:56:04 +00:00
|
|
|
#include "common/ptr.h"
|
2006-07-26 22:24:33 +00:00
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
#include "sound/midiparser.h"
|
2006-02-17 15:37:25 +00:00
|
|
|
#include "sound/mixer.h"
|
2007-03-24 00:04:08 +00:00
|
|
|
#include "sound/softsynth/ym2612.h"
|
2006-07-26 22:24:33 +00:00
|
|
|
|
2006-01-13 23:06:04 +00:00
|
|
|
namespace Audio {
|
2006-04-29 22:33:31 +00:00
|
|
|
class AudioStream;
|
2006-01-13 23:06:04 +00:00
|
|
|
} // end of namespace Audio
|
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
namespace Kyra {
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-12-16 18:48:43 +00:00
|
|
|
/**
|
2007-11-03 23:32:15 +00:00
|
|
|
* Analog audio output device API for Kyrandia games.
|
2008-05-09 13:33:31 +00:00
|
|
|
* It contains functionality to play music tracks,
|
2007-11-03 23:32:15 +00:00
|
|
|
* sound effects and voices.
|
|
|
|
*/
|
2006-01-13 23:06:04 +00:00
|
|
|
class Sound {
|
|
|
|
public:
|
2008-05-11 23:16:50 +00:00
|
|
|
Sound(KyraEngine_v1 *vm, Audio::Mixer *mixer);
|
2006-02-27 22:39:55 +00:00
|
|
|
virtual ~Sound();
|
|
|
|
|
2008-04-06 13:32:41 +00:00
|
|
|
enum kType {
|
|
|
|
kAdlib,
|
|
|
|
kMidiMT32,
|
|
|
|
kMidiGM,
|
2008-06-26 19:42:59 +00:00
|
|
|
kTowns,
|
|
|
|
kPC98
|
2008-04-06 13:32:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual kType getMusicType() const = 0;
|
|
|
|
virtual kType getSfxType() const { return getMusicType(); }
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Initializes the output device.
|
|
|
|
*
|
|
|
|
* @return true on success, else false
|
|
|
|
*/
|
2006-02-27 22:39:55 +00:00
|
|
|
virtual bool init() = 0;
|
2007-11-03 23:32:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the device, this is needed for some devices.
|
|
|
|
*/
|
2006-03-21 17:17:24 +00:00
|
|
|
virtual void process() {}
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
2008-05-09 13:33:31 +00:00
|
|
|
* Updates internal volume settings according to ConfigManager.
|
2007-11-03 23:32:15 +00:00
|
|
|
*/
|
2008-04-04 18:09:19 +00:00
|
|
|
virtual void updateVolumeSettings() {}
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Sets the soundfiles the output device will use
|
|
|
|
* when playing a track and/or sound effect.
|
|
|
|
*
|
|
|
|
* @param list soundfile list
|
|
|
|
*/
|
2008-01-03 14:42:49 +00:00
|
|
|
virtual void setSoundList(const AudioDataStruct *list) { _soundDataList = list; }
|
2007-12-16 18:48:43 +00:00
|
|
|
|
2008-04-06 14:11:43 +00:00
|
|
|
/**
|
2008-05-09 13:33:31 +00:00
|
|
|
* Checks if a given sound file is present.
|
2008-04-06 14:11:43 +00:00
|
|
|
*
|
|
|
|
* @param track track number
|
|
|
|
* @return true if available, false otherwise
|
|
|
|
*/
|
2008-04-06 14:13:14 +00:00
|
|
|
virtual bool hasSoundFile(uint file) { return (fileListEntry(file) != 0); }
|
2008-04-06 14:11:43 +00:00
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Load a specifc sound file for use of
|
|
|
|
* playing music and sound effects.
|
|
|
|
*/
|
2007-01-29 18:15:14 +00:00
|
|
|
virtual void loadSoundFile(uint file) = 0;
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2008-08-02 15:05:19 +00:00
|
|
|
/**
|
|
|
|
* Load a sound file for playing music
|
2008-11-30 02:47:20 +00:00
|
|
|
* (and somtimes sound effects) from.
|
2008-08-02 15:05:19 +00:00
|
|
|
*/
|
|
|
|
virtual void loadSoundFile(Common::String file) = 0;
|
|
|
|
|
2008-11-30 02:47:20 +00:00
|
|
|
/**
|
|
|
|
* Load a sound file for playing sound
|
|
|
|
* effects from.
|
|
|
|
*/
|
|
|
|
virtual void loadSfxFile(Common::String file) { }
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Plays the specified track.
|
|
|
|
*
|
|
|
|
* @param track track number
|
|
|
|
*/
|
2006-03-12 14:22:27 +00:00
|
|
|
virtual void playTrack(uint8 track) = 0;
|
2007-11-03 23:32:15 +00:00
|
|
|
|
|
|
|
/**
|
2008-05-09 13:33:31 +00:00
|
|
|
* Stop playback of the current track.
|
2007-11-03 23:32:15 +00:00
|
|
|
*/
|
2006-01-13 23:06:04 +00:00
|
|
|
virtual void haltTrack() = 0;
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
2008-05-09 13:33:31 +00:00
|
|
|
* Plays the specified sound effect.
|
2007-11-03 23:32:15 +00:00
|
|
|
*
|
|
|
|
* @param track sound effect id
|
|
|
|
*/
|
2006-01-13 23:06:04 +00:00
|
|
|
virtual void playSoundEffect(uint8 track) = 0;
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2008-11-30 15:15:14 +00:00
|
|
|
/**
|
|
|
|
* Stop playback of all sfx tracks.
|
|
|
|
*/
|
|
|
|
virtual void stopAllSoundEffects() {}
|
|
|
|
|
2008-04-06 14:58:02 +00:00
|
|
|
/**
|
2008-05-09 13:33:31 +00:00
|
|
|
* Checks if the sound driver plays any sound.
|
2008-04-06 14:58:02 +00:00
|
|
|
*
|
|
|
|
* @return true if playing, false otherwise
|
|
|
|
*/
|
|
|
|
virtual bool isPlaying() const { return false; }
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Starts fading out the volume.
|
|
|
|
*
|
|
|
|
* This keeps fading out the output until
|
|
|
|
* it is silenced, but does not change
|
|
|
|
* the volume set by setVolume! It will
|
|
|
|
* automatically reset the volume when
|
|
|
|
* playing a new track or sound effect.
|
|
|
|
*/
|
2006-01-13 23:06:04 +00:00
|
|
|
virtual void beginFadeOut() = 0;
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2007-03-24 00:04:08 +00:00
|
|
|
void enableMusic(int enable) { _musicEnabled = enable; }
|
|
|
|
int musicEnabled() const { return _musicEnabled; }
|
2006-06-02 22:57:02 +00:00
|
|
|
void enableSFX(bool enable) { _sfxEnabled = enable; }
|
|
|
|
bool sfxEnabled() const { return _sfxEnabled; }
|
|
|
|
|
2008-03-21 16:18:27 +00:00
|
|
|
virtual bool voiceFileIsPresent(const char *file);
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Plays the specified voice file.
|
|
|
|
*
|
|
|
|
* Also before starting to play the
|
|
|
|
* specified voice file, it stops the
|
|
|
|
* current voice.
|
|
|
|
*
|
|
|
|
* TODO: add support for queueing voice
|
|
|
|
* files
|
|
|
|
*
|
2009-02-01 20:35:51 +00:00
|
|
|
* @param file file to be played
|
|
|
|
* @param volume volume of the voice file
|
|
|
|
* @param isSfx marks file as sfx instead of voice
|
2008-05-24 22:47:08 +00:00
|
|
|
* @return playtime of the voice file (-1 marks unknown playtime)
|
2007-11-03 23:32:15 +00:00
|
|
|
*/
|
2009-02-01 20:35:51 +00:00
|
|
|
virtual int32 voicePlay(const char *file, uint8 volume = 255, bool isSfx = false);
|
2007-11-03 23:32:15 +00:00
|
|
|
|
2009-02-01 19:27:01 +00:00
|
|
|
/**
|
|
|
|
* Queues the specified voice files in an AppendableAudioStream
|
|
|
|
* and plays them.
|
|
|
|
*
|
|
|
|
* @param fileList: files to be played
|
|
|
|
*/
|
|
|
|
virtual void voicePlayFromList(Common::List<const char*> fileList);
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Checks if a voice is being played.
|
|
|
|
*
|
|
|
|
* @return true when playing, else false
|
|
|
|
*/
|
2008-03-21 16:18:27 +00:00
|
|
|
bool voiceIsPlaying(const char *file = 0);
|
2007-11-03 23:32:15 +00:00
|
|
|
|
2008-05-24 22:47:08 +00:00
|
|
|
/**
|
|
|
|
* Checks how long a voice has been playing
|
|
|
|
*
|
|
|
|
* @return time in milliseconds
|
|
|
|
*/
|
|
|
|
uint32 voicePlayedTime(const char *file);
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Stops playback of the current voice.
|
|
|
|
*/
|
2008-03-21 16:18:27 +00:00
|
|
|
void voiceStop(const char *file = 0);
|
2006-02-27 22:39:55 +00:00
|
|
|
protected:
|
2008-01-11 00:33:45 +00:00
|
|
|
const char *fileListEntry(int file) const { return (_soundDataList != 0 && file >= 0 && file < _soundDataList->_fileListLen) ? _soundDataList->_fileList[file] : ""; }
|
2008-01-11 00:35:39 +00:00
|
|
|
const void *cdaData() const { return _soundDataList != 0 ? _soundDataList->_cdaTracks : 0; }
|
2008-05-08 21:23:14 +00:00
|
|
|
int cdaTrackNum() const { return _soundDataList != 0 ? _soundDataList->_cdaNumTracks : 0; }
|
2008-01-03 14:42:49 +00:00
|
|
|
|
2008-02-17 02:06:04 +00:00
|
|
|
enum {
|
2008-03-21 16:18:27 +00:00
|
|
|
kNumChannelHandles = 4
|
2008-02-17 02:06:04 +00:00
|
|
|
};
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-03-21 16:21:27 +00:00
|
|
|
struct SoundChannel {
|
|
|
|
Common::String file;
|
|
|
|
Audio::SoundHandle channelHandle;
|
|
|
|
};
|
|
|
|
SoundChannel _soundChannels[kNumChannelHandles];
|
2008-02-17 02:06:04 +00:00
|
|
|
|
2007-03-24 00:04:08 +00:00
|
|
|
int _musicEnabled;
|
2006-06-02 22:57:02 +00:00
|
|
|
bool _sfxEnabled;
|
|
|
|
|
2008-05-11 23:16:50 +00:00
|
|
|
KyraEngine_v1 *_vm;
|
2006-02-27 22:39:55 +00:00
|
|
|
Audio::Mixer *_mixer;
|
2007-11-03 23:32:15 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
private:
|
2008-01-03 14:42:49 +00:00
|
|
|
const AudioDataStruct *_soundDataList;
|
2008-03-21 16:18:27 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
struct SpeechCodecs {
|
|
|
|
const char *fileext;
|
2007-07-15 18:29:05 +00:00
|
|
|
Audio::AudioStream *(*streamFunc)(
|
|
|
|
Common::SeekableReadStream *stream,
|
|
|
|
bool disposeAfterUse,
|
|
|
|
uint32 startTime,
|
|
|
|
uint32 duration,
|
|
|
|
uint numLoops);
|
2006-02-27 22:39:55 +00:00
|
|
|
};
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2008-06-03 18:12:21 +00:00
|
|
|
static const SpeechCodecs _supportedCodecs[];
|
2006-02-27 22:39:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AdlibDriver;
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* AdLib implementation of the sound output device.
|
|
|
|
*
|
|
|
|
* It uses a special sound file format special to
|
|
|
|
* Dune II, Kyrandia 1 and 2. While Dune II and
|
|
|
|
* Kyrandia 1 are using exact the same format, the
|
|
|
|
* one of Kyrandia 2 slightly differs.
|
2007-12-16 18:48:43 +00:00
|
|
|
*
|
2007-11-03 23:32:15 +00:00
|
|
|
* See AdlibDriver for more information.
|
|
|
|
* @see AdlibDriver
|
|
|
|
*/
|
2006-02-27 22:39:55 +00:00
|
|
|
class SoundAdlibPC : public Sound {
|
|
|
|
public:
|
2008-05-11 23:16:50 +00:00
|
|
|
SoundAdlibPC(KyraEngine_v1 *vm, Audio::Mixer *mixer);
|
2006-02-27 22:39:55 +00:00
|
|
|
~SoundAdlibPC();
|
|
|
|
|
2008-04-06 13:32:41 +00:00
|
|
|
kType getMusicType() const { return kAdlib; }
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
bool init();
|
2006-03-21 17:17:24 +00:00
|
|
|
void process();
|
2006-02-27 22:39:55 +00:00
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
void loadSoundFile(uint file);
|
2008-08-02 15:05:19 +00:00
|
|
|
void loadSoundFile(Common::String file);
|
2007-03-24 00:04:08 +00:00
|
|
|
|
2006-03-12 14:22:27 +00:00
|
|
|
void playTrack(uint8 track);
|
2006-02-27 22:39:55 +00:00
|
|
|
void haltTrack();
|
2008-04-06 13:57:28 +00:00
|
|
|
bool isPlaying();
|
2007-03-24 00:04:08 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void playSoundEffect(uint8 track);
|
2007-03-24 00:04:08 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
void beginFadeOut();
|
|
|
|
private:
|
2008-08-02 15:05:19 +00:00
|
|
|
void internalLoadFile(Common::String file);
|
|
|
|
|
2006-06-02 22:57:02 +00:00
|
|
|
void play(uint8 track);
|
|
|
|
|
2006-03-09 20:50:19 +00:00
|
|
|
void unk1();
|
|
|
|
void unk2();
|
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
AdlibDriver *_driver;
|
|
|
|
|
2007-02-16 16:57:59 +00:00
|
|
|
bool _v2;
|
|
|
|
uint8 _trackEntries[500];
|
2006-02-27 22:39:55 +00:00
|
|
|
uint8 *_soundDataPtr;
|
|
|
|
int _sfxPlayingSound;
|
2008-08-02 15:05:19 +00:00
|
|
|
|
|
|
|
Common::String _soundFileLoaded;
|
2006-02-27 22:39:55 +00:00
|
|
|
|
2006-03-16 23:22:23 +00:00
|
|
|
uint8 _sfxPriority;
|
2006-02-27 22:39:55 +00:00
|
|
|
uint8 _sfxFourthByteOfSong;
|
2006-03-21 17:17:24 +00:00
|
|
|
|
|
|
|
int _numSoundTriggers;
|
|
|
|
const int *_soundTriggers;
|
|
|
|
|
|
|
|
static const int _kyra1NumSoundTriggers;
|
|
|
|
static const int _kyra1SoundTriggers[];
|
2006-01-13 23:06:04 +00:00
|
|
|
};
|
|
|
|
|
2008-11-30 01:53:32 +00:00
|
|
|
class MidiOutput;
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* MIDI output device.
|
|
|
|
*
|
|
|
|
* This device supports both MT-32 MIDI, as used in
|
|
|
|
* Kyrandia 1 and 2, and GM MIDI, as used in Kyrandia 2.
|
|
|
|
*/
|
2008-11-30 01:53:32 +00:00
|
|
|
class SoundMidiPC : public Sound {
|
2005-09-11 14:35:34 +00:00
|
|
|
public:
|
2008-05-11 23:16:50 +00:00
|
|
|
SoundMidiPC(KyraEngine_v1 *vm, Audio::Mixer *mixer, MidiDriver *driver);
|
2006-02-27 22:39:55 +00:00
|
|
|
~SoundMidiPC();
|
|
|
|
|
2008-11-30 01:53:32 +00:00
|
|
|
kType getMusicType() const { return _nativeMT32 ? kMidiMT32 : kMidiGM; }
|
2008-04-06 13:32:41 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
bool init();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
void updateVolumeSettings();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
void loadSoundFile(uint file);
|
2008-08-02 15:05:19 +00:00
|
|
|
void loadSoundFile(Common::String file);
|
2008-11-30 02:47:20 +00:00
|
|
|
void loadSfxFile(Common::String file);
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2006-03-12 14:22:27 +00:00
|
|
|
void playTrack(uint8 track);
|
2006-03-12 15:38:59 +00:00
|
|
|
void haltTrack();
|
2008-11-30 02:38:08 +00:00
|
|
|
bool isPlaying();
|
2006-03-21 17:17:24 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
void playSoundEffect(uint8 track);
|
2008-11-30 15:15:14 +00:00
|
|
|
void stopAllSoundEffects();
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
void beginFadeOut();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-12-26 01:09:46 +00:00
|
|
|
void hasNativeMT32(bool nativeMT32);
|
2006-02-27 22:39:55 +00:00
|
|
|
private:
|
2005-09-11 14:35:34 +00:00
|
|
|
static void onTimer(void *data);
|
|
|
|
|
2008-04-07 17:56:04 +00:00
|
|
|
// Our channel handling
|
2008-12-11 13:54:18 +00:00
|
|
|
int _musicVolume, _sfxVolume;
|
2008-04-07 17:56:04 +00:00
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
uint32 _fadeStartTime;
|
|
|
|
bool _fadeMusicOut;
|
2008-04-07 17:56:04 +00:00
|
|
|
|
|
|
|
// Midi file related
|
2008-12-07 13:12:09 +00:00
|
|
|
Common::String _mFileName, _sFileName;
|
2008-11-30 01:53:32 +00:00
|
|
|
byte *_musicFile, *_sfxFile;
|
2006-07-26 22:24:33 +00:00
|
|
|
|
2008-11-30 01:53:32 +00:00
|
|
|
MidiParser *_music;
|
|
|
|
MidiParser *_sfx[3];
|
2008-04-07 17:56:04 +00:00
|
|
|
|
|
|
|
// misc
|
|
|
|
bool _nativeMT32;
|
|
|
|
bool _useC55;
|
|
|
|
MidiDriver *_driver;
|
2008-11-30 01:53:32 +00:00
|
|
|
MidiOutput *_output;
|
|
|
|
|
2006-07-26 22:24:33 +00:00
|
|
|
Common::Mutex _mutex;
|
2005-09-11 14:35:34 +00:00
|
|
|
};
|
2006-03-28 15:15:36 +00:00
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
class Towns_EuphonyDriver;
|
|
|
|
class TownsPC98_OpnDriver;
|
|
|
|
|
2007-03-24 00:04:08 +00:00
|
|
|
class SoundTowns : public MidiDriver, public Sound {
|
2007-01-25 17:43:48 +00:00
|
|
|
public:
|
2008-05-11 23:16:50 +00:00
|
|
|
SoundTowns(KyraEngine_v1 *vm, Audio::Mixer *mixer);
|
2007-01-29 18:15:14 +00:00
|
|
|
~SoundTowns();
|
2007-01-25 17:43:48 +00:00
|
|
|
|
2008-04-06 13:32:41 +00:00
|
|
|
kType getMusicType() const { return kTowns; }
|
|
|
|
|
2007-01-25 17:43:48 +00:00
|
|
|
bool init();
|
|
|
|
void process();
|
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
void loadSoundFile(uint file);
|
2008-08-02 15:05:19 +00:00
|
|
|
void loadSoundFile(Common::String) {}
|
2007-01-25 17:43:48 +00:00
|
|
|
|
|
|
|
void playTrack(uint8 track);
|
|
|
|
void haltTrack();
|
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
void playSoundEffect(uint8);
|
2007-01-25 17:43:48 +00:00
|
|
|
|
2007-03-24 00:04:08 +00:00
|
|
|
void beginFadeOut();
|
|
|
|
|
|
|
|
//MidiDriver interface implementation
|
|
|
|
int open();
|
|
|
|
void close();
|
|
|
|
void send(uint32 b);
|
|
|
|
void metaEvent(byte type, byte *data, uint16 length) {}
|
|
|
|
|
|
|
|
void setTimerCallback(void *timerParam, void (*timerProc)(void *)) { }
|
|
|
|
uint32 getBaseTempo(void);
|
|
|
|
|
|
|
|
//Channel allocation functions
|
|
|
|
MidiChannel *allocateChannel() { return 0; }
|
|
|
|
MidiChannel *getPercussionChannel() { return 0; }
|
|
|
|
|
2008-08-16 12:38:37 +00:00
|
|
|
static float calculatePhaseStep(int8 semiTone, int8 semiToneRootkey,
|
2007-03-24 00:04:08 +00:00
|
|
|
uint32 sampleRate, uint32 outputRate, int32 pitchWheel);
|
2008-06-26 19:42:59 +00:00
|
|
|
|
2007-01-25 17:43:48 +00:00
|
|
|
private:
|
2007-03-24 00:04:08 +00:00
|
|
|
bool loadInstruments();
|
|
|
|
void playEuphonyTrack(uint32 offset, int loop);
|
|
|
|
|
|
|
|
static void onTimer(void *data);
|
2007-01-29 18:15:14 +00:00
|
|
|
|
2007-01-25 17:43:48 +00:00
|
|
|
int _lastTrack;
|
2007-01-29 18:15:14 +00:00
|
|
|
Audio::AudioStream *_currentSFX;
|
|
|
|
Audio::SoundHandle _sfxHandle;
|
2007-03-24 00:04:08 +00:00
|
|
|
|
2007-01-29 18:15:14 +00:00
|
|
|
uint _sfxFileIndex;
|
|
|
|
uint8 *_sfxFileData;
|
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
Towns_EuphonyDriver * _driver;
|
2007-03-24 00:04:08 +00:00
|
|
|
MidiParser * _parser;
|
|
|
|
|
|
|
|
Common::Mutex _mutex;
|
|
|
|
|
2008-01-10 23:25:19 +00:00
|
|
|
const uint8 *_sfxBTTable;
|
2007-03-24 00:04:08 +00:00
|
|
|
const uint8 *_sfxWDTable;
|
2007-01-25 17:43:48 +00:00
|
|
|
};
|
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
class SoundPC98 : public Sound {
|
2007-12-16 18:48:43 +00:00
|
|
|
public:
|
2008-06-26 19:42:59 +00:00
|
|
|
SoundPC98(KyraEngine_v1 *vm, Audio::Mixer *mixer);
|
|
|
|
~SoundPC98();
|
2007-12-16 18:48:43 +00:00
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
virtual kType getMusicType() const { return kPC98; }
|
|
|
|
|
|
|
|
bool init();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
void process() {}
|
|
|
|
void loadSoundFile(uint file) {}
|
2008-08-02 15:05:19 +00:00
|
|
|
void loadSoundFile(Common::String) {}
|
2008-06-26 19:42:59 +00:00
|
|
|
|
|
|
|
void playTrack(uint8 track);
|
|
|
|
void haltTrack();
|
|
|
|
void beginFadeOut();
|
|
|
|
|
2009-02-01 20:35:51 +00:00
|
|
|
int32 voicePlay(const char *file, uint8 volume = 255, bool isSfx = false) { return -1; }
|
2008-06-26 19:42:59 +00:00
|
|
|
void playSoundEffect(uint8);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int _lastTrack;
|
|
|
|
uint8 *_musicTrackData;
|
|
|
|
uint8 *_sfxTrackData;
|
|
|
|
TownsPC98_OpnDriver *_driver;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SoundTownsPC98_v2 : public Sound {
|
|
|
|
public:
|
|
|
|
SoundTownsPC98_v2(KyraEngine_v1 *vm, Audio::Mixer *mixer);
|
|
|
|
~SoundTownsPC98_v2();
|
|
|
|
|
|
|
|
kType getMusicType() const { return _vm->gameFlags().platform == Common::kPlatformFMTowns ? kTowns : kPC98; }
|
2008-04-06 13:32:41 +00:00
|
|
|
|
2007-12-16 18:48:43 +00:00
|
|
|
bool init();
|
|
|
|
void process();
|
|
|
|
|
|
|
|
void loadSoundFile(uint file) {}
|
2008-08-16 12:38:37 +00:00
|
|
|
void loadSoundFile(Common::String file);
|
2007-12-16 18:48:43 +00:00
|
|
|
|
|
|
|
void playTrack(uint8 track);
|
|
|
|
void haltTrack();
|
|
|
|
void beginFadeOut();
|
|
|
|
|
2009-02-01 20:35:51 +00:00
|
|
|
int32 voicePlay(const char *file, uint8 volume = 255, bool isSfx = false);
|
2008-06-29 15:25:45 +00:00
|
|
|
void playSoundEffect(uint8 track);
|
2007-12-16 18:48:43 +00:00
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
protected:
|
2007-12-16 18:48:43 +00:00
|
|
|
Audio::AudioStream *_currentSFX;
|
2008-06-26 19:42:59 +00:00
|
|
|
int _lastTrack;
|
2008-06-29 15:25:45 +00:00
|
|
|
bool _useFmSfx;
|
|
|
|
|
2008-06-26 19:42:59 +00:00
|
|
|
uint8 *_musicTrackData;
|
2008-08-16 12:38:37 +00:00
|
|
|
uint8 *_sfxTrackData;
|
2009-01-01 15:06:43 +00:00
|
|
|
TownsPC98_OpnDriver *_driver;
|
2007-12-16 18:48:43 +00:00
|
|
|
};
|
|
|
|
|
2006-03-28 15:15:36 +00:00
|
|
|
class MixedSoundDriver : public Sound {
|
|
|
|
public:
|
2008-05-11 23:16:50 +00:00
|
|
|
MixedSoundDriver(KyraEngine_v1 *vm, Audio::Mixer *mixer, Sound *music, Sound *sfx) : Sound(vm, mixer), _music(music), _sfx(sfx) {}
|
2006-03-28 15:15:36 +00:00
|
|
|
~MixedSoundDriver() { delete _music; delete _sfx; }
|
|
|
|
|
2008-04-06 13:32:41 +00:00
|
|
|
kType getMusicType() const { return _music->getMusicType(); }
|
|
|
|
kType getSfxType() const { return _sfx->getSfxType(); }
|
|
|
|
|
2007-12-22 23:29:15 +00:00
|
|
|
bool init() { return (_music->init() && _sfx->init()); }
|
2006-03-28 15:15:36 +00:00
|
|
|
void process() { _music->process(); _sfx->process(); }
|
|
|
|
|
2008-04-04 18:09:19 +00:00
|
|
|
void updateVolumeSettings() { _music->updateVolumeSettings(); _sfx->updateVolumeSettings(); }
|
2006-03-28 15:15:36 +00:00
|
|
|
|
2008-01-03 21:57:54 +00:00
|
|
|
void setSoundList(const AudioDataStruct * list) { _music->setSoundList(list); _sfx->setSoundList(list); }
|
2008-04-06 14:13:14 +00:00
|
|
|
bool hasSoundFile(uint file) const { return _music->hasSoundFile(file) && _sfx->hasSoundFile(file); }
|
2007-01-29 18:15:14 +00:00
|
|
|
void loadSoundFile(uint file) { _music->loadSoundFile(file); _sfx->loadSoundFile(file); }
|
2008-08-02 15:05:19 +00:00
|
|
|
void loadSoundFile(Common::String file) { _music->loadSoundFile(file); _sfx->loadSoundFile(file); }
|
2006-03-28 15:15:36 +00:00
|
|
|
|
|
|
|
void playTrack(uint8 track) { _music->playTrack(track); }
|
|
|
|
void haltTrack() { _music->haltTrack(); }
|
2008-04-06 14:58:02 +00:00
|
|
|
bool isPlaying() const { return _music->isPlaying() | _sfx->isPlaying(); }
|
2006-03-28 15:15:36 +00:00
|
|
|
|
|
|
|
void playSoundEffect(uint8 track) { _sfx->playSoundEffect(track); }
|
|
|
|
|
|
|
|
void beginFadeOut() { _music->beginFadeOut(); }
|
|
|
|
private:
|
|
|
|
Sound *_music, *_sfx;
|
|
|
|
};
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
// Digital Audio
|
|
|
|
class AUDStream;
|
2008-06-03 18:12:21 +00:00
|
|
|
class KyraAudioStream;
|
2008-05-11 17:50:13 +00:00
|
|
|
class KyraEngine_MR;
|
2007-11-03 23:32:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Digital audio output device.
|
|
|
|
*
|
|
|
|
* This is just used for Kyrandia 3.
|
|
|
|
*/
|
2006-05-17 18:07:02 +00:00
|
|
|
class SoundDigital {
|
|
|
|
public:
|
2008-05-11 17:50:13 +00:00
|
|
|
SoundDigital(KyraEngine_MR *vm, Audio::Mixer *mixer);
|
2006-05-17 18:07:02 +00:00
|
|
|
~SoundDigital();
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
bool init() { return true; }
|
2007-03-24 00:04:08 +00:00
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Plays a sound.
|
|
|
|
*
|
2008-04-20 14:36:39 +00:00
|
|
|
* @param filename file to be played
|
2008-04-20 14:25:37 +00:00
|
|
|
* @param priority priority of the sound
|
2008-04-17 17:46:39 +00:00
|
|
|
* @param type type
|
2008-04-17 17:57:16 +00:00
|
|
|
* @param volume channel volume
|
2007-11-03 23:32:15 +00:00
|
|
|
* @param loop true if the sound should loop (endlessly)
|
|
|
|
* @param channel tell the sound player to use a specific channel for playback
|
|
|
|
*
|
|
|
|
* @return channel playing the sound
|
|
|
|
*/
|
2008-04-20 22:24:24 +00:00
|
|
|
int playSound(const char *filename, uint8 priority, Audio::Mixer::SoundType type, int volume = 255, bool loop = false, int channel = -1);
|
2007-11-03 23:32:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a given channel is playing a sound.
|
|
|
|
*
|
|
|
|
* @param channel channel number to check
|
|
|
|
* @return true if playing, else false
|
|
|
|
*/
|
2006-05-17 18:07:02 +00:00
|
|
|
bool isPlaying(int channel);
|
2007-11-03 23:32:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the playback of a sound in the given
|
|
|
|
* channel.
|
|
|
|
*
|
|
|
|
* @param channel channel number
|
|
|
|
*/
|
2006-05-17 18:07:02 +00:00
|
|
|
void stopSound(int channel);
|
2007-11-03 23:32:15 +00:00
|
|
|
|
2008-04-14 20:20:51 +00:00
|
|
|
/**
|
2008-05-09 13:33:31 +00:00
|
|
|
* Stops playback of all sounds.
|
2008-04-14 20:20:51 +00:00
|
|
|
*/
|
|
|
|
void stopAllSounds();
|
|
|
|
|
2007-11-03 23:32:15 +00:00
|
|
|
/**
|
|
|
|
* Makes the sound in a given channel
|
|
|
|
* fading out.
|
|
|
|
*
|
|
|
|
* @param channel channel number
|
2008-04-12 23:26:13 +00:00
|
|
|
* @param ticks fadeout time
|
2007-11-03 23:32:15 +00:00
|
|
|
*/
|
2008-04-12 23:26:13 +00:00
|
|
|
void beginFadeOut(int channel, int ticks);
|
2006-05-17 18:07:02 +00:00
|
|
|
private:
|
2008-05-11 17:50:13 +00:00
|
|
|
KyraEngine_MR *_vm;
|
2006-05-17 18:07:02 +00:00
|
|
|
Audio::Mixer *_mixer;
|
|
|
|
|
|
|
|
struct Sound {
|
|
|
|
Audio::SoundHandle handle;
|
2008-04-20 14:36:39 +00:00
|
|
|
|
|
|
|
char filename[16];
|
2008-04-20 14:25:37 +00:00
|
|
|
uint8 priority;
|
2008-06-03 18:12:21 +00:00
|
|
|
KyraAudioStream *stream;
|
2008-04-17 17:49:18 +00:00
|
|
|
} _sounds[4];
|
2008-06-03 18:12:21 +00:00
|
|
|
|
|
|
|
struct AudioCodecs {
|
|
|
|
const char *fileext;
|
|
|
|
Audio::AudioStream *(*streamFunc)(
|
|
|
|
Common::SeekableReadStream *stream,
|
|
|
|
bool disposeAfterUse,
|
|
|
|
uint32 startTime,
|
|
|
|
uint32 duration,
|
|
|
|
uint numLoops);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AudioCodecs _supportedCodecs[];
|
2006-05-17 18:07:02 +00:00
|
|
|
};
|
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
} // end of namespace Kyra
|
|
|
|
|
|
|
|
#endif
|