aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sfx/core.h
blob: 2c327e1f6d1e0c2b300a6eb7aa04d64a8d1c9592 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* 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.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

/* Sound engine */
#ifndef SCI_SFX_CORE_H
#define SCI_SFX_CORE_H

#include "common/error.h"
#include "sci/sfx/songlib.h"
#include "sci/resource.h"

namespace Sci {

class SongIterator;
struct fade_params_t;

#define SFX_TICKS_PER_SEC 60 /* MIDI ticks per second */


#define SFX_STATE_FLAG_MULTIPLAY (1 << 0) /* More than one song playable
** simultaneously ? */
#define SFX_STATE_FLAG_NOSOUND	 (1 << 1) /* Completely disable sound playing */


#define SFX_DEBUG_SONGS		(1 << 0) /* Debug song changes */
#define SFX_DEBUG_CUES		(1 << 1) /* Debug cues, loops, and
** song completions */

class SfxState {
public:	// FIXME, make private
	SongIterator *_it; /**< The song iterator at the heart of things */
	uint _flags; /**< SFX_STATE_FLAG_* */
	songlib_t _songlib; /**< Song library */
	song_t *_song; /**< Active song, or start of active song chain */
	bool _suspended; /**< Whether we are suspended */
	uint _debug; /**< Debug flags */
	ResourceSync *_soundSync; /**< Used by kDoSync for speech syncing in CD talkie games */
	AudioResource *_audioResource; /**< Used for audio resources in CD talkie games */

public:
	/***********/
	/* General */
	/***********/

	/* Initializes the sound engine
	** Parameters: (ResourceManager *) resmgr: Resource manager for initialization
	**             (int) flags: SFX_STATE_FLAG_*
	*/
	void sfx_init(ResourceManager *resmgr, int flags);

	/** Deinitializes the sound subsystem. */
	void sfx_exit();

	/* Suspends/unsuspends the sound sybsystem
	** Parameters: (int) suspend: Whether to suspend (non-null) or to unsuspend
	*/
	void sfx_suspend(bool suspend);

	/* Polls the sound server for cues etc.
	** Returns   : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
	**             (song_handle_t) *handle: The affected handle
	**             (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP)
	*/
	int sfx_poll(song_handle_t *handle, int *cue);

	/* Polls the sound server for cues etc.
	** Parameters: (song_handle_t) handle: The handle to poll
	** Returns   : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
	**             (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP)
	*/
	int sfx_poll_specific(song_handle_t handle, int *cue);

	/* Determines the current global volume settings
	** Returns   : (int) The global volume, between 0 (silent) and 127 (max. volume)
	*/
	int sfx_get_volume();

	/* Determines the current global volume settings
	** Parameters: (int) volume: The new global volume, between 0 and 127 (see above)
	*/
	void sfx_set_volume(int volume);

	/* Stops all songs currently playing, purges song library
	*/
	void sfx_all_stop();


	/*****************/
	/*  Song basics  */
	/*****************/

	/* Adds a song to the internal sound library
	** Parameters: (SongIterator *) it: The iterator describing the song
	**             (int) priority: Initial song priority (higher <-> more important)
	**             (song_handle_t) handle: The handle to associate with the song
	** Returns   : (int) 0 on success, nonzero on error
	*/
	int sfx_add_song(SongIterator *it, int priority, song_handle_t handle, int resnum);


	/* Deletes a song and its associated song iterator from the song queue
	** Parameters: (song_handle_t) handle: The song to remove
	*/
	void sfx_remove_song(song_handle_t handle);


	/**********************/
	/* Song modifications */
	/**********************/


	/* Sets the song status, i.e. whether it is playing, suspended, or stopped.
	** Parameters: (song_handle_t) handle: Handle of the song to modify
	**             (int) status: The song status the song should assume
	** WAITING and PLAYING are set implicitly and essentially describe the same state
	** as far as this function is concerned.
	*/
	void sfx_song_set_status(song_handle_t handle, int status);

	/* Sets the new song priority
	** Parameters: (song_handle_t) handle: The handle to modify
	**             (int) priority: The priority to set
	*/
	void sfx_song_renice(song_handle_t handle, int priority);

	/* Sets the number of loops for the specified song
	** Parameters: (song_handle_t) handle: The song handle to reference
	**             (int) loops: Number of loops to set
	*/
	void sfx_song_set_loops(song_handle_t handle, int loops);

	/* Sets the number of loops for the specified song
	** Parameters: (song_handle_t) handle: The song handle to reference
	**             (int) hold: Number of loops to setn
	*/
	void sfx_song_set_hold(song_handle_t handle, int hold);

	/* Instructs a song to be faded out
	** Parameters: (song_handle_t) handle: The song handle to reference
	**             (fade_params_t *) fade_setup: The precise fade-out configuration to use
	*/
	void sfx_song_set_fade(song_handle_t handle, fade_params_t *fade_setup);


	// Previously undocumented:
	Common::Error sfx_send_midi(song_handle_t handle, int channel,
		int command, int arg1, int arg2);

protected:
	void freezeTime();
	void thawTime();

	bool isPlaying(song_t *song);
	void setSongStatus(song_t *song, int status);
	void updateSingleSong();
	void updateMultiSong();
	void update();
};


} // End of namespace Sci

#endif // SCI_SFX_CORE_H