s_sound.h 9.12 KB
Newer Older
Alam Ed Arias committed
1 2 3 4
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
James R. committed
5
// Copyright (C) 1999-2020 by Sonic Team Junior.
Alam Ed Arias committed
6 7 8 9 10 11 12 13 14 15 16
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file  s_sound.h
/// \brief The not so system specific sound interface

#ifndef __S_SOUND__
#define __S_SOUND__

17
#include "i_sound.h" // musictype_t
Alam Ed Arias committed
18 19 20 21 22
#include "sounds.h"
#include "m_fixed.h"
#include "command.h"
#include "tables.h" // angle_t

SteelT committed
23 24
#ifdef HAVE_OPENMPT
#include "libopenmpt/libopenmpt.h"
25
extern openmpt_module *openmpt_mhandle;
SteelT committed
26 27
#endif

Alam Ed Arias committed
28 29 30 31
// mask used to indicate sound origin is player item pickup
#define PICKUP_SOUND 0x8000

extern consvar_t stereoreverse;
toaster committed
32
extern consvar_t cv_soundvolume, cv_closedcaptioning, cv_digmusicvolume, cv_midimusicvolume;
Alam Ed Arias committed
33
extern consvar_t cv_numChannels;
34

35
extern consvar_t cv_resetmusic;
36 37
extern consvar_t cv_resetmusicbyheader;

38 39
extern consvar_t cv_1upsound;

40 41 42 43 44 45
#define RESETMUSIC (!modeattacking && \
	(cv_resetmusicbyheader.value ? \
		(mapheaderinfo[gamemap-1]->musforcereset != -1 ? mapheaderinfo[gamemap-1]->musforcereset : cv_resetmusic.value) \
		: cv_resetmusic.value) \
	)

SteelT committed
46 47 48
extern consvar_t cv_gamedigimusic;
extern consvar_t cv_gamemidimusic;
extern consvar_t cv_gamesounds;
kaysrishaq committed
49 50
extern consvar_t cv_musicpref;

51 52 53
extern consvar_t cv_playmusicifunfocused;
extern consvar_t cv_playsoundsifunfocused;

54 55 56
#ifdef HAVE_OPENMPT
extern consvar_t cv_modfilter;
#endif
Alam Ed Arias committed
57

58 59 60 61 62 63
#ifdef HAVE_MIXERX
extern consvar_t cv_midiplayer;
extern consvar_t cv_midisoundfontpath;
extern consvar_t cv_miditimiditypath;
#endif

Alam Ed Arias committed
64 65 66 67 68 69 70 71 72 73 74
#ifdef SNDSERV
extern consvar_t sndserver_cmd, sndserver_arg;
#endif
#ifdef MUSSERV
extern consvar_t musserver_cmd, musserver_arg;
#endif

extern CV_PossibleValue_t soundvolume_cons_t[];
//part of i_cdmus.c
extern consvar_t cd_volume, cdUpdate;

Alam Ed Arias committed
75
#if defined (macintosh) && !defined (HAVE_SDL)
Alam Ed Arias committed
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
typedef enum
{
	music_normal,
	playlist_random,
	playlist_normal
} playmode_t;

extern consvar_t play_mode;
#endif

typedef enum
{
	SF_TOTALLYSINGLE =  1, // Only play one of these sounds at a time...GLOBALLY
	SF_NOMULTIPLESOUND =  2, // Like SF_NOINTERRUPT, but doesnt care what the origin is
	SF_OUTSIDESOUND  =  4, // Volume is adjusted depending on how far away you are from 'outside'
	SF_X4AWAYSOUND   =  8, // Hear it from 4x the distance away
	SF_X8AWAYSOUND   = 16, // Hear it from 8x the distance away
	SF_NOINTERRUPT   = 32, // Only play this sound if it isn't already playing on the origin
	SF_X2AWAYSOUND   = 64, // Hear it from 2x the distance away
} soundflags_t;

typedef struct {
	fixed_t x, y, z;
	angle_t angle;
} listener_t;

toaster committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
typedef struct
{
	// sound information (if null, channel avail.)
	sfxinfo_t *sfxinfo;

	// origin of sound
	const void *origin;

	// handle of the sound being played
	INT32 handle;

} channel_t;

typedef struct {
	channel_t *c;
	sfxinfo_t *s;
118 119
	UINT16 t;
	UINT8 b;
toaster committed
120 121
} caption_t;

122
#define NUMCAPTIONS 8
toaster committed
123 124
#define MAXCAPTIONTICS (2*TICRATE)
#define CAPTIONFADETICS 20
125 126

extern caption_t closedcaptions[NUMCAPTIONS];
127
void S_StartCaption(sfxenum_t sfx_id, INT32 cnum, UINT16 lifespan);
128
void S_ResetCaptions(void);
toaster committed
129

Alam Ed Arias committed
130 131 132 133 134
// register sound vars and commands at game startup
void S_RegisterSoundStuff(void);

//
// Initializes sound stuff, including volume
Marco Z committed
135
// Sets channels, SFX, allocates channel buffer, sets S_sfx lookup.
Alam Ed Arias committed
136
//
Marco Z committed
137
void S_InitSfxChannels(INT32 sfxVolume);
Alam Ed Arias committed
138 139 140 141 142 143 144

//
// Per level startup code.
// Kills playing sounds at start of level, determines music if any, changes music.
//
void S_StopSounds(void);
void S_ClearSfx(void);
145 146
void S_StartEx(boolean reset);
#define S_Start() S_StartEx(false)
Alam Ed Arias committed
147 148 149 150 151 152

//
// Basically a W_GetNumForName that adds "ds" at the beginning of the string. Returns a lumpnum.
//
lumpnum_t S_GetSfxLumpNum(sfxinfo_t *sfx);

153 154 155 156 157 158
//
// Sound Status
//

boolean S_SoundDisabled(void);

Alam Ed Arias committed
159 160 161 162 163 164 165 166 167 168 169
//
// Start sound for thing at <origin> using <sound_id> from sounds.h
//
void S_StartSound(const void *origin, sfxenum_t sound_id);

// Will start a sound at a given volume.
void S_StartSoundAtVolume(const void *origin, sfxenum_t sound_id, INT32 volume);

// Stop sound for thing at <origin>
void S_StopSound(void *origin);

170 171 172 173
//
// Music Status
//

Marco Z committed
174 175 176 177 178
boolean S_DigMusicDisabled(void);
boolean S_MIDIMusicDisabled(void);
boolean S_MusicDisabled(void);
boolean S_MusicPlaying(void);
boolean S_MusicPaused(void);
179
boolean S_MusicNotInFocus(void);
180
musictype_t S_MusicType(void);
181
const char *S_MusicName(void);
Marco Z committed
182 183 184
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi);
#define S_DigExists(a) S_MusicExists(a, false, true)
#define S_MIDIExists(a) S_MusicExists(a, true, false)
Alam Ed Arias committed
185

kaysrishaq committed
186 187
// Returns whether the preferred format a (true = MIDI, false = Digital)
// exists and is enabled for musicname b
kaysrishaq committed
188
#define S_PrefAvailable(a, b) (a ? \
kaysrishaq committed
189 190 191
	(!S_MIDIMusicDisabled() && S_MIDIExists(b)) : \
	(!S_DigMusicDisabled() && S_DigExists(b)))

192
//
193
// Music Effects
194
//
195

Alam Ed Arias committed
196 197 198
// Set Speed of Music
boolean S_SpeedMusic(float speed);

199
// Music definitions
toaster committed
200 201 202 203 204 205
typedef struct musicdef_s
{
	char name[7];
	char title[32];
	char alttitle[64];
	char authors[256];
206 207 208 209 210 211 212
	//char usage[256]; -- probably never going to be relevant to vanilla
	/*
	the trouble here is that kart combines what we call "title"
	and "authors" into one string. we need to split it for sound
	test reasons. they might split it later like we did, but...
	*/
	//char source[256];
toaster committed
213 214 215 216
	UINT8 soundtestpage;
	INT16 soundtestcond; // +ve for map, -ve for conditionset, 0 for already here
	tic_t stoppingtics;
	fixed_t bpm;
James R. committed
217
	UINT32 loop_ms;/* override LOOPPOINT/LOOPMS */
toaster committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	boolean allowed; // question marks or listenable on sound test?
	struct musicdef_s *next;
} musicdef_t;

extern musicdef_t soundtestsfx;
extern musicdef_t *musicdefstart;
extern musicdef_t **soundtestdefs;
extern INT32 numsoundtestdefs;
extern UINT8 soundtestpage;

void S_LoadMusicDefs(UINT16 wadnum);
void S_InitMusicDefs(void);

boolean S_PrepareSoundTest(void);

233
//
234 235 236
// Music Seeking
//

237 238 239
// Get Length of Music
UINT32 S_GetMusicLength(void);

240 241 242 243 244 245
// Set LoopPoint of Music
boolean S_SetMusicLoopPoint(UINT32 looppoint);

// Get LoopPoint of Music
UINT32 S_GetMusicLoopPoint(void);

246
// Set Position of Music
247
boolean S_SetMusicPosition(UINT32 position);
248 249

// Get Position of Music
250
UINT32 S_GetMusicPosition(void);
251

252 253 254 255 256 257 258 259 260 261 262 263 264
//
// Music Stacking (Jingles)
//

typedef struct musicstack_s
{
	char musname[7];
	UINT16 musflags;
	boolean looping;
	UINT32 position;
	tic_t tic;
	UINT16 status;
	lumpnum_t mlumpnum;
265
	boolean noposition; // force music stack resuming from zero (like music_stack_noposition)
266 267 268 269 270

    struct musicstack_s *prev;
    struct musicstack_s *next;
} musicstack_t;

271 272 273 274
extern char music_stack_nextmusname[7];
extern boolean music_stack_noposition;
extern UINT32 music_stack_fadeout;
extern UINT32 music_stack_fadein;
275 276 277 278 279 280

void S_SetStackAdjustmentStart(void);
void S_AdjustMusicStackTics(void);
void S_RetainMusic(const char *mname, UINT16 mflags, boolean looping, UINT32 position, UINT16 status);
boolean S_RecallMusic(UINT16 status, boolean fromfirst);

281 282
//
// Music Playback
283 284
//

285 286 287
// Start music track, arbitrary, given its name, and set whether looping
// note: music flags 12 bits for tracknum (gme, other formats with more than one track)
//       13-15 aren't used yet
Alam Ed Arias committed
288
//       and the last bit we ignore (internal game flag for resetting music on reload)
289 290 291
void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 position, UINT32 prefadems, UINT32 fadeinms);
#define S_ChangeMusicInternal(a,b) S_ChangeMusicEx(a,0,b,0,0,0)
#define S_ChangeMusic(a,b,c) S_ChangeMusicEx(a,b,c,0,0,0)
Alam Ed Arias committed
292 293 294 295 296

// Stops the music.
void S_StopMusic(void);

// Stop and resume music, during game PAUSE.
297 298
void S_PauseAudio(void);
void S_ResumeAudio(void);
Alam Ed Arias committed
299

300 301 302
//
// Music Fading
//
303

304
void S_SetInternalMusicVolume(INT32 volume);
305
void S_StopFadingMusic(void);
306 307
boolean S_FadeMusicFromVolume(UINT8 target_volume, INT16 source_volume, UINT32 ms);
#define S_FadeMusic(a, b) S_FadeMusicFromVolume(a, -1, b)
308
#define S_FadeInChangeMusic(a,b,c,d) S_ChangeMusicEx(a,b,c,0,0,d)
309
boolean S_FadeOutStopMusic(UINT32 ms);
310

Alam Ed Arias committed
311 312 313 314
//
// Updates music & sounds
//
void S_UpdateSounds(void);
315
void S_UpdateClosedCaptions(void);
Alam Ed Arias committed
316

Alam Ed Arias committed
317
FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2);
Alam Ed Arias committed
318 319

void S_SetSfxVolume(INT32 volume);
320 321 322 323
void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume);
#define S_SetDigMusicVolume(a) S_SetMusicVolume(a,-1)
#define S_SetMIDIMusicVolume(a) S_SetMusicVolume(-1,a)
#define S_InitMusicVolume() S_SetMusicVolume(-1,-1)
Alam Ed Arias committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338

INT32 S_OriginPlaying(void *origin);
INT32 S_IdPlaying(sfxenum_t id);
INT32 S_SoundPlaying(void *origin, sfxenum_t id);

void S_StartSoundName(void *mo, const  char *soundname);

void S_StopSoundByID(void *origin, sfxenum_t sfx_id);
void S_StopSoundByNum(sfxenum_t sfxnum);

#ifndef HW3SOUND
#define S_StartAttackSound S_StartSound
#define S_StartScreamSound S_StartSound
#endif

Inuyasha committed
339 340 341
#ifdef MUSICSLOT_COMPATIBILITY
// For compatibility with code/scripts relying on older versions
// This is a list of all the "special" slot names and their associated numbers
342
extern const char *compat_special_music_slots[16];
Inuyasha committed
343 344
#endif

Alam Ed Arias committed
345
#endif