[17] | 1 | /* -*- mode: C; tab-width:8; c-basic-offset:8 -*- |
---|
| 2 | * vi:set ts=8: |
---|
| 3 | * |
---|
| 4 | * al_main.h |
---|
| 5 | * |
---|
| 6 | * Miscellanous prototypes, macros and definitions |
---|
| 7 | */ |
---|
| 8 | #ifndef _AL_MAIN_H_ |
---|
| 9 | #define _AL_MAIN_H_ |
---|
| 10 | |
---|
| 11 | #include "al_siteconfig.h" |
---|
| 12 | |
---|
| 13 | #include <AL/al.h> |
---|
| 14 | |
---|
| 15 | #include "alc/alc_context.h" |
---|
| 16 | |
---|
| 17 | /* |
---|
| 18 | * _alLockPrintf is used for debugging purposes. If DEBUG_LOCK is defined, |
---|
| 19 | * calls to _alLockPrintf generate a print to stderr. If not, these calls are |
---|
| 20 | * optimized away. |
---|
| 21 | */ |
---|
| 22 | #ifndef DEBUG_LOCK |
---|
| 23 | #define _alLockPrintf(x, f, l) |
---|
| 24 | #else |
---|
| 25 | int _alLockPrintf( const char *str, const char *fn, int line ); |
---|
| 26 | #endif /* DEBUG_LOCK */ |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * evaluates to the depth of the passed audioconvert format, in bits. |
---|
| 30 | */ |
---|
| 31 | #define _al_ACformatbits(fmt) (fmt & 0x00FF) |
---|
| 32 | |
---|
| 33 | /* |
---|
| 34 | * These macros are make calls to the associated regular-library str calls, |
---|
| 35 | * but cast their arguments to const char * before doing so. This is to aid |
---|
| 36 | * the manipulate of const ALubyte * strings. |
---|
| 37 | */ |
---|
| 38 | #define ustrcmp(s1, s2) strcmp((const char *) s1, (const char *) s2) |
---|
| 39 | #define ustrncmp(s1, s2, n) strncmp((const char *) s1, \ |
---|
| 40 | (const char *) s2, \ |
---|
| 41 | n) |
---|
| 42 | #define ustrncpy(s1, s2, n) strncpy((char *) s1, \ |
---|
| 43 | (const char *) s2, \ |
---|
| 44 | n) |
---|
| 45 | |
---|
| 46 | /* |
---|
| 47 | * Like memcpy, but copies to dst + offset instead of to dst. |
---|
| 48 | */ |
---|
| 49 | #define offset_memcpy(d,o,s,l) memcpy(((char *)d) + o, s, l) |
---|
| 50 | |
---|
| 51 | /* |
---|
| 52 | * Like memcpy, but copies from src + offset instead of from src. |
---|
| 53 | */ |
---|
| 54 | #define memcpy_offset(d,s,o,l) memcpy(d, (char *) s + o, l) |
---|
| 55 | |
---|
| 56 | /* |
---|
| 57 | * If DEBUG_STUB is defined, _alStub prints out a warning message. If not, no |
---|
| 58 | * action is taken. |
---|
| 59 | * |
---|
| 60 | */ |
---|
| 61 | #ifdef DEBUG_STUB |
---|
| 62 | void _alStub( const char *str ); |
---|
| 63 | #else |
---|
| 64 | #define _alStub( s ) |
---|
| 65 | #endif /* DEBUG_STUB */ |
---|
| 66 | |
---|
| 67 | /* |
---|
| 68 | * Does misc. initialization for the library. |
---|
| 69 | */ |
---|
| 70 | ALboolean _alInit( void ); |
---|
| 71 | |
---|
| 72 | /* |
---|
| 73 | * Deallocates the data structures created by _alInit. |
---|
| 74 | */ |
---|
| 75 | void _alExit( void ); |
---|
| 76 | |
---|
| 77 | /* |
---|
| 78 | * Returns the openal format that has the number of channels channels and the |
---|
| 79 | * bit depth bits. |
---|
| 80 | */ |
---|
| 81 | ALenum _al_AL2FMT( ALuint channels, ALuint bits ); |
---|
| 82 | |
---|
| 83 | /* |
---|
| 84 | * Returns the openal format equivilant to the audioconvert format acformat, |
---|
| 85 | * with the number of channels specified by channels. |
---|
| 86 | */ |
---|
| 87 | ALenum _al_AC2ALFMT( ALuint acformat, ALuint channels ); |
---|
| 88 | |
---|
| 89 | /* |
---|
| 90 | * Returns the equivilant (sort of) audioconvert format specified by alfmt. |
---|
| 91 | * audioconvert formats do not have channel information, so this should be |
---|
| 92 | * combined with _alGetChannelsFromFormat. |
---|
| 93 | */ |
---|
| 94 | ALushort _al_AL2ACFMT( ALenum alfmt ); |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | * evaluates to the number of channels in an openal format. |
---|
| 98 | */ |
---|
| 99 | ALubyte _alGetChannelsFromFormat(ALenum alformat); |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Returns the number of bits per sample for the given format. |
---|
| 103 | */ |
---|
| 104 | ALbyte _alGetBitsFromFormat( ALenum format ); |
---|
| 105 | |
---|
| 106 | /* |
---|
| 107 | * Returns the openal format that is identical to format, but with sufficient |
---|
| 108 | * channel width to accomedate new_channel_num channels. |
---|
| 109 | */ |
---|
| 110 | ALenum _al_formatscale( ALenum format, ALuint new_channel_num ); |
---|
| 111 | |
---|
| 112 | /* |
---|
| 113 | * Returns the number of byte necessary to contain samples worth of data, if |
---|
| 114 | * the data undergoes a conversion from ffreq to tfreq in the sampling-rate |
---|
| 115 | * and from ffmt to tfmt in terms of format. |
---|
| 116 | */ |
---|
| 117 | ALuint _al_PCMRatioify( ALuint ffreq, ALuint tfreq, |
---|
| 118 | ALenum ffmt, ALenum tfmt, |
---|
| 119 | ALuint samples ); |
---|
| 120 | |
---|
| 121 | /* |
---|
| 122 | * Returns AL_TRUE if format is an openal format specifying raw pcm data, |
---|
| 123 | * AL_FALSE otherwise. |
---|
| 124 | */ |
---|
| 125 | ALboolean _al_RAWFORMAT( ALenum format ); |
---|
| 126 | |
---|
| 127 | /* |
---|
| 128 | * Multiplies each ALshort in bpt (len bytes long) by sa, clamped above |
---|
| 129 | * by 32767 and below by -32768. Only appropriate for 0.0 <= sa <= 1.0. |
---|
| 130 | */ |
---|
| 131 | void _alFloatMul( ALshort *bpt, ALfloat sa, ALuint len ); |
---|
| 132 | |
---|
| 133 | /* |
---|
| 134 | * Starts the mixer thread. |
---|
| 135 | */ |
---|
| 136 | void _alStartMixerThread( void ); |
---|
| 137 | |
---|
| 138 | /* |
---|
| 139 | * Waits for the mixer thread to die. This call does not kill the mixer |
---|
| 140 | * thread, it just hangs around poking the body. |
---|
| 141 | */ |
---|
| 142 | void _alWaitForMixerThreadToDie( void ); |
---|
| 143 | |
---|
| 144 | /* |
---|
| 145 | * Copies srcs[0..nc-1][0..(len/2)-1] to |
---|
| 146 | * dsts[0..nc-1][offset/2..((offset + len)/2)-1]. |
---|
| 147 | */ |
---|
| 148 | void _alBuffersAppend( void **dsts, void **srcs, int len, int offset, int nc ); |
---|
| 149 | |
---|
| 150 | /* |
---|
| 151 | * slurp file named by fname to into *buffer, mallocing memory. |
---|
| 152 | */ |
---|
| 153 | int _alSlurp( const char *fname, void **buffer ); |
---|
| 154 | |
---|
| 155 | /* |
---|
| 156 | * sleep for n microseconds |
---|
| 157 | */ |
---|
| 158 | void _alMicroSleep( unsigned int n ); |
---|
| 159 | |
---|
| 160 | /* |
---|
| 161 | * Convert degree argument to radians |
---|
| 162 | */ |
---|
| 163 | ALfloat _alDegreeToRadian( ALfloat degree ); |
---|
| 164 | |
---|
| 165 | /* |
---|
| 166 | * Functions for verifying values fall between min and max, |
---|
| 167 | * inclusive. |
---|
| 168 | */ |
---|
| 169 | |
---|
| 170 | /* |
---|
| 171 | * Returns AL_TRUE if val is between min and max, inclusive. |
---|
| 172 | */ |
---|
| 173 | ALboolean _alCheckRangef( ALfloat val, ALfloat min, ALfloat max ); |
---|
| 174 | |
---|
| 175 | /* |
---|
| 176 | * Returns AL_TRUE if val is either AL_TRUE or AL_FALSE. |
---|
| 177 | */ |
---|
| 178 | ALboolean _alCheckRangeb( ALboolean val ); |
---|
| 179 | |
---|
| 180 | /* |
---|
| 181 | * Returns true if fv1 == { 0.0f, 0.0f, 0.0f } |
---|
| 182 | */ |
---|
| 183 | ALboolean _alIsZeroVector( const ALfloat *fv1 ); |
---|
| 184 | |
---|
| 185 | /* |
---|
| 186 | * the buffers that sources are split into in SplitSources and |
---|
| 187 | * Collapsed from in CollapseSources. Filters work on these |
---|
| 188 | * intermediate buffers, each of which contains one mono channel of |
---|
| 189 | * the source data. |
---|
| 190 | * |
---|
| 191 | * f_buffers contain PCM data |
---|
| 192 | */ |
---|
| 193 | |
---|
| 194 | extern _alDecodeScratch f_buffers; |
---|
| 195 | |
---|
| 196 | /* |
---|
| 197 | * Returns smallest power of two large that meets or exceeds num. |
---|
| 198 | */ |
---|
| 199 | ALuint _alSmallestPowerOfTwo( ALuint num ); |
---|
| 200 | |
---|
| 201 | /* |
---|
| 202 | * Returns AL_TRUE if v is a finite, non NaN value, AL_FALSE otherwise. |
---|
| 203 | */ |
---|
| 204 | ALboolean _alIsFinite( ALfloat v ); |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | /* |
---|
| 208 | * Returns smallest power of two that meets or exceeds num. |
---|
| 209 | */ |
---|
| 210 | ALuint _alSpot( ALuint num ); |
---|
| 211 | |
---|
| 212 | #endif |
---|