[17] | 1 | /* -*- mode: C; tab-width:8; c-basic-offset:8 -*- |
---|
| 2 | * vi:set ts=8: |
---|
| 3 | * |
---|
| 4 | * al_buffer.h |
---|
| 5 | * |
---|
| 6 | * Prototypes, macros and definitions related to the creation and |
---|
| 7 | * management of buffers. |
---|
| 8 | * |
---|
| 9 | */ |
---|
| 10 | #ifndef _AL_BUFFER_H_ |
---|
| 11 | #define _AL_BUFFER_H_ |
---|
| 12 | |
---|
| 13 | #include "al_types.h" |
---|
| 14 | |
---|
| 15 | /* |
---|
| 16 | * Initialize data structures common to all buffers. Returns AL_TRUE if |
---|
| 17 | * initialization was successful, AL_FALSE otherwise. |
---|
| 18 | */ |
---|
| 19 | ALboolean _alInitBuffers( void ); |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * Destroys data structures created by _alInitBuffers, and any AL_buffer or |
---|
| 23 | * bpool objects as well. |
---|
| 24 | */ |
---|
| 25 | void _alDestroyBuffers( void ); |
---|
| 26 | |
---|
| 27 | /* |
---|
| 28 | * Non locking version of alIsBuffer. |
---|
| 29 | */ |
---|
| 30 | ALboolean _alIsBuffer( ALuint bid ); |
---|
| 31 | |
---|
| 32 | /* |
---|
| 33 | * Returns a pointer to the AL_buffer object named by id. If id does not name |
---|
| 34 | * a buffer, NULL is returned. |
---|
| 35 | */ |
---|
| 36 | AL_buffer *_alGetBuffer( ALuint id ); |
---|
| 37 | |
---|
| 38 | /* |
---|
| 39 | * Returns a pointer to the AL_buffer object associated with the source named |
---|
| 40 | * by sid from the context named by cid. If sid in cid is not a valid source, |
---|
| 41 | * or is a valid source but does not have its buffer attribute set, NULL is |
---|
| 42 | * returned. |
---|
| 43 | */ |
---|
| 44 | AL_buffer *_alGetBufferFromSid( ALuint cid, ALuint sid ); |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * Buffer State functions |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | /* |
---|
| 52 | * Returns one member of the set AL_UNUSED, AL_PROCESSED, or AL_PENDING. If the |
---|
| 53 | * AL_buffer named by bid is not being used by a playing source, AL_UNUSED is |
---|
| 54 | * returned. If it is being used by a playing source, but is part of a queue |
---|
| 55 | * and is not the current buffer being played, AL_PENDING is returned. |
---|
| 56 | * Otherwise, AL_PROCESSED is returned. |
---|
| 57 | */ |
---|
| 58 | ALenum _alGetBidState( ALuint bid ); |
---|
| 59 | |
---|
| 60 | /* |
---|
| 61 | * Returns one member of the set AL_UNUSED, AL_PROCESSED, or AL_PENDING. If the |
---|
| 62 | * AL_buffer (buffer) is not being used by a playing source, AL_UNUSED is |
---|
| 63 | * returned. If it is being used by a playing source, but is part of a queue |
---|
| 64 | * and is not the current buffer being played, AL_PENDING is returned. |
---|
| 65 | * Otherwise, AL_PROCESSED is returned. |
---|
| 66 | */ |
---|
| 67 | ALenum _alGetBufferState( AL_buffer *buffer ); |
---|
| 68 | |
---|
| 69 | /* |
---|
| 70 | * adds a queue reference to the buffer named by bid. The queue reference |
---|
| 71 | * refers to the source named by sid. |
---|
| 72 | * |
---|
| 73 | * If no current reference is added, and this queue reference is not deleted, |
---|
| 74 | * _alGet{Bid,Buffer}State will return AL_PENDING. |
---|
| 75 | * |
---|
| 76 | */ |
---|
| 77 | void _alBidAddQueueRef( ALuint bid, ALuint sid ); |
---|
| 78 | |
---|
| 79 | /* |
---|
| 80 | * removes a queue reference to the buffer named by bid. The first queue |
---|
| 81 | * reference refering to sid will be removed. |
---|
| 82 | */ |
---|
| 83 | void _alBidRemoveQueueRef( ALuint bid, ALuint sid ); |
---|
| 84 | |
---|
| 85 | /* |
---|
| 86 | * adds a current reference to the buffer named by bid. The reference refers |
---|
| 87 | * to the source named by sid. |
---|
| 88 | * |
---|
| 89 | * If this reference is not removed, _alGet{Bid,Buffer}state will return |
---|
| 90 | * AL_PROCESSED. |
---|
| 91 | */ |
---|
| 92 | void _alBidAddCurrentRef( ALuint bid, ALuint sid ); |
---|
| 93 | |
---|
| 94 | /* |
---|
| 95 | * removes a current reference to the buffer named by bid. The first current |
---|
| 96 | * reference refering to sid will be removed. |
---|
| 97 | */ |
---|
| 98 | void _alBidRemoveCurrentRef( ALuint bid, ALuint sid ); |
---|
| 99 | |
---|
| 100 | /* |
---|
| 101 | * Returns AL_TRUE if the AL_buffer named by bid is valid and is a streaming |
---|
| 102 | * buffer ( created by alGenStreamingBuffer_LOKI ), AL_FALSE otherwise. |
---|
| 103 | */ |
---|
| 104 | ALboolean _alBidIsStreaming( ALuint bid ); |
---|
| 105 | |
---|
| 106 | /* |
---|
| 107 | * Returns AL_TRUE if the AL_buffer named by bid is valid and is a callback |
---|
| 108 | * buffer ( has been used with the call alBufferDataWithCallback ), AL_FALSE |
---|
| 109 | * otherwise. |
---|
| 110 | */ |
---|
| 111 | ALboolean _alBidIsCallback( ALuint bid ); |
---|
| 112 | |
---|
| 113 | /* |
---|
| 114 | * Returns AL_TRUE if the AL_buffer (buffer) is a callback buffer ( has been |
---|
| 115 | * used with the call alBufferDataWithCallback ), AL_FALSE otherwise. |
---|
| 116 | */ |
---|
| 117 | ALboolean _alBufferIsCallback( AL_buffer *buffer ); |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | /* |
---|
| 121 | * Free the orig_buffers of buf. Don't just use free(buf->orig_buffer[n] |
---|
| 122 | * because there are duplicates in there. |
---|
| 123 | */ |
---|
| 124 | void _alBufferFreeOrigBuffers(AL_buffer *buf); |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * Reserves space for num_buffers AL_buffer objects. |
---|
| 128 | */ |
---|
| 129 | void _alNumBufferHint( ALuint num_buffers ); |
---|
| 130 | |
---|
| 131 | /* |
---|
| 132 | * Associates the AL_buffer named by bid with a callback. This is somewhat |
---|
| 133 | * equivilant to calling alBufferData( bid, ... ), except that instead of |
---|
| 134 | * getting all the data at once, whenever the buffer is required to provide |
---|
| 135 | * data, it relies on the callback. |
---|
| 136 | * |
---|
| 137 | * The destroyer callbacks are used to update data structures. They are not |
---|
| 138 | * available publically, and are only used by internal functions ( in alut, |
---|
| 139 | * mostly ). |
---|
| 140 | */ |
---|
| 141 | void _alBufferDataWithCallback_LOKI( ALuint bid, |
---|
| 142 | int (*callback)( ALuint sid, |
---|
| 143 | ALuint bid, |
---|
| 144 | ALshort *outdata, |
---|
| 145 | ALenum format, |
---|
| 146 | ALint freq, |
---|
| 147 | ALint samples ), |
---|
| 148 | DestroyCallback_LOKI source_destroyer, |
---|
| 149 | DestroyCallback_LOKI buffer_destroyer ); |
---|
| 150 | |
---|
| 151 | /* |
---|
| 152 | * Calls the source-callback-completion notification function for the |
---|
| 153 | * buffer associated with the source named by sid. |
---|
| 154 | */ |
---|
| 155 | void _alBidCallDestroyCallbackSource( ALuint sid ); |
---|
| 156 | |
---|
| 157 | /* |
---|
| 158 | * Locks the buffer mutex. fn and ln name the file and line that this call |
---|
| 159 | * takes place in, for debugging purposes. |
---|
| 160 | */ |
---|
| 161 | ALboolean FL_alLockBuffer( const char *fn, int ln ); |
---|
| 162 | |
---|
| 163 | /* |
---|
| 164 | * Unlocks the buffer mutex. fn and ln name the file and line that this call |
---|
| 165 | * takes place in, for debugging purposes. |
---|
| 166 | */ |
---|
| 167 | ALboolean FL_alUnlockBuffer( const char *fn, int ln ); |
---|
| 168 | |
---|
| 169 | /* |
---|
| 170 | * convert data passed from the format specified by the tuple format and |
---|
| 171 | * ffreq, into the format specified by tformat and tfreq. *retsize is set to |
---|
| 172 | * the resulting size. |
---|
| 173 | * |
---|
| 174 | * If should_use_passed_data is AL_TRUE, then the conversion happens |
---|
| 175 | * in-place, and the return value is equal to data. Otherwise, a |
---|
| 176 | * new memory region is alloced, and it is the responsibility of the |
---|
| 177 | * caller to free it. |
---|
| 178 | * |
---|
| 179 | * If no conversion is possible, NULL is returned. |
---|
| 180 | */ |
---|
| 181 | ALvoid *_alBufferCanonizeData( ALenum format, const ALvoid *data, ALuint size, ALuint freq, |
---|
| 182 | ALenum tformat, ALuint tfreq, ALuint *retsize, |
---|
| 183 | ALenum should_use_passed_data ); |
---|
| 184 | |
---|
| 185 | /* macros */ |
---|
| 186 | #define _alLockBuffer() FL_alLockBuffer(__FILE__, __LINE__) |
---|
| 187 | #define _alUnlockBuffer() FL_alUnlockBuffer(__FILE__, __LINE__) |
---|
| 188 | |
---|
| 189 | #define _alDCGetBufferFromSid(x) \ |
---|
| 190 | _alGetBufferFromSid((ALuint) _alcCCId, x) |
---|
| 191 | |
---|
| 192 | #endif |
---|