2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:47:41 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef D_SOUND_H
|
|
|
|
#define D_SOUND_H
|
|
|
|
|
2003-09-25 06:11:07 +00:00
|
|
|
#include "sound/audiostream.h"
|
2003-08-02 02:31:36 +00:00
|
|
|
#include "sound/mixer.h"
|
2003-12-24 00:25:18 +00:00
|
|
|
|
|
|
|
class RateConverter;
|
2003-07-29 12:34:46 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-10-04 08:31:20 +00:00
|
|
|
// Max number of sound fx
|
|
|
|
#define MAXFX 16
|
|
|
|
#define MAXMUS 2
|
|
|
|
|
2003-09-10 12:43:54 +00:00
|
|
|
extern void sword2_sound_handler(void *refCon);
|
2003-08-30 18:06:08 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
struct FxHandle {
|
2003-09-21 14:26:25 +00:00
|
|
|
int32 _id;
|
|
|
|
bool _paused;
|
|
|
|
int8 _volume;
|
|
|
|
uint16 _rate;
|
|
|
|
uint32 _flags;
|
|
|
|
uint16 *_buf;
|
|
|
|
int32 _bufSize;
|
|
|
|
PlayingSoundHandle _handle;
|
2003-12-28 15:08:12 +00:00
|
|
|
};
|
2003-09-21 14:26:25 +00:00
|
|
|
|
2004-01-03 14:10:13 +00:00
|
|
|
class MusicHandle : public AudioStream {
|
2003-09-25 06:11:07 +00:00
|
|
|
public:
|
Ok, I'm stupid.
The initial sample is, indeed, two bytes, just like the rest of them, but
it really, really helps if you read it from the correct position in the
file.
After fixing that, it turned out that my changing of signedness of the
sample was also wrong. Funny how those two bugs almost cancelled each other
out. Almost.
I've made a few other changes as well, but they're just to clean things up
a bit. The credits music works for me, and I've played the game up to
arriving in Quaramonte, with no obvious music-related problems.
svn-id: r10412
2003-09-26 06:26:18 +00:00
|
|
|
bool _firstTime;
|
2003-09-21 14:26:25 +00:00
|
|
|
bool _streaming;
|
|
|
|
bool _paused;
|
|
|
|
bool _looping;
|
2003-09-25 06:11:07 +00:00
|
|
|
int32 _fading;
|
Ok, I'm stupid.
The initial sample is, indeed, two bytes, just like the rest of them, but
it really, really helps if you read it from the correct position in the
file.
After fixing that, it turned out that my changing of signedness of the
sample was also wrong. Funny how those two bugs almost cancelled each other
out. Almost.
I've made a few other changes as well, but they're just to clean things up
a bit. The credits music works for me, and I've played the game up to
arriving in Quaramonte, with no obvious music-related problems.
svn-id: r10412
2003-09-26 06:26:18 +00:00
|
|
|
int32 _fileStart;
|
2003-09-21 14:26:25 +00:00
|
|
|
int32 _filePos;
|
|
|
|
int32 _fileEnd;
|
2003-09-25 10:02:52 +00:00
|
|
|
uint16 _lastSample;
|
2003-09-25 06:11:07 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
bool isStereo(void) const { return false; }
|
|
|
|
int getRate(void) const { return 22050; }
|
2003-09-25 06:11:07 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
void fadeDown(void);
|
|
|
|
void fadeUp(void);
|
|
|
|
int32 play(const char *filename, uint32 musicId, bool looping);
|
|
|
|
void stop(void);
|
2004-01-03 19:12:23 +00:00
|
|
|
int readBuffer(int16 *buffer, const int numSamples);
|
2004-01-03 11:24:39 +00:00
|
|
|
bool endOfData(void) const;
|
2003-12-19 01:30:19 +00:00
|
|
|
// This stream never 'ends'
|
2004-01-03 11:24:39 +00:00
|
|
|
bool endOfStream(void) const { return false; }
|
2003-09-25 06:11:07 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
MusicHandle() : _firstTime(false), _streaming(false), _paused(false),
|
|
|
|
_looping(false), _fading(0), _fileStart(0),
|
|
|
|
_filePos(0), _fileEnd(0), _lastSample(0) {}
|
2003-09-25 06:11:07 +00:00
|
|
|
};
|
2003-09-21 14:26:25 +00:00
|
|
|
|
2003-10-04 01:09:29 +00:00
|
|
|
class Sound {
|
2003-10-01 06:36:25 +00:00
|
|
|
private:
|
2003-11-16 14:18:29 +00:00
|
|
|
Sword2Engine *_vm;
|
2003-10-01 06:36:25 +00:00
|
|
|
|
|
|
|
OSystem::MutexRef _mutex;
|
|
|
|
|
2003-11-02 10:12:08 +00:00
|
|
|
int32 _panTable[33];
|
2004-01-03 11:24:39 +00:00
|
|
|
bool _soundOn;
|
2003-11-01 18:12:04 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
static int32 _musicVolTable[17];
|
2003-10-04 01:09:29 +00:00
|
|
|
MusicHandle _music[MAXMUS + 1];
|
2004-01-03 11:24:39 +00:00
|
|
|
char *savedMusicFilename;
|
|
|
|
RateConverter *_converter;
|
|
|
|
bool _musicMuted;
|
|
|
|
uint8 _musicVol;
|
2003-10-01 06:36:25 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
void updateCompSampleStreaming(int16 *data, uint len);
|
|
|
|
int32 dipMusic(void);
|
|
|
|
|
|
|
|
PlayingSoundHandle _soundHandleSpeech;
|
2003-10-29 07:53:05 +00:00
|
|
|
bool _speechStatus;
|
|
|
|
bool _speechPaused;
|
|
|
|
bool _speechMuted;
|
2003-10-01 06:36:25 +00:00
|
|
|
uint8 _speechVol;
|
2003-07-29 12:34:46 +00:00
|
|
|
|
2004-01-03 11:24:39 +00:00
|
|
|
FxHandle _fx[MAXFX];
|
|
|
|
bool _fxPaused;
|
|
|
|
bool _fxMuted;
|
|
|
|
uint8 _fxVol;
|
2003-10-01 06:36:25 +00:00
|
|
|
|
|
|
|
int32 getFxIndex(int32 id);
|
2004-01-03 11:24:39 +00:00
|
|
|
void stopFxHandle(int i);
|
2003-12-31 14:05:53 +00:00
|
|
|
|
2003-10-01 06:36:25 +00:00
|
|
|
public:
|
2003-11-16 14:18:29 +00:00
|
|
|
Sound(Sword2Engine *vm);
|
2003-10-04 01:09:29 +00:00
|
|
|
~Sound();
|
2004-01-03 11:24:39 +00:00
|
|
|
|
2003-10-01 06:36:25 +00:00
|
|
|
void fxServer(int16 *data, uint len);
|
2004-01-03 11:24:39 +00:00
|
|
|
void buildPanTable(bool reverse);
|
|
|
|
|
|
|
|
void muteMusic(bool mute);
|
|
|
|
bool isMusicMute(void);
|
|
|
|
void setMusicVolume(uint8 vol);
|
|
|
|
uint8 getMusicVolume(void);
|
2003-10-01 06:36:25 +00:00
|
|
|
void pauseMusic(void);
|
|
|
|
void unpauseMusic(void);
|
2004-01-03 11:24:39 +00:00
|
|
|
void stopMusic(void);
|
|
|
|
void saveMusicState(void);
|
|
|
|
void restoreMusicState(void);
|
2003-10-01 06:36:25 +00:00
|
|
|
void playLeadOut(uint8 *leadOut);
|
2004-01-03 11:24:39 +00:00
|
|
|
int32 streamCompMusic(const char *filename, uint32 musicId, bool looping);
|
|
|
|
int32 musicTimeRemaining(void);
|
|
|
|
|
|
|
|
void muteSpeech(bool mute);
|
2003-10-29 07:53:05 +00:00
|
|
|
bool isSpeechMute(void);
|
2003-10-01 06:36:25 +00:00
|
|
|
void setSpeechVolume(uint8 vol);
|
2004-01-03 11:24:39 +00:00
|
|
|
uint8 getSpeechVolume(void);
|
|
|
|
void pauseSpeech(void);
|
|
|
|
void unpauseSpeech(void);
|
|
|
|
int32 stopSpeech(void);
|
|
|
|
int32 getSpeechStatus(void);
|
|
|
|
int32 amISpeaking(void);
|
|
|
|
uint32 preFetchCompSpeech(const char *filename, uint32 speechid, uint16 **buf);
|
|
|
|
int32 playCompSpeech(const char *filename, uint32 speechid, uint8 vol, int8 pan);
|
|
|
|
|
2003-10-29 07:53:05 +00:00
|
|
|
void muteFx(bool mute);
|
2004-01-03 11:24:39 +00:00
|
|
|
bool isFxMute(void);
|
|
|
|
uint8 getFxVolume(void);
|
|
|
|
void setFxVolume(uint8 vol);
|
2003-10-01 06:36:25 +00:00
|
|
|
int32 setFxIdVolumePan(int32 id, uint8 vol, int8 pan);
|
|
|
|
int32 setFxIdVolume(int32 id, uint8 vol);
|
2004-01-03 11:24:39 +00:00
|
|
|
void pauseFx(void);
|
|
|
|
void pauseFxForSequence(void);
|
|
|
|
void unpauseFx(void);
|
|
|
|
bool isFxPlaying(int32 id);
|
|
|
|
int32 openFx(int32 id, uint8 *data);
|
|
|
|
int32 closeFx(int32 id);
|
|
|
|
int32 playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type);
|
|
|
|
void clearAllFx(void);
|
2003-10-01 06:36:25 +00:00
|
|
|
};
|
2003-07-28 01:47:41 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
} // End of namespace Sword2
|
|
|
|
|
2003-07-28 01:47:41 +00:00
|
|
|
#endif
|