aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/include/aud_supp.h
blob: a5819ff116e2ff96041618a55ccb08bddd491853 (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
/*
 * PARSEC HEADER: aud_supp.h
 */

#ifndef _AUD_SUPP_H_
#define _AUD_SUPP_H_


// sample-channel relation (holds id once sample is fetched by name) ----------
//
struct sample_channel_info_s {

	const char*	samplename;
	const char*	fallbacksample;
	int		sampleid;
	int		channel;
	int		interruptold;
};


// macro to fetch a wave for sample x -----------------------------------------
//
#define AUD_FETCHSAMPLE(x)	\
\
	audiowave_t fetch_wave = NULL; \
	sampleinfo_s* fetch_pSampleInfo; \
	SoundParams_s fetch_params; \
	memset( &fetch_params, 0, sizeof( fetch_params ) ); \
	static int sampleid = -1; \
	if ( sampleid == -1 ) { \
		fetch_pSampleInfo = AUD_FetchSampleByName((x),&sampleid); \
	} else { \
		fetch_pSampleInfo = AUD_FetchSampleById(sampleid); \
	} \
	if(fetch_pSampleInfo != NULL) { \
		fetch_wave = (audiowave_t)fetch_pSampleInfo->samplepointer; \
		fetch_params.volume = ( fetch_pSampleInfo->volume == -1 ) ? \
								AUD_MAX_VOLUME : fetch_pSampleInfo->volume; \
		fetch_params.flags = SOUNDPARAMS_VOLUME; \
	}


// macro to fetch a wave for sample x store id in y ---------------------------
//
#define AUD_FETCHSAMPLE_EX(x,y)	\
\
	audiowave_t fetch_wave = NULL; \
	sampleinfo_s* fetch_pSampleInfo; \
	SoundParams_s fetch_params; \
	memset( &fetch_params, 0, sizeof( fetch_params ) ); \
	if ( (y) == -1 ) { \
		fetch_pSampleInfo = AUD_FetchSampleByName((x),&(y)); \
	} else { \
		fetch_pSampleInfo = AUD_FetchSampleById(y); \
	} \
	if(fetch_pSampleInfo != NULL) { \
		fetch_wave = (audiowave_t)fetch_pSampleInfo->samplepointer; \
		fetch_params.volume = ( fetch_pSampleInfo->volume == -1 ) ? \
								AUD_MAX_VOLUME : fetch_pSampleInfo->volume; \
		fetch_params.flags = SOUNDPARAMS_VOLUME; \
	}


// macro to fetch a wave for sample x, fallback to sample y -------------------
//
#define AUD_FETCHSAMPLE_FALLBACK(x,y)	\
\
	audiowave_t fetch_wave = NULL; \
	sampleinfo_s* fetch_pSampleInfo; \
	SoundParams_s fetch_params; \
	memset( &fetch_params, 0, sizeof( fetch_params ) ); \
	static int sampleid = -1; \
	if ( sampleid == -1 ) { \
		fetch_pSampleInfo = AUD_FetchSampleByName( (x) ,&sampleid); \
		if(fetch_pSampleInfo == NULL) { \
			fetch_pSampleInfo = AUD_FetchSampleByName( (y) ,&sampleid); \
		} \
	} else { \
		fetch_pSampleInfo = AUD_FetchSampleById(sampleid); \
	} \
	if(fetch_pSampleInfo != NULL) { \
		fetch_wave = (audiowave_t)fetch_pSampleInfo->samplepointer; \
		fetch_params.volume = ( fetch_pSampleInfo->volume == -1 ) ? \
								AUD_MAX_VOLUME : fetch_pSampleInfo->volume; \
		fetch_params.flags = SOUNDPARAMS_VOLUME; \
	}


// macro to fetch a wave for sample x, fallback to sample z, store id in y ----
//
#define AUD_FETCHSAMPLE_FALLBACK_EX(x,y,z)	\
\
	audiowave_t fetch_wave = NULL; \
	sampleinfo_s* fetch_pSampleInfo; \
	SoundParams_s fetch_params; \
	memset( &fetch_params, 0, sizeof( fetch_params ) ); \
	if ( (y) == -1 ) { \
		fetch_pSampleInfo = AUD_FetchSampleByName( (x) ,&(y)); \
		if(fetch_pSampleInfo == NULL) { \
			fetch_pSampleInfo = AUD_FetchSampleByName( (z) ,&(y)); \
		} \
	} else { \
		fetch_pSampleInfo = AUD_FetchSampleById((y)); \
	} \
	if(fetch_pSampleInfo != NULL) { \
		fetch_wave = (audiowave_t)fetch_pSampleInfo->samplepointer; \
		fetch_params.volume = ( fetch_pSampleInfo->volume == -1 ) ? \
								AUD_MAX_VOLUME : fetch_pSampleInfo->volume; \
		fetch_params.flags = SOUNDPARAMS_VOLUME; \
	}


// encapsulate global audio disabling -----------------------------------------
//
#define DISABLE_AUDIO_FUNCTIONS		(!Op_SoundEffects)
#define DISABLE_MUSIC_FUNCTIONS		(!Op_Music)


// external functions ---------------------------------------------------------
//
sampleinfo_s*	AUD_FetchSampleByName( const char *name, int *id );
sampleinfo_s*	AUD_FetchSampleById( int id );
int				AUD_SetSampleVolume( int id, int volume );
int				AUD_PlaySampleOnChannel( sample_channel_info_s *info );


#endif // _AUD_SUPP_H_