Avoid void-pointer arithmetic
[openal-soft.git] / OpenAL32 / alBuffer.c
blob0abdb61f07911d4deb883c2e57eebea22ac8d1fb
1 /**
2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
21 #define _CRT_SECURE_NO_DEPRECATE // get rid of sprintf security warnings on VS2005
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include "alMain.h"
26 #include "AL/al.h"
27 #include "AL/alc.h"
28 #include "alError.h"
29 #include "alBuffer.h"
33 * AL Buffer Functions
35 * AL Buffers are shared amoung Contexts, so we store the list of generated Buffers
36 * as a global variable in this module. (A valid context is not required to make
37 * AL Buffer function calls
42 * Global Variables
45 static ALbuffer *g_pBuffers = NULL; // Linked List of Buffers
46 static ALuint g_uiBufferCount = 0; // Buffer Count
48 static const long g_IMAStep_size[89]={ // IMA ADPCM Stepsize table
49 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
50 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
51 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
52 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
53 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,10442,11487,12635,13899,
54 15289,16818,18500,20350,22358,24633,27086,29794,32767
57 static const long g_IMACodeword_4[16]={ // IMA4 ADPCM Codeword decode table
58 1, 3, 5, 7, 9, 11, 13, 15,
59 -1,-3,-5,-7,-9,-11,-13,-15,
62 static const long g_IMAIndex_adjust_4[16]={ // IMA4 ADPCM Step index adjust decode table
63 -1,-1,-1,-1, 2, 4, 6, 8,
64 -1,-1,-1,-1, 2, 4, 6, 8
68 * alGenBuffers(ALsizei n, ALuint *puiBuffers)
70 * Generates n AL Buffers, and stores the Buffers Names in the array pointed to by puiBuffers
72 ALAPI ALvoid ALAPIENTRY alGenBuffers(ALsizei n,ALuint *puiBuffers)
74 ALCcontext *Context;
75 ALsizei i=0;
77 Context = alcGetCurrentContext();
78 SuspendContext(Context);
80 // Check that we are actually generation some Buffers
81 if (n > 0)
83 // Check the pointer is valid (and points to enough memory to store Buffer Names)
84 if (!IsBadWritePtr((void*)puiBuffers, n * sizeof(ALuint)))
86 ALbuffer **list = &g_pBuffers;
87 while(*list)
88 list = &(*list)->next;
90 // Create all the new Buffers
91 while(i < n)
93 *list = calloc(1, sizeof(ALbuffer));
94 if(*list)
96 puiBuffers[i] = (ALuint)ALTHUNK_ADDENTRY(*list);
97 (*list)->state = UNUSED;
98 g_uiBufferCount++;
99 i++;
101 list = &(*list)->next;
105 // If we didn't create all the Buffers, we must have run out of memory
106 if (i != n)
107 alSetError(AL_OUT_OF_MEMORY);
109 else
111 // Pointer does not point to enough memory to write Buffer names
112 alSetError(AL_INVALID_VALUE);
116 ProcessContext(Context);
118 return;
122 * alDeleteBuffers(ALsizei n, ALuint *puiBuffers)
124 * Deletes the n AL Buffers pointed to by puiBuffers
126 ALAPI ALvoid ALAPIENTRY alDeleteBuffers(ALsizei n, const ALuint *puiBuffers)
128 ALCcontext *Context;
129 ALbuffer *ALBuf;
130 ALsizei i;
131 ALboolean bFailed = AL_FALSE;
133 Context = alcGetCurrentContext();
134 SuspendContext(Context);
136 // Check we are actually Deleting some Buffers
137 if (n >= 0)
139 if ((ALuint)n <= g_uiBufferCount)
141 // Check that all the buffers are valid and can actually be deleted
142 for (i = 0; i < n; i++)
144 // Check for valid Buffer ID (can be NULL buffer)
145 if (alIsBuffer(puiBuffers[i]))
147 // If not the NULL buffer, check that the reference count is 0
148 ALBuf = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
149 if (ALBuf)
151 if (ALBuf->refcount != 0)
153 // Buffer still in use, cannot be deleted
154 alSetError(AL_INVALID_OPERATION);
155 bFailed = AL_TRUE;
159 else
161 // Invalid Buffer
162 alSetError(AL_INVALID_NAME);
163 bFailed = AL_TRUE;
167 // If all the Buffers were valid (and have Reference Counts of 0), then we can delete them
168 if (!bFailed)
170 for (i = 0; i < n; i++)
172 ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(puiBuffers[i]));
173 if (ALBuf)
175 ALbuffer **list = &g_pBuffers;
176 while(*list && *list != ALBuf)
177 list = &(*list)->next;
179 if(*list)
180 *list = (*list)->next;
182 // Release the memory used to store audio data
183 free(ALBuf->data);
185 // Release buffer structure
186 ALTHUNK_REMOVEENTRY(puiBuffers[i]);
187 memset(ALBuf, 0, sizeof(ALbuffer));
188 g_uiBufferCount--;
189 free(ALBuf);
194 else
195 alSetError(AL_INVALID_NAME);
197 else
198 alSetError(AL_INVALID_VALUE);
200 ProcessContext(Context);
202 return;
207 * alIsBuffer(ALuint uiBuffer)
209 * Checks if ulBuffer is a valid Buffer Name
211 ALAPI ALboolean ALAPIENTRY alIsBuffer(ALuint uiBuffer)
213 ALCcontext *Context;
214 ALboolean result=AL_FALSE;
215 ALbuffer *ALBuf;
216 ALbuffer *TgtALBuf;
218 Context = alcGetCurrentContext();
219 SuspendContext(Context);
221 if (uiBuffer)
223 TgtALBuf = (ALbuffer *)ALTHUNK_LOOKUPENTRY(uiBuffer);
225 // Check through list of generated buffers for uiBuffer
226 ALBuf = g_pBuffers;
227 while (ALBuf)
229 if (ALBuf == TgtALBuf)
231 result = AL_TRUE;
232 break;
235 ALBuf = ALBuf->next;
238 else
240 result = AL_TRUE;
244 ProcessContext(Context);
246 return result;
250 * alBufferData(ALuint buffer,ALenum format,ALvoid *data,ALsizei size,ALsizei freq)
252 * Fill buffer with audio data
254 ALAPI ALvoid ALAPIENTRY alBufferData(ALuint buffer,ALenum format,const ALvoid *data,ALsizei size,ALsizei freq)
256 ALuint *IMAData,IMACode;
257 ALCcontext *Context;
258 ALint Sample,Index;
259 ALint LeftSample,LeftIndex;
260 ALint RightSample,RightIndex;
261 ALuint LeftIMACode,RightIMACode;
262 ALbuffer *ALBuf;
263 ALsizei i,j,k;
265 Context = alcGetCurrentContext();
266 SuspendContext(Context);
268 if (alIsBuffer(buffer) && (buffer != 0))
270 ALBuf=((ALbuffer *)ALTHUNK_LOOKUPENTRY(buffer));
271 if ((ALBuf->refcount==0)&&(data))
273 switch(format)
275 case AL_FORMAT_MONO8:
276 if ((size%1) == 0)
278 // 8bit Samples are converted to 16 bit here
279 // Allocate 8 extra samples (16 bytes)
280 ALBuf->data=realloc(ALBuf->data,16+(size/sizeof(ALubyte))*(1*sizeof(ALshort)));
281 if (ALBuf->data)
283 ALBuf->format = AL_FORMAT_MONO16;
284 ALBuf->eOriginalFormat = AL_FORMAT_MONO8;
285 for (i=0;i<(ALsizei)(size/sizeof(ALubyte));i++)
286 ALBuf->data[i]=(ALshort)((((ALubyte *)data)[i]-128)<<8);
287 memset(&(ALBuf->data[size/sizeof(ALubyte)]), 0, 16);
288 ALBuf->size=size/sizeof(ALubyte)*1*sizeof(ALshort);
289 ALBuf->frequency=freq;
291 else
292 alSetError(AL_OUT_OF_MEMORY);
294 else
295 alSetError(AL_INVALID_VALUE);
296 break;
298 case AL_FORMAT_MONO16:
299 if ((size%2) == 0)
301 // Allocate 8 extra samples (16 bytes)
302 ALBuf->data=realloc(ALBuf->data,16+(size/sizeof(ALshort))*(1*sizeof(ALshort)));
303 if (ALBuf->data)
305 ALBuf->format = AL_FORMAT_MONO16;
306 ALBuf->eOriginalFormat = AL_FORMAT_MONO16;
307 memcpy(ALBuf->data,data,size/sizeof(ALshort)*1*sizeof(ALshort));
308 memset(&(ALBuf->data[size/sizeof(ALshort)]), 0, 16);
309 ALBuf->size=size/sizeof(ALshort)*1*sizeof(ALshort);
310 ALBuf->frequency=freq;
312 else
313 alSetError(AL_OUT_OF_MEMORY);
315 else
316 alSetError(AL_INVALID_VALUE);
317 break;
319 case AL_FORMAT_STEREO8:
320 if ((size%2) == 0)
322 // 8bit Samples are converted to 16 bit here
323 // Allocate 8 extra samples (32 bytes)
324 ALBuf->data=realloc(ALBuf->data,32+(size/sizeof(ALubyte))*(1*sizeof(ALshort)));
325 if (ALBuf->data)
327 ALBuf->format = AL_FORMAT_STEREO16;
328 ALBuf->eOriginalFormat = AL_FORMAT_STEREO8;
329 for (i=0;i<(ALsizei)(size/sizeof(ALubyte));i++)
330 ALBuf->data[i]=(ALshort)((((ALubyte *)data)[i]-128)<<8);
331 memset(&(ALBuf->data[size/sizeof(ALubyte)]), 0, 32);
332 ALBuf->size=size/sizeof(ALubyte)*1*sizeof(ALshort);
333 ALBuf->frequency=freq;
335 else
336 alSetError(AL_OUT_OF_MEMORY);
338 else
339 alSetError(AL_INVALID_VALUE);
340 break;
342 case AL_FORMAT_STEREO16:
343 if ((size%4) == 0)
345 // Allocate 8 extra samples (32 bytes)
346 ALBuf->data=realloc(ALBuf->data,32+(size/sizeof(ALshort))*(1*sizeof(ALshort)));
347 if (ALBuf->data)
349 ALBuf->format = AL_FORMAT_STEREO16;
350 ALBuf->eOriginalFormat = AL_FORMAT_STEREO16;
351 memcpy(ALBuf->data,data,size/sizeof(ALshort)*1*sizeof(ALshort));
352 memset(&(ALBuf->data[size/sizeof(ALshort)]), 0, 32);
353 ALBuf->size=size/sizeof(ALshort)*1*sizeof(ALshort);
354 ALBuf->frequency=freq;
356 else
357 alSetError(AL_OUT_OF_MEMORY);
359 else
360 alSetError(AL_INVALID_VALUE);
361 break;
363 case AL_FORMAT_MONO_IMA4:
364 // Here is where things vary:
365 // nVidia and Apple use 64+1 samples per block => block_size=36 bytes
366 // Most PC sound software uses 2040+1 samples per block -> block_size=1024 bytes
367 if ((size%36) == 0)
369 // Allocate 8 extra samples (16 bytes)
370 ALBuf->data=realloc(ALBuf->data,16+(size/36)*(65*sizeof(ALshort)));
371 if (ALBuf->data)
373 ALBuf->format = AL_FORMAT_MONO16;
374 ALBuf->eOriginalFormat = AL_FORMAT_MONO_IMA4;
375 IMAData=(ALuint *)data;
376 for (i=0;i<size/36;i++)
378 Sample=((ALshort *)IMAData)[0];
379 Index=((ALshort *)IMAData)[1];
381 Index=Index<0?0:Index;
382 Index=Index>88?88:Index;
384 ALBuf->data[i*65]=(short)Sample;
386 IMAData++;
388 for (j=1;j<65;j+=8)
390 IMACode=*IMAData;
391 for (k=0;k<8;k+=2)
393 Sample+=((g_IMAStep_size[Index]*g_IMACodeword_4[IMACode&15])/8);
394 Index+=g_IMAIndex_adjust_4[IMACode&15];
395 if (Sample<-32768) Sample=-32768;
396 else if (Sample>32767) Sample=32767;
397 if (Index<0) Index=0;
398 else if (Index>88) Index=88;
399 ALBuf->data[i*65+j+k]=(short)Sample;
400 IMACode>>=4;
402 Sample+=((g_IMAStep_size[Index]*g_IMACodeword_4[IMACode&15])/8);
403 Index+=g_IMAIndex_adjust_4[IMACode&15];
404 if (Sample<-32768) Sample=-32768;
405 else if (Sample>32767) Sample=32767;
406 if (Index<0) Index=0;
407 else if (Index>88) Index=88;
408 ALBuf->data[i*65+j+k+1]=(short)Sample;
409 IMACode>>=4;
411 IMAData++;
414 memset(&(ALBuf->data[(size/36*65)]), 0, 16);
415 ALBuf->size=size/36*65*sizeof(ALshort);
416 ALBuf->frequency=freq;
418 else
419 alSetError(AL_OUT_OF_MEMORY);
421 else
422 alSetError(AL_INVALID_VALUE);
423 break;
425 case AL_FORMAT_STEREO_IMA4:
426 // Here is where things vary:
427 // nVidia and Apple use 64+1 samples per channel per block => block_size=72 bytes
428 // Most PC sound software uses 2040+1 samples per channel per block -> block_size=2048 bytes
429 if ((size%72) == 0)
431 // Allocate 8 extra samples (32 bytes)
432 ALBuf->data=realloc(ALBuf->data,32+(size/72)*(2*65*sizeof(ALshort)));
433 if (ALBuf->data)
435 ALBuf->format = AL_FORMAT_STEREO16;
436 ALBuf->eOriginalFormat = AL_FORMAT_STEREO_IMA4;
437 IMAData=(ALuint *)data;
438 for (i=0;i<size/72;i++)
440 LeftSample=((ALshort *)IMAData)[0];
441 LeftIndex=((ALshort *)IMAData)[1];
443 LeftIndex=LeftIndex<0?0:LeftIndex;
444 LeftIndex=LeftIndex>88?88:LeftIndex;
446 ALBuf->data[i*2*65]=(short)LeftSample;
448 IMAData++;
450 RightSample=((ALshort *)IMAData)[0];
451 RightIndex=((ALshort *)IMAData)[1];
453 RightIndex=RightIndex<0?0:RightIndex;
454 RightIndex=RightIndex>88?88:RightIndex;
456 ALBuf->data[i*2*65+1]=(short)RightSample;
458 IMAData++;
460 for (j=2;j<130;j+=16)
462 LeftIMACode=IMAData[0];
463 RightIMACode=IMAData[1];
464 for (k=0;k<16;k+=4)
466 LeftSample+=((g_IMAStep_size[LeftIndex]*g_IMACodeword_4[LeftIMACode&15])/8);
467 LeftIndex+=g_IMAIndex_adjust_4[LeftIMACode&15];
468 if (LeftSample<-32768) LeftSample=-32768;
469 else if (LeftSample>32767) LeftSample=32767;
470 if (LeftIndex<0) LeftIndex=0;
471 else if (LeftIndex>88) LeftIndex=88;
472 ALBuf->data[i*2*65+j+k]=(short)LeftSample;
473 LeftIMACode>>=4;
475 RightSample+=((g_IMAStep_size[RightIndex]*g_IMACodeword_4[RightIMACode&15])/8);
476 RightIndex+=g_IMAIndex_adjust_4[RightIMACode&15];
477 if (RightSample<-32768) RightSample=-32768;
478 else if (RightSample>32767) RightSample=32767;
479 if (RightIndex<0) RightIndex=0;
480 else if (RightIndex>88) RightIndex=88;
481 ALBuf->data[i*2*65+j+k+1]=(short)RightSample;
482 RightIMACode>>=4;
484 LeftSample+=((g_IMAStep_size[LeftIndex]*g_IMACodeword_4[LeftIMACode&15])/8);
485 LeftIndex+=g_IMAIndex_adjust_4[LeftIMACode&15];
486 if (LeftSample<-32768) LeftSample=-32768;
487 else if (LeftSample>32767) LeftSample=32767;
488 if (LeftIndex<0) LeftIndex=0;
489 else if (LeftIndex>88) LeftIndex=88;
490 ALBuf->data[i*2*65+j+k+2]=(short)LeftSample;
491 LeftIMACode>>=4;
493 RightSample+=((g_IMAStep_size[RightIndex]*g_IMACodeword_4[RightIMACode&15])/8);
494 RightIndex+=g_IMAIndex_adjust_4[RightIMACode&15];
495 if (RightSample<-32768) RightSample=-32768;
496 else if (RightSample>32767) RightSample=32767;
497 if (RightIndex<0) RightIndex=0;
498 else if (RightIndex>88) RightIndex=88;
499 ALBuf->data[i*2*65+j+k+3]=(short)RightSample;
500 RightIMACode>>=4;
502 IMAData+=2;
505 memset(&(ALBuf->data[(size/72*2*65)]), 0, 32);
506 ALBuf->size=size/72*2*65*sizeof(ALshort);
507 ALBuf->frequency=freq;
509 else
510 alSetError(AL_OUT_OF_MEMORY);
512 else
513 alSetError(AL_INVALID_VALUE);
514 break;
516 default:
517 alSetError(AL_INVALID_ENUM);
518 break;
521 else
523 // Buffer is in use, or data is a NULL pointer
524 alSetError(AL_INVALID_VALUE);
527 else
529 // Invalid Buffer Name
530 alSetError(AL_INVALID_NAME);
533 ProcessContext(Context);
537 ALAPI void ALAPIENTRY alBufferf(ALuint buffer, ALenum eParam, ALfloat flValue)
539 ALCcontext *pContext;
541 (void)flValue;
543 pContext = alcGetCurrentContext();
544 SuspendContext(pContext);
546 if (alIsBuffer(buffer) && (buffer != 0))
548 switch(eParam)
550 default:
551 alSetError(AL_INVALID_ENUM);
552 break;
555 else
557 alSetError(AL_INVALID_NAME);
560 ProcessContext(pContext);
564 ALAPI void ALAPIENTRY alBuffer3f(ALuint buffer, ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3)
566 ALCcontext *pContext;
568 (void)flValue1;
569 (void)flValue2;
570 (void)flValue3;
572 pContext = alcGetCurrentContext();
573 SuspendContext(pContext);
575 if (alIsBuffer(buffer) && (buffer != 0))
577 switch(eParam)
579 default:
580 alSetError(AL_INVALID_ENUM);
581 break;
584 else
586 alSetError(AL_INVALID_NAME);
589 ProcessContext(pContext);
593 ALAPI void ALAPIENTRY alBufferfv(ALuint buffer, ALenum eParam, const ALfloat* flValues)
595 ALCcontext *pContext;
597 (void)flValues;
599 pContext = alcGetCurrentContext();
600 SuspendContext(pContext);
602 if (alIsBuffer(buffer) && (buffer != 0))
604 switch(eParam)
606 default:
607 alSetError(AL_INVALID_ENUM);
608 break;
611 else
613 alSetError(AL_INVALID_NAME);
616 ProcessContext(pContext);
620 ALAPI void ALAPIENTRY alBufferi(ALuint buffer, ALenum eParam, ALint lValue)
622 ALCcontext *pContext;
624 (void)lValue;
626 pContext = alcGetCurrentContext();
627 SuspendContext(pContext);
629 if (alIsBuffer(buffer) && (buffer != 0))
631 switch(eParam)
633 default:
634 alSetError(AL_INVALID_ENUM);
635 break;
638 else
640 alSetError(AL_INVALID_NAME);
643 ProcessContext(pContext);
647 ALAPI void ALAPIENTRY alBuffer3i( ALuint buffer, ALenum eParam, ALint lValue1, ALint lValue2, ALint lValue3)
649 ALCcontext *pContext;
651 (void)lValue1;
652 (void)lValue2;
653 (void)lValue3;
655 pContext = alcGetCurrentContext();
656 SuspendContext(pContext);
658 if (alIsBuffer(buffer) && (buffer != 0))
660 switch(eParam)
662 default:
663 alSetError(AL_INVALID_ENUM);
664 break;
667 else
669 alSetError(AL_INVALID_NAME);
672 ProcessContext(pContext);
676 ALAPI void ALAPIENTRY alBufferiv(ALuint buffer, ALenum eParam, const ALint* plValues)
678 ALCcontext *pContext;
680 (void)plValues;
682 pContext = alcGetCurrentContext();
683 SuspendContext(pContext);
685 if (alIsBuffer(buffer) && (buffer != 0))
687 switch(eParam)
689 default:
690 alSetError(AL_INVALID_ENUM);
691 break;
694 else
696 alSetError(AL_INVALID_NAME);
699 ProcessContext(pContext);
703 ALAPI ALvoid ALAPIENTRY alGetBufferf(ALuint buffer, ALenum eParam, ALfloat *pflValue)
705 ALCcontext *pContext;
707 pContext = alcGetCurrentContext();
708 SuspendContext(pContext);
710 if (pflValue)
712 if (alIsBuffer(buffer) && (buffer != 0))
714 switch(eParam)
716 default:
717 alSetError(AL_INVALID_ENUM);
718 break;
721 else
723 alSetError(AL_INVALID_NAME);
726 else
728 alSetError(AL_INVALID_VALUE);
731 ProcessContext(pContext);
735 ALAPI void ALAPIENTRY alGetBuffer3f(ALuint buffer, ALenum eParam, ALfloat* pflValue1, ALfloat* pflValue2, ALfloat* pflValue3)
737 ALCcontext *pContext;
739 pContext = alcGetCurrentContext();
740 SuspendContext(pContext);
742 if ((pflValue1) && (pflValue2) && (pflValue3))
744 if (alIsBuffer(buffer) && (buffer != 0))
746 switch(eParam)
748 default:
749 alSetError(AL_INVALID_ENUM);
750 break;
753 else
755 alSetError(AL_INVALID_NAME);
758 else
760 alSetError(AL_INVALID_VALUE);
763 ProcessContext(pContext);
767 ALAPI void ALAPIENTRY alGetBufferfv(ALuint buffer, ALenum eParam, ALfloat* pflValues)
769 ALCcontext *pContext;
771 pContext = alcGetCurrentContext();
772 SuspendContext(pContext);
774 if (pflValues)
776 if (alIsBuffer(buffer) && (buffer != 0))
778 switch(eParam)
780 default:
781 alSetError(AL_INVALID_ENUM);
782 break;
785 else
787 alSetError(AL_INVALID_NAME);
790 else
792 alSetError(AL_INVALID_VALUE);
795 ProcessContext(pContext);
799 ALAPI ALvoid ALAPIENTRY alGetBufferi(ALuint buffer, ALenum eParam, ALint *plValue)
801 ALCcontext *pContext;
802 ALbuffer *pBuffer;
804 pContext = alcGetCurrentContext();
805 SuspendContext(pContext);
807 if (plValue)
809 if (alIsBuffer(buffer) && (buffer != 0))
811 pBuffer = ((ALbuffer *)ALTHUNK_LOOKUPENTRY(buffer));
813 switch (eParam)
815 case AL_FREQUENCY:
816 *plValue = pBuffer->frequency;
817 break;
819 case AL_BITS:
820 *plValue= (((pBuffer->format==AL_FORMAT_MONO8)||(pBuffer->format==AL_FORMAT_STEREO8))?8:16);
821 break;
823 case AL_CHANNELS:
824 *plValue = (((pBuffer->format==AL_FORMAT_MONO8)||(pBuffer->format==AL_FORMAT_MONO16))?1:2);
825 break;
827 case AL_SIZE:
828 *plValue = pBuffer->size;
829 break;
831 default:
832 alSetError(AL_INVALID_ENUM);
833 break;
836 else
838 alSetError(AL_INVALID_NAME);
841 else
843 alSetError(AL_INVALID_VALUE);
846 ProcessContext(pContext);
850 ALAPI void ALAPIENTRY alGetBuffer3i(ALuint buffer, ALenum eParam, ALint* plValue1, ALint* plValue2, ALint* plValue3)
852 ALCcontext *pContext;
854 pContext = alcGetCurrentContext();
855 SuspendContext(pContext);
857 if ((plValue1) && (plValue2) && (plValue3))
859 if (alIsBuffer(buffer) && (buffer != 0))
861 switch(eParam)
863 default:
864 alSetError(AL_INVALID_ENUM);
865 break;
868 else
870 alSetError(AL_INVALID_NAME);
873 else
875 alSetError(AL_INVALID_VALUE);
878 ProcessContext(pContext);
882 ALAPI void ALAPIENTRY alGetBufferiv(ALuint buffer, ALenum eParam, ALint* plValues)
884 ALCcontext *pContext;
886 pContext = alcGetCurrentContext();
887 SuspendContext(pContext);
889 if (plValues)
891 if (alIsBuffer(buffer) && (buffer != 0))
893 switch (eParam)
895 case AL_FREQUENCY:
896 case AL_BITS:
897 case AL_CHANNELS:
898 case AL_SIZE:
899 alGetBufferi(buffer, eParam, plValues);
900 break;
902 default:
903 alSetError(AL_INVALID_ENUM);
904 break;
907 else
909 alSetError(AL_INVALID_NAME);
912 else
914 alSetError(AL_INVALID_VALUE);
917 ProcessContext(pContext);
922 * ReleaseALBuffers()
924 * INTERNAL FN : Called by DLLMain on exit to destroy any buffers that still exist
926 ALvoid ReleaseALBuffers(ALvoid)
928 ALbuffer *ALBuffer;
929 ALbuffer *ALBufferTemp;
931 #ifdef _DEBUG
932 if(g_uiBufferCount > 0)
933 AL_PRINT("exit() %d Buffer(s) NOT deleted\n", g_uiBufferCount);
934 #endif
936 ALBuffer = g_pBuffers;
937 while(ALBuffer)
939 // Release sample data
940 free(ALBuffer->data);
942 // Release Buffer structure
943 ALBufferTemp = ALBuffer;
944 ALBuffer = ALBuffer->next;
945 memset(ALBufferTemp, 0, sizeof(ALbuffer));
946 free(ALBufferTemp);
948 g_pBuffers = NULL;
949 g_uiBufferCount = 0;