aboutsummaryrefslogtreecommitdiff
path: root/sword2/driver/d_sound.h
blob: ddea6f41f7d03b2f504ecddd85f7356ee02f721c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Copyright (C) 1994-2004 Revolution Software Ltd
 *
 * 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

#include "common/file.h"
#include "sound/audiostream.h"
#include "sound/mixer.h"

namespace Sword2 {

class MusicInputStream;

// Max number of sound fx
#define MAXFX 16
#define MAXMUS 2

enum {
	kCLUMode = 1,
	kMP3Mode,
	kVorbisMode,
	kFlacMode
};

extern void sword2_sound_handler(void *refCon);

struct WavInfo {
	uint8 channels;
	uint16 rate;
	uint32 samples;
	uint8 *data;
};

struct FxHandle {
	int32 _id;
	bool _paused;
	int8 _volume;
	PlayingSoundHandle _handle;
};

class Sound : public AudioStream {
private:
	Sword2Engine *_vm;

	OSystem::MutexRef _mutex;

	int32 _panTable[33];
	bool _soundOn;

	static int32 _musicVolTable[17];
	MusicInputStream *_music[MAXMUS];
	int16 *_mixBuffer;
	int _mixBufferLen;

	bool _musicPaused;
	bool _musicMuted;
	uint8 _musicVol;

	PlayingSoundHandle _soundHandleSpeech;
	bool _speechPaused;
	bool _speechMuted;
	uint8 _speechVol;

	FxHandle _fx[MAXFX];
	bool _fxPaused;
	bool _fxMuted;
	uint8 _fxVol;

	int32 getFxIndex(int32 id);
	void stopFxHandle(int i);

public:
	Sound(Sword2Engine *vm);
	~Sound();

	// AudioStream API

	int readBuffer(int16 *buffer, const int numSamples);
	bool isStereo() const;
	bool endOfData() const;
	int getRate() const;

	// End of AudioStream API

	void buildPanTable(bool reverse);

	bool getWavInfo(uint8 *data, WavInfo *wavInfo);

	void muteMusic(bool mute);
	bool isMusicMute(void);
	void setMusicVolume(uint8 vol);
	uint8 getMusicVolume(void);
	void pauseMusic(void);
	void unpauseMusic(void);
	void stopMusic(void);
	void waitForLeadOut(void);
	int32 streamCompMusic(uint32 musicId, bool looping);
	int32 musicTimeRemaining(void);

	void muteSpeech(bool mute);
	bool isSpeechMute(void);
	void setSpeechVolume(uint8 vol);
	uint8 getSpeechVolume(void);
	void pauseSpeech(void);
	void unpauseSpeech(void);
	int32 stopSpeech(void);
	int32 getSpeechStatus(void);
	int32 amISpeaking(void);
	uint32 preFetchCompSpeech(uint32 speechid, uint16 **buf);
	int32 playCompSpeech(uint32 speechid, uint8 vol, int8 pan);

	void muteFx(bool mute);
	bool isFxMute(void);
	uint8 getFxVolume(void);
	void setFxVolume(uint8 vol);
	int32 setFxIdVolumePan(int32 id, uint8 vol, int8 pan);
	int32 setFxIdVolume(int32 id, uint8 vol);
	void pauseFx(void);
	void pauseFxForSequence(void);
	void unpauseFx(void);
	bool isFxPlaying(int32 id);
	int32 playFx(int32 id, uint8 *data, uint8 vol, int8 pan, uint8 type);
	int32 stopFx(int32 id);
	void clearAllFx(void);
};

} // End of namespace Sword2

#endif