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
33 #include "alDatabuffer.h"
37 static ALenum
LoadData(ALbuffer
*ALBuf
, const ALvoid
*data
, ALsizei size
, ALuint freq
, ALenum OrigFormat
, ALenum NewFormat
);
38 static void ConvertData(ALvoid
*dst
, enum FmtType dstType
, const ALvoid
*src
, enum SrcFmtType srcType
, ALsizei len
);
39 static void ConvertDataRear(ALvoid
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
);
40 static void ConvertDataIMA4(ALvoid
*dst
, const ALvoid
*src
, ALint origChans
, ALsizei len
);
41 static void ConvertDataMULaw(ALvoid
*dst
, const ALvoid
*src
, ALsizei len
);
42 static void ConvertDataMULawRear(ALvoid
*dst
, const ALvoid
*src
, ALsizei len
);
44 #define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k)))
51 static const long g_IMAStep_size
[89]={ // IMA ADPCM Stepsize table
52 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
53 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
54 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
55 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
56 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,10442,11487,12635,13899,
57 15289,16818,18500,20350,22358,24633,27086,29794,32767
60 static const long g_IMACodeword_4
[16]={ // IMA4 ADPCM Codeword decode table
61 1, 3, 5, 7, 9, 11, 13, 15,
62 -1,-3,-5,-7,-9,-11,-13,-15,
65 static const long g_IMAIndex_adjust_4
[16]={ // IMA4 ADPCM Step index adjust decode table
66 -1,-1,-1,-1, 2, 4, 6, 8,
67 -1,-1,-1,-1, 2, 4, 6, 8
70 static const ALshort muLawDecompressionTable
[256] = {
71 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
72 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
73 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
74 -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
75 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
76 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
77 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
78 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
79 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
80 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
81 -876, -844, -812, -780, -748, -716, -684, -652,
82 -620, -588, -556, -524, -492, -460, -428, -396,
83 -372, -356, -340, -324, -308, -292, -276, -260,
84 -244, -228, -212, -196, -180, -164, -148, -132,
85 -120, -112, -104, -96, -88, -80, -72, -64,
86 -56, -48, -40, -32, -24, -16, -8, 0,
87 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
88 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
89 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
90 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
91 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
92 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
93 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
94 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
95 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
96 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
97 876, 844, 812, 780, 748, 716, 684, 652,
98 620, 588, 556, 524, 492, 460, 428, 396,
99 372, 356, 340, 324, 308, 292, 276, 260,
100 244, 228, 212, 196, 180, 164, 148, 132,
101 120, 112, 104, 96, 88, 80, 72, 64,
102 56, 48, 40, 32, 24, 16, 8, 0
106 * alGenBuffers(ALsizei n, ALuint *buffers)
108 * Generates n AL Buffers, and stores the Buffers Names in the array pointed to by buffers
110 AL_API ALvoid AL_APIENTRY
alGenBuffers(ALsizei n
, ALuint
*buffers
)
115 Context
= GetContextSuspended();
118 // Check that we are actually generating some Buffers
119 if(n
< 0 || IsBadWritePtr((void*)buffers
, n
* sizeof(ALuint
)))
120 alSetError(Context
, AL_INVALID_VALUE
);
123 ALCdevice
*device
= Context
->Device
;
126 // Create all the new Buffers
129 ALbuffer
*buffer
= calloc(1, sizeof(ALbuffer
));
132 alSetError(Context
, AL_OUT_OF_MEMORY
);
133 alDeleteBuffers(i
, buffers
);
137 buffer
->buffer
= (ALuint
)ALTHUNK_ADDENTRY(buffer
);
138 err
= InsertUIntMapEntry(&device
->BufferMap
, buffer
->buffer
, buffer
);
139 if(err
!= AL_NO_ERROR
)
141 ALTHUNK_REMOVEENTRY(buffer
->buffer
);
142 memset(buffer
, 0, sizeof(ALbuffer
));
145 alSetError(Context
, err
);
146 alDeleteBuffers(i
, buffers
);
149 buffers
[i
++] = buffer
->buffer
;
153 ProcessContext(Context
);
157 * alDeleteBuffers(ALsizei n, ALuint *buffers)
159 * Deletes the n AL Buffers pointed to by buffers
161 AL_API ALvoid AL_APIENTRY
alDeleteBuffers(ALsizei n
, const ALuint
*buffers
)
169 Context
= GetContextSuspended();
173 device
= Context
->Device
;
174 /* Check we are actually Deleting some Buffers */
176 alSetError(Context
, AL_INVALID_VALUE
);
181 /* Check that all the buffers are valid and can actually be deleted */
187 /* Check for valid Buffer ID */
188 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffers
[i
])) == NULL
)
190 alSetError(Context
, AL_INVALID_NAME
);
194 else if(ALBuf
->refcount
!= 0)
196 /* Buffer still in use, cannot be deleted */
197 alSetError(Context
, AL_INVALID_OPERATION
);
204 /* If all the Buffers were valid (and have Reference Counts of 0), then we can delete them */
209 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffers
[i
])) == NULL
)
212 /* Release the memory used to store audio data */
215 /* Release buffer structure */
216 RemoveUIntMapKey(&device
->BufferMap
, ALBuf
->buffer
);
217 ALTHUNK_REMOVEENTRY(ALBuf
->buffer
);
219 memset(ALBuf
, 0, sizeof(ALbuffer
));
224 ProcessContext(Context
);
228 * alIsBuffer(ALuint buffer)
230 * Checks if buffer is a valid Buffer Name
232 AL_API ALboolean AL_APIENTRY
alIsBuffer(ALuint buffer
)
237 Context
= GetContextSuspended();
238 if(!Context
) return AL_FALSE
;
240 result
= ((!buffer
|| LookupBuffer(Context
->Device
->BufferMap
, buffer
)) ?
243 ProcessContext(Context
);
249 * alBufferData(ALuint buffer,ALenum format,const ALvoid *data,ALsizei size,ALsizei freq)
251 * Fill buffer with audio data
253 AL_API ALvoid AL_APIENTRY
alBufferData(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei size
,ALsizei freq
)
261 Context
= GetContextSuspended();
264 if(Context
->SampleSource
)
268 if(Context
->SampleSource
->state
== MAPPED
)
270 alSetError(Context
, AL_INVALID_OPERATION
);
271 ProcessContext(Context
);
275 offset
= (const ALubyte
*)data
- (ALubyte
*)NULL
;
276 data
= Context
->SampleSource
->data
+ offset
;
279 device
= Context
->Device
;
280 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
281 alSetError(Context
, AL_INVALID_NAME
);
282 else if(size
< 0 || freq
< 0)
283 alSetError(Context
, AL_INVALID_VALUE
);
284 else if(ALBuf
->refcount
!= 0)
285 alSetError(Context
, AL_INVALID_VALUE
);
288 case AL_FORMAT_MONO8
:
289 case AL_FORMAT_MONO16
:
290 case AL_FORMAT_MONO_FLOAT32
:
291 case AL_FORMAT_MONO_DOUBLE_EXT
:
292 case AL_FORMAT_STEREO8
:
293 case AL_FORMAT_STEREO16
:
294 case AL_FORMAT_STEREO_FLOAT32
:
295 case AL_FORMAT_STEREO_DOUBLE_EXT
:
296 case AL_FORMAT_QUAD8_LOKI
:
297 case AL_FORMAT_QUAD16_LOKI
:
298 case AL_FORMAT_QUAD8
:
299 case AL_FORMAT_QUAD16
:
300 case AL_FORMAT_QUAD32
:
301 case AL_FORMAT_51CHN8
:
302 case AL_FORMAT_51CHN16
:
303 case AL_FORMAT_51CHN32
:
304 case AL_FORMAT_61CHN8
:
305 case AL_FORMAT_61CHN16
:
306 case AL_FORMAT_61CHN32
:
307 case AL_FORMAT_71CHN8
:
308 case AL_FORMAT_71CHN16
:
309 case AL_FORMAT_71CHN32
:
310 err
= LoadData(ALBuf
, data
, size
, freq
, format
, format
);
311 if(err
!= AL_NO_ERROR
)
312 alSetError(Context
, err
);
315 case AL_FORMAT_REAR8
:
316 case AL_FORMAT_REAR16
:
317 case AL_FORMAT_REAR32
: {
318 ALuint OrigBytes
= ((format
==AL_FORMAT_REAR8
) ? 1 :
319 ((format
==AL_FORMAT_REAR16
) ? 2 : 4));
320 ALenum NewFormat
= ((OrigBytes
==4) ? AL_FORMAT_QUAD32
:
321 ((OrigBytes
==2) ? AL_FORMAT_QUAD16
:
323 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
324 ALuint NewBytes
= aluBytesFromFormat(NewFormat
);
327 if((size
%(OrigBytes
*2)) != 0)
329 alSetError(Context
, AL_INVALID_VALUE
);
333 newsize
= size
/ OrigBytes
;
337 if(newsize
> INT_MAX
)
339 alSetError(Context
, AL_OUT_OF_MEMORY
);
342 temp
= realloc(ALBuf
->data
, newsize
);
346 ConvertDataRear(ALBuf
->data
, data
, OrigBytes
, newsize
/NewBytes
);
348 ALBuf
->format
= NewFormat
;
349 ALBuf
->eOriginalFormat
= format
;
350 ALBuf
->size
= newsize
;
351 ALBuf
->frequency
= freq
;
353 ALBuf
->LoopStart
= 0;
354 ALBuf
->LoopEnd
= newsize
/ NewChannels
/ NewBytes
;
356 DecomposeFormat(NewFormat
, &ALBuf
->FmtType
, &ALBuf
->FmtChannels
);
358 ALBuf
->OriginalSize
= size
;
359 ALBuf
->OriginalAlign
= OrigBytes
* 2;
362 alSetError(Context
, AL_OUT_OF_MEMORY
);
365 case AL_FORMAT_MONO_IMA4
:
366 case AL_FORMAT_STEREO_IMA4
: {
367 ALuint Channels
= ((format
==AL_FORMAT_MONO_IMA4
) ? 1 : 2);
368 ALenum NewFormat
= ((Channels
==1) ? AL_FORMAT_MONO16
:
370 ALuint NewBytes
= aluBytesFromFormat(NewFormat
);
373 /* Here is where things vary:
374 * nVidia and Apple use 64+1 sample frames per block => block_size=36*chans bytes
375 * Most PC sound software uses 2040+1 sample frames per block -> block_size=1024*chans bytes
377 if((size
%(36*Channels
)) != 0)
379 alSetError(Context
, AL_INVALID_VALUE
);
387 if(newsize
> INT_MAX
)
389 alSetError(Context
, AL_OUT_OF_MEMORY
);
392 temp
= realloc(ALBuf
->data
, newsize
);
396 ConvertDataIMA4(ALBuf
->data
, data
, Channels
, newsize
/(65*Channels
*NewBytes
));
398 ALBuf
->format
= NewFormat
;
399 ALBuf
->eOriginalFormat
= format
;
400 ALBuf
->size
= newsize
;
401 ALBuf
->frequency
= freq
;
403 ALBuf
->LoopStart
= 0;
404 ALBuf
->LoopEnd
= newsize
/ Channels
/ NewBytes
;
406 DecomposeFormat(NewFormat
, &ALBuf
->FmtType
, &ALBuf
->FmtChannels
);
408 ALBuf
->OriginalSize
= size
;
409 ALBuf
->OriginalAlign
= 36 * Channels
;
412 alSetError(Context
, AL_OUT_OF_MEMORY
);
415 case AL_FORMAT_MONO_MULAW
:
416 case AL_FORMAT_STEREO_MULAW
:
417 case AL_FORMAT_QUAD_MULAW
:
418 case AL_FORMAT_51CHN_MULAW
:
419 case AL_FORMAT_61CHN_MULAW
:
420 case AL_FORMAT_71CHN_MULAW
: {
421 ALuint Channels
= ((format
==AL_FORMAT_MONO_MULAW
) ? 1 :
422 ((format
==AL_FORMAT_STEREO_MULAW
) ? 2 :
423 ((format
==AL_FORMAT_QUAD_MULAW
) ? 4 :
424 ((format
==AL_FORMAT_51CHN_MULAW
) ? 6 :
425 ((format
==AL_FORMAT_61CHN_MULAW
) ? 7 : 8)))));
426 ALenum NewFormat
= ((Channels
==1) ? AL_FORMAT_MONO16
:
427 ((Channels
==2) ? AL_FORMAT_STEREO16
:
428 ((Channels
==4) ? AL_FORMAT_QUAD16
:
429 ((Channels
==6) ? AL_FORMAT_51CHN16
:
430 ((Channels
==7) ? AL_FORMAT_61CHN16
:
431 AL_FORMAT_71CHN16
)))));
432 ALuint NewBytes
= aluBytesFromFormat(NewFormat
);
435 if((size
%(1*Channels
)) != 0)
437 alSetError(Context
, AL_INVALID_VALUE
);
441 newsize
= size
* NewBytes
;
442 if(newsize
> INT_MAX
)
444 alSetError(Context
, AL_OUT_OF_MEMORY
);
447 temp
= realloc(ALBuf
->data
, newsize
);
451 ConvertDataMULaw(ALBuf
->data
, data
, newsize
/NewBytes
);
453 ALBuf
->format
= NewFormat
;
454 ALBuf
->eOriginalFormat
= format
;
455 ALBuf
->size
= newsize
;
456 ALBuf
->frequency
= freq
;
458 ALBuf
->LoopStart
= 0;
459 ALBuf
->LoopEnd
= newsize
/ Channels
/ NewBytes
;
461 DecomposeFormat(NewFormat
, &ALBuf
->FmtType
, &ALBuf
->FmtChannels
);
463 ALBuf
->OriginalSize
= size
;
464 ALBuf
->OriginalAlign
= 1 * Channels
;
467 alSetError(Context
, AL_OUT_OF_MEMORY
);
470 case AL_FORMAT_REAR_MULAW
: {
471 ALenum NewFormat
= AL_FORMAT_QUAD16
;
472 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
473 ALuint NewBytes
= aluBytesFromFormat(NewFormat
);
476 if((size
%(1*2)) != 0)
478 alSetError(Context
, AL_INVALID_VALUE
);
485 if(newsize
> INT_MAX
)
487 alSetError(Context
, AL_OUT_OF_MEMORY
);
490 temp
= realloc(ALBuf
->data
, newsize
);
494 ConvertDataMULawRear(ALBuf
->data
, data
, newsize
/NewBytes
);
496 ALBuf
->format
= NewFormat
;
497 ALBuf
->eOriginalFormat
= format
;
498 ALBuf
->size
= newsize
;
499 ALBuf
->frequency
= freq
;
501 ALBuf
->LoopStart
= 0;
502 ALBuf
->LoopEnd
= newsize
/ NewChannels
/ NewBytes
;
504 DecomposeFormat(NewFormat
, &ALBuf
->FmtType
, &ALBuf
->FmtChannels
);
506 ALBuf
->OriginalSize
= size
;
507 ALBuf
->OriginalAlign
= 1 * 2;
510 alSetError(Context
, AL_OUT_OF_MEMORY
);
514 alSetError(Context
, AL_INVALID_ENUM
);
518 ProcessContext(Context
);
522 * alBufferSubDataSOFT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length)
524 * Update buffer's audio data
526 AL_API ALvoid AL_APIENTRY
alBufferSubDataSOFT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
532 Context
= GetContextSuspended();
535 if(Context
->SampleSource
)
539 if(Context
->SampleSource
->state
== MAPPED
)
541 alSetError(Context
, AL_INVALID_OPERATION
);
542 ProcessContext(Context
);
546 offset
= (const ALubyte
*)data
- (ALubyte
*)NULL
;
547 data
= Context
->SampleSource
->data
+ offset
;
550 device
= Context
->Device
;
551 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
552 alSetError(Context
, AL_INVALID_NAME
);
553 else if(length
< 0 || offset
< 0 || (length
> 0 && data
== NULL
))
554 alSetError(Context
, AL_INVALID_VALUE
);
555 else if(ALBuf
->eOriginalFormat
!= format
)
556 alSetError(Context
, AL_INVALID_ENUM
);
557 else if(offset
> ALBuf
->OriginalSize
||
558 length
> ALBuf
->OriginalSize
-offset
||
559 (offset
%ALBuf
->OriginalAlign
) != 0 ||
560 (length
%ALBuf
->OriginalAlign
) != 0)
561 alSetError(Context
, AL_INVALID_VALUE
);
564 case AL_FORMAT_MONO8
:
565 case AL_FORMAT_MONO16
:
566 case AL_FORMAT_MONO_FLOAT32
:
567 case AL_FORMAT_MONO_DOUBLE_EXT
:
568 case AL_FORMAT_STEREO8
:
569 case AL_FORMAT_STEREO16
:
570 case AL_FORMAT_STEREO_FLOAT32
:
571 case AL_FORMAT_STEREO_DOUBLE_EXT
:
572 case AL_FORMAT_QUAD8_LOKI
:
573 case AL_FORMAT_QUAD16_LOKI
:
574 case AL_FORMAT_QUAD8
:
575 case AL_FORMAT_QUAD16
:
576 case AL_FORMAT_QUAD32
:
577 case AL_FORMAT_51CHN8
:
578 case AL_FORMAT_51CHN16
:
579 case AL_FORMAT_51CHN32
:
580 case AL_FORMAT_61CHN8
:
581 case AL_FORMAT_61CHN16
:
582 case AL_FORMAT_61CHN32
:
583 case AL_FORMAT_71CHN8
:
584 case AL_FORMAT_71CHN16
:
585 case AL_FORMAT_71CHN32
: {
586 ALuint OldBytes
= aluBytesFromFormat(format
);
587 ALuint Bytes
= aluBytesFromFormat(ALBuf
->format
);
588 enum SrcFmtChannels SrcChannels
;
589 enum SrcFmtType SrcType
;
595 DecomposeInputFormat(format
, &SrcType
, &SrcChannels
);
596 ConvertData(&((ALubyte
*)ALBuf
->data
)[offset
], ALBuf
->FmtType
,
597 data
, SrcType
, length
);
600 case AL_FORMAT_REAR8
:
601 case AL_FORMAT_REAR16
:
602 case AL_FORMAT_REAR32
: {
603 ALuint OldBytes
= ((format
==AL_FORMAT_REAR8
) ? 1 :
604 ((format
==AL_FORMAT_REAR16
) ? 2 : 4));
605 ALuint Bytes
= aluBytesFromFormat(ALBuf
->format
);
613 ConvertDataRear(&((ALubyte
*)ALBuf
->data
)[offset
], data
, Bytes
, length
);
616 case AL_FORMAT_MONO_IMA4
:
617 case AL_FORMAT_STEREO_IMA4
: {
618 ALuint Channels
= aluChannelsFromFormat(ALBuf
->format
);
619 ALuint Bytes
= aluBytesFromFormat(ALBuf
->format
);
621 /* offset -> byte offset, length -> block count */
625 length
/= ALBuf
->OriginalAlign
;
627 ConvertDataIMA4(&((ALubyte
*)ALBuf
->data
)[offset
], data
, Channels
, length
);
630 case AL_FORMAT_MONO_MULAW
:
631 case AL_FORMAT_STEREO_MULAW
:
632 case AL_FORMAT_QUAD_MULAW
:
633 case AL_FORMAT_51CHN_MULAW
:
634 case AL_FORMAT_61CHN_MULAW
:
635 case AL_FORMAT_71CHN_MULAW
: {
636 ALuint Bytes
= aluBytesFromFormat(ALBuf
->format
);
640 ConvertDataMULaw(&((ALubyte
*)ALBuf
->data
)[offset
], data
, length
);
643 case AL_FORMAT_REAR_MULAW
: {
644 ALuint Bytes
= aluBytesFromFormat(ALBuf
->format
);
650 ConvertDataMULawRear(&((ALubyte
*)ALBuf
->data
)[offset
], data
, length
);
654 alSetError(Context
, AL_INVALID_ENUM
);
658 ProcessContext(Context
);
661 AL_API ALvoid AL_APIENTRY
alBufferSubDataEXT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
663 alBufferSubDataSOFT(buffer
, format
, data
, offset
, length
);
667 AL_API
void AL_APIENTRY
alBufferf(ALuint buffer
, ALenum eParam
, ALfloat flValue
)
669 ALCcontext
*pContext
;
674 pContext
= GetContextSuspended();
675 if(!pContext
) return;
677 device
= pContext
->Device
;
678 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
679 alSetError(pContext
, AL_INVALID_NAME
);
685 alSetError(pContext
, AL_INVALID_ENUM
);
690 ProcessContext(pContext
);
694 AL_API
void AL_APIENTRY
alBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat flValue1
, ALfloat flValue2
, ALfloat flValue3
)
696 ALCcontext
*pContext
;
703 pContext
= GetContextSuspended();
704 if(!pContext
) return;
706 device
= pContext
->Device
;
707 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
708 alSetError(pContext
, AL_INVALID_NAME
);
714 alSetError(pContext
, AL_INVALID_ENUM
);
719 ProcessContext(pContext
);
723 AL_API
void AL_APIENTRY
alBufferfv(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
)
725 ALCcontext
*pContext
;
728 pContext
= GetContextSuspended();
729 if(!pContext
) return;
731 device
= pContext
->Device
;
733 alSetError(pContext
, AL_INVALID_VALUE
);
734 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
735 alSetError(pContext
, AL_INVALID_NAME
);
741 alSetError(pContext
, AL_INVALID_ENUM
);
746 ProcessContext(pContext
);
750 AL_API
void AL_APIENTRY
alBufferi(ALuint buffer
, ALenum eParam
, ALint lValue
)
752 ALCcontext
*pContext
;
757 pContext
= GetContextSuspended();
758 if(!pContext
) return;
760 device
= pContext
->Device
;
761 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
762 alSetError(pContext
, AL_INVALID_NAME
);
768 alSetError(pContext
, AL_INVALID_ENUM
);
773 ProcessContext(pContext
);
777 AL_API
void AL_APIENTRY
alBuffer3i( ALuint buffer
, ALenum eParam
, ALint lValue1
, ALint lValue2
, ALint lValue3
)
779 ALCcontext
*pContext
;
786 pContext
= GetContextSuspended();
787 if(!pContext
) return;
789 device
= pContext
->Device
;
790 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
791 alSetError(pContext
, AL_INVALID_NAME
);
797 alSetError(pContext
, AL_INVALID_ENUM
);
802 ProcessContext(pContext
);
806 AL_API
void AL_APIENTRY
alBufferiv(ALuint buffer
, ALenum eParam
, const ALint
* plValues
)
808 ALCcontext
*pContext
;
812 pContext
= GetContextSuspended();
813 if(!pContext
) return;
815 device
= pContext
->Device
;
817 alSetError(pContext
, AL_INVALID_VALUE
);
818 else if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
819 alSetError(pContext
, AL_INVALID_NAME
);
825 if(ALBuf
->refcount
> 0)
826 alSetError(pContext
, AL_INVALID_OPERATION
);
827 else if(plValues
[0] < 0 || plValues
[1] < 0 ||
828 plValues
[0] >= plValues
[1] || ALBuf
->size
== 0)
829 alSetError(pContext
, AL_INVALID_VALUE
);
832 ALint maxlen
= ALBuf
->size
/ aluFrameSizeFromFormat(ALBuf
->format
);
833 if(plValues
[0] > maxlen
|| plValues
[1] > maxlen
)
834 alSetError(pContext
, AL_INVALID_VALUE
);
837 ALBuf
->LoopStart
= plValues
[0];
838 ALBuf
->LoopEnd
= plValues
[1];
844 alSetError(pContext
, AL_INVALID_ENUM
);
849 ProcessContext(pContext
);
853 AL_API ALvoid AL_APIENTRY
alGetBufferf(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
)
855 ALCcontext
*pContext
;
858 pContext
= GetContextSuspended();
859 if(!pContext
) return;
861 device
= pContext
->Device
;
863 alSetError(pContext
, AL_INVALID_VALUE
);
864 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
865 alSetError(pContext
, AL_INVALID_NAME
);
871 alSetError(pContext
, AL_INVALID_ENUM
);
876 ProcessContext(pContext
);
880 AL_API
void AL_APIENTRY
alGetBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat
* pflValue1
, ALfloat
* pflValue2
, ALfloat
* pflValue3
)
882 ALCcontext
*pContext
;
885 pContext
= GetContextSuspended();
886 if(!pContext
) return;
888 device
= pContext
->Device
;
889 if(!pflValue1
|| !pflValue2
|| !pflValue3
)
890 alSetError(pContext
, AL_INVALID_VALUE
);
891 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
892 alSetError(pContext
, AL_INVALID_NAME
);
898 alSetError(pContext
, AL_INVALID_ENUM
);
903 ProcessContext(pContext
);
907 AL_API
void AL_APIENTRY
alGetBufferfv(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
)
909 ALCcontext
*pContext
;
912 pContext
= GetContextSuspended();
913 if(!pContext
) return;
915 device
= pContext
->Device
;
917 alSetError(pContext
, AL_INVALID_VALUE
);
918 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
919 alSetError(pContext
, AL_INVALID_NAME
);
925 alSetError(pContext
, AL_INVALID_ENUM
);
930 ProcessContext(pContext
);
934 AL_API ALvoid AL_APIENTRY
alGetBufferi(ALuint buffer
, ALenum eParam
, ALint
*plValue
)
936 ALCcontext
*pContext
;
940 pContext
= GetContextSuspended();
941 if(!pContext
) return;
943 device
= pContext
->Device
;
945 alSetError(pContext
, AL_INVALID_VALUE
);
946 else if((pBuffer
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
947 alSetError(pContext
, AL_INVALID_NAME
);
953 *plValue
= pBuffer
->frequency
;
957 *plValue
= aluBytesFromFormat(pBuffer
->format
) * 8;
961 *plValue
= aluChannelsFromFormat(pBuffer
->format
);
965 *plValue
= pBuffer
->size
;
969 alSetError(pContext
, AL_INVALID_ENUM
);
974 ProcessContext(pContext
);
978 AL_API
void AL_APIENTRY
alGetBuffer3i(ALuint buffer
, ALenum eParam
, ALint
* plValue1
, ALint
* plValue2
, ALint
* plValue3
)
980 ALCcontext
*pContext
;
983 pContext
= GetContextSuspended();
984 if(!pContext
) return;
986 device
= pContext
->Device
;
987 if(!plValue1
|| !plValue2
|| !plValue3
)
988 alSetError(pContext
, AL_INVALID_VALUE
);
989 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
990 alSetError(pContext
, AL_INVALID_NAME
);
996 alSetError(pContext
, AL_INVALID_ENUM
);
1001 ProcessContext(pContext
);
1005 AL_API
void AL_APIENTRY
alGetBufferiv(ALuint buffer
, ALenum eParam
, ALint
* plValues
)
1007 ALCcontext
*pContext
;
1011 pContext
= GetContextSuspended();
1012 if(!pContext
) return;
1014 device
= pContext
->Device
;
1016 alSetError(pContext
, AL_INVALID_VALUE
);
1017 else if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
1018 alSetError(pContext
, AL_INVALID_NAME
);
1027 alGetBufferi(buffer
, eParam
, plValues
);
1030 case AL_LOOP_POINTS
:
1031 plValues
[0] = ALBuf
->LoopStart
;
1032 plValues
[1] = ALBuf
->LoopEnd
;
1036 alSetError(pContext
, AL_INVALID_ENUM
);
1041 ProcessContext(pContext
);
1045 static void ConvertDataRear(ALvoid
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
)
1053 for(i
= 0;i
< len
;i
+=4)
1055 ((ALubyte
*)dst
)[i
+0] = 0;
1056 ((ALubyte
*)dst
)[i
+1] = 0;
1057 ((ALubyte
*)dst
)[i
+2] = ((ALubyte
*)src
)[i
/2+0];
1058 ((ALubyte
*)dst
)[i
+3] = ((ALubyte
*)src
)[i
/2+1];
1063 for(i
= 0;i
< len
;i
+=4)
1065 ((ALshort
*)dst
)[i
+0] = 0;
1066 ((ALshort
*)dst
)[i
+1] = 0;
1067 ((ALshort
*)dst
)[i
+2] = ((ALshort
*)src
)[i
/2+0];
1068 ((ALshort
*)dst
)[i
+3] = ((ALshort
*)src
)[i
/2+1];
1073 for(i
= 0;i
< len
;i
+=4)
1075 ((ALfloat
*)dst
)[i
+0] = 0.f
;
1076 ((ALfloat
*)dst
)[i
+1] = 0.f
;
1077 ((ALfloat
*)dst
)[i
+2] = ((ALfloat
*)src
)[i
/2+0];
1078 ((ALfloat
*)dst
)[i
+3] = ((ALfloat
*)src
)[i
/2+1];
1087 static void ConvertDataIMA4(ALvoid
*dst
, const ALvoid
*src
, ALint chans
, ALsizei len
)
1089 const ALubyte
*IMAData
;
1090 ALint Sample
[2],Index
[2];
1098 for(i
= 0;i
< len
;i
++)
1100 for(c
= 0;c
< chans
;c
++)
1102 Sample
[c
] = *(IMAData
++);
1103 Sample
[c
] |= *(IMAData
++) << 8;
1104 Sample
[c
] = (Sample
[c
]^0x8000) - 32768;
1105 Index
[c
] = *(IMAData
++);
1106 Index
[c
] |= *(IMAData
++) << 8;
1107 Index
[c
] = (Index
[c
]^0x8000) - 32768;
1109 Index
[c
] = ((Index
[c
]<0) ? 0 : Index
[c
]);
1110 Index
[c
] = ((Index
[c
]>88) ? 88 : Index
[c
]);
1112 ((ALshort
*)dst
)[i
*65*chans
+ c
] = Sample
[c
];
1115 for(j
= 1;j
< 65;j
+= 8)
1117 for(c
= 0;c
< chans
;c
++)
1119 IMACode
[c
] = *(IMAData
++);
1120 IMACode
[c
] |= *(IMAData
++) << 8;
1121 IMACode
[c
] |= *(IMAData
++) << 16;
1122 IMACode
[c
] |= *(IMAData
++) << 24;
1125 for(k
= 0;k
< 8;k
++)
1127 for(c
= 0;c
< chans
;c
++)
1129 Sample
[c
] += ((g_IMAStep_size
[Index
[c
]]*g_IMACodeword_4
[IMACode
[c
]&15])/8);
1130 Index
[c
] += g_IMAIndex_adjust_4
[IMACode
[c
]&15];
1132 if(Sample
[c
] < -32768) Sample
[c
] = -32768;
1133 else if(Sample
[c
] > 32767) Sample
[c
] = 32767;
1135 if(Index
[c
]<0) Index
[c
] = 0;
1136 else if(Index
[c
]>88) Index
[c
] = 88;
1138 ((ALshort
*)dst
)[(i
*65+j
+k
)*chans
+ c
] = Sample
[c
];
1146 static void ConvertDataMULaw(ALvoid
*dst
, const ALvoid
*src
, ALsizei len
)
1151 for(i
= 0;i
< len
;i
++)
1152 ((ALshort
*)dst
)[i
] = muLawDecompressionTable
[((ALubyte
*)src
)[i
]];
1155 static void ConvertDataMULawRear(ALvoid
*dst
, const ALvoid
*src
, ALsizei len
)
1160 for(i
= 0;i
< len
;i
+=4)
1162 ((ALshort
*)dst
)[i
+0] = 0;
1163 ((ALshort
*)dst
)[i
+1] = 0;
1164 ((ALshort
*)dst
)[i
+2] = muLawDecompressionTable
[((ALubyte
*)src
)[i
/2+0]];
1165 ((ALshort
*)dst
)[i
+3] = muLawDecompressionTable
[((ALubyte
*)src
)[i
/2+1]];
1170 static __inline ALbyte
Conv_ALbyte_ALbyte(ALbyte val
)
1172 static __inline ALbyte
Conv_ALbyte_ALubyte(ALubyte val
)
1173 { return val
^0x80; }
1174 static __inline ALbyte
Conv_ALbyte_ALshort(ALshort val
)
1176 static __inline ALbyte
Conv_ALbyte_ALushort(ALushort val
)
1177 { return (val
>>8)-128; }
1178 static __inline ALbyte
Conv_ALbyte_ALfloat(ALfloat val
)
1180 if(val
>= 1.0f
) return 127;
1181 if(val
<= -1.0f
) return -128;
1182 return (ALint
)(val
* 127.0f
);
1184 static __inline ALbyte
Conv_ALbyte_ALdouble(ALdouble val
)
1186 if(val
>= 1.0) return 127;
1187 if(val
<= -1.0) return -128;
1188 return (ALint
)(val
* 127.0);
1191 static __inline ALubyte
Conv_ALubyte_ALbyte(ALbyte val
)
1192 { return val
^0x80; }
1193 static __inline ALubyte
Conv_ALubyte_ALubyte(ALubyte val
)
1195 static __inline ALubyte
Conv_ALubyte_ALshort(ALshort val
)
1196 { return (val
>>8)+128; }
1197 static __inline ALubyte
Conv_ALubyte_ALushort(ALushort val
)
1199 static __inline ALubyte
Conv_ALubyte_ALfloat(ALfloat val
)
1201 if(val
>= 1.0f
) return 255;
1202 if(val
<= -1.0f
) return 0;
1203 return (ALint
)(val
* 127.0f
) + 128;
1205 static __inline ALubyte
Conv_ALubyte_ALdouble(ALdouble val
)
1207 if(val
>= 1.0) return 255;
1208 if(val
<= -1.0) return 0;
1209 return (ALint
)(val
* 127.0) + 128;
1212 static __inline ALshort
Conv_ALshort_ALbyte(ALbyte val
)
1214 static __inline ALshort
Conv_ALshort_ALubyte(ALubyte val
)
1215 { return (val
-128)<<8; }
1216 static __inline ALshort
Conv_ALshort_ALshort(ALshort val
)
1218 static __inline ALshort
Conv_ALshort_ALushort(ALushort val
)
1219 { return val
^0x8000; }
1220 static __inline ALshort
Conv_ALshort_ALfloat(ALfloat val
)
1222 if(val
>= 1.0f
) return 32767;
1223 if(val
<= -1.0f
) return -32768;
1224 return (ALint
)(val
* 32767.0f
);
1226 static __inline ALshort
Conv_ALshort_ALdouble(ALdouble val
)
1228 if(val
>= 1.0) return 32767;
1229 if(val
<= -1.0) return -32768;
1230 return (ALint
)(val
* 32767.0);
1233 static __inline ALushort
Conv_ALushort_ALbyte(ALbyte val
)
1234 { return (val
+128)<<8; }
1235 static __inline ALushort
Conv_ALushort_ALubyte(ALubyte val
)
1237 static __inline ALushort
Conv_ALushort_ALshort(ALshort val
)
1238 { return val
^0x8000; }
1239 static __inline ALushort
Conv_ALushort_ALushort(ALushort val
)
1241 static __inline ALushort
Conv_ALushort_ALfloat(ALfloat val
)
1243 if(val
>= 1.0f
) return 65535;
1244 if(val
<= -1.0f
) return 0;
1245 return (ALint
)(val
* 32767.0f
) + 32768;
1247 static __inline ALushort
Conv_ALushort_ALdouble(ALdouble val
)
1249 if(val
>= 1.0) return 65535;
1250 if(val
<= -1.0) return 0;
1251 return (ALint
)(val
* 32767.0) + 32768;
1254 static __inline ALfloat
Conv_ALfloat_ALbyte(ALbyte val
)
1255 { return val
* (1.0f
/127.0f
); }
1256 static __inline ALfloat
Conv_ALfloat_ALubyte(ALubyte val
)
1257 { return (val
-128) * (1.0f
/127.0f
); }
1258 static __inline ALfloat
Conv_ALfloat_ALshort(ALshort val
)
1259 { return val
* (1.0f
/32767.0f
); }
1260 static __inline ALfloat
Conv_ALfloat_ALushort(ALushort val
)
1261 { return (val
-32768) * (1.0f
/32767.0f
); }
1262 static __inline ALfloat
Conv_ALfloat_ALfloat(ALfloat val
)
1264 static __inline ALfloat
Conv_ALfloat_ALdouble(ALdouble val
)
1267 static __inline ALdouble
Conv_ALdouble_ALbyte(ALbyte val
)
1268 { return val
* (1.0/127.0); }
1269 static __inline ALdouble
Conv_ALdouble_ALubyte(ALubyte val
)
1270 { return (val
-128) * (1.0/127.0); }
1271 static __inline ALdouble
Conv_ALdouble_ALshort(ALshort val
)
1272 { return val
* (1.0/32767.0); }
1273 static __inline ALdouble
Conv_ALdouble_ALushort(ALushort val
)
1274 { return (val
-32768) * (1.0/32767.0); }
1275 static __inline ALdouble
Conv_ALdouble_ALfloat(ALfloat val
)
1277 static __inline ALdouble
Conv_ALdouble_ALdouble(ALdouble val
)
1281 #define DECL_TEMPLATE(T1, T2) \
1282 static void Convert_##T1##_##T2(T1 *dst, const T2 *src, ALuint len) \
1285 for(i = 0;i < len;i++) \
1286 *(dst++) = Conv_##T1##_##T2(*(src++)); \
1289 DECL_TEMPLATE(ALubyte
, ALbyte
)
1290 DECL_TEMPLATE(ALubyte
, ALubyte
)
1291 DECL_TEMPLATE(ALubyte
, ALshort
)
1292 DECL_TEMPLATE(ALubyte
, ALushort
)
1293 DECL_TEMPLATE(ALubyte
, ALfloat
)
1294 DECL_TEMPLATE(ALubyte
, ALdouble
)
1296 DECL_TEMPLATE(ALbyte
, ALbyte
)
1297 DECL_TEMPLATE(ALbyte
, ALubyte
)
1298 DECL_TEMPLATE(ALbyte
, ALshort
)
1299 DECL_TEMPLATE(ALbyte
, ALushort
)
1300 DECL_TEMPLATE(ALbyte
, ALfloat
)
1301 DECL_TEMPLATE(ALbyte
, ALdouble
)
1303 DECL_TEMPLATE(ALshort
, ALbyte
)
1304 DECL_TEMPLATE(ALshort
, ALubyte
)
1305 DECL_TEMPLATE(ALshort
, ALshort
)
1306 DECL_TEMPLATE(ALshort
, ALushort
)
1307 DECL_TEMPLATE(ALshort
, ALfloat
)
1308 DECL_TEMPLATE(ALshort
, ALdouble
)
1310 DECL_TEMPLATE(ALushort
, ALbyte
)
1311 DECL_TEMPLATE(ALushort
, ALubyte
)
1312 DECL_TEMPLATE(ALushort
, ALshort
)
1313 DECL_TEMPLATE(ALushort
, ALushort
)
1314 DECL_TEMPLATE(ALushort
, ALfloat
)
1315 DECL_TEMPLATE(ALushort
, ALdouble
)
1317 DECL_TEMPLATE(ALfloat
, ALbyte
)
1318 DECL_TEMPLATE(ALfloat
, ALubyte
)
1319 DECL_TEMPLATE(ALfloat
, ALshort
)
1320 DECL_TEMPLATE(ALfloat
, ALushort
)
1321 DECL_TEMPLATE(ALfloat
, ALfloat
)
1322 DECL_TEMPLATE(ALfloat
, ALdouble
)
1324 DECL_TEMPLATE(ALdouble
, ALbyte
)
1325 DECL_TEMPLATE(ALdouble
, ALubyte
)
1326 DECL_TEMPLATE(ALdouble
, ALshort
)
1327 DECL_TEMPLATE(ALdouble
, ALushort
)
1328 DECL_TEMPLATE(ALdouble
, ALfloat
)
1329 DECL_TEMPLATE(ALdouble
, ALdouble
)
1331 #undef DECL_TEMPLATE
1333 #define DECL_TEMPLATE(T) \
1334 static void Convert_##T(T *dst, const ALvoid *src, enum SrcFmtType srcType, \
1340 Convert_##T##_ALbyte(dst, src, len); \
1343 Convert_##T##_ALubyte(dst, src, len); \
1346 Convert_##T##_ALshort(dst, src, len); \
1348 case SrcFmtUShort: \
1349 Convert_##T##_ALushort(dst, src, len); \
1352 Convert_##T##_ALfloat(dst, src, len); \
1354 case SrcFmtDouble: \
1355 Convert_##T##_ALdouble(dst, src, len); \
1360 DECL_TEMPLATE(ALbyte
)
1361 DECL_TEMPLATE(ALubyte
)
1362 DECL_TEMPLATE(ALshort
)
1363 DECL_TEMPLATE(ALushort
)
1364 DECL_TEMPLATE(ALfloat
)
1365 DECL_TEMPLATE(ALdouble
)
1367 #undef DECL_TEMPLATE
1373 * Loads the specified data into the buffer, using the specified formats.
1374 * Currently, the new format must have the same channel configuration as the
1375 * original format. This does NOT handle compressed formats (eg. IMA4).
1377 static ALenum
LoadData(ALbuffer
*ALBuf
, const ALvoid
*data
, ALsizei size
, ALuint freq
, ALenum OrigFormat
, ALenum NewFormat
)
1379 ALuint NewBytes
= aluBytesFromFormat(NewFormat
);
1380 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
1381 ALuint OrigBytes
= aluBytesFromFormat(OrigFormat
);
1382 ALuint OrigChannels
= aluChannelsFromFormat(OrigFormat
);
1383 enum SrcFmtChannels SrcChannels
;
1384 enum FmtChannels DstChannels
;
1385 enum SrcFmtType SrcType
;
1386 enum FmtType DstType
;
1390 assert(NewChannels
== OrigChannels
);
1392 DecomposeInputFormat(OrigFormat
, &SrcType
, &SrcChannels
);
1393 DecomposeFormat(NewFormat
, &DstType
, &DstChannels
);
1395 if((size
%(OrigBytes
*OrigChannels
)) != 0)
1396 return AL_INVALID_VALUE
;
1398 newsize
= size
/ OrigBytes
;
1399 newsize
*= NewBytes
;
1400 if(newsize
> INT_MAX
)
1401 return AL_OUT_OF_MEMORY
;
1403 temp
= realloc(ALBuf
->data
, newsize
);
1404 if(!temp
) return AL_OUT_OF_MEMORY
;
1409 // Samples are converted here
1410 ConvertData(ALBuf
->data
, DstType
, data
, SrcType
, newsize
/NewBytes
);
1413 ALBuf
->format
= NewFormat
;
1414 ALBuf
->eOriginalFormat
= OrigFormat
;
1415 ALBuf
->size
= newsize
;
1416 ALBuf
->frequency
= freq
;
1418 ALBuf
->LoopStart
= 0;
1419 ALBuf
->LoopEnd
= newsize
/ NewChannels
/ NewBytes
;
1421 ALBuf
->FmtType
= DstType
;
1422 ALBuf
->FmtChannels
= DstChannels
;
1424 ALBuf
->OriginalSize
= size
;
1425 ALBuf
->OriginalAlign
= OrigBytes
* OrigChannels
;
1430 static void ConvertData(ALvoid
*dst
, enum FmtType dstType
, const ALvoid
*src
, enum SrcFmtType srcType
, ALsizei len
)
1434 (void)Convert_ALbyte
;
1436 Convert_ALubyte(dst
, src
, srcType
, len
);
1439 Convert_ALshort(dst
, src
, srcType
, len
);
1441 (void)Convert_ALushort
;
1443 Convert_ALfloat(dst
, src
, srcType
, len
);
1446 Convert_ALdouble(dst
, src
, srcType
, len
);
1452 void DecomposeInputFormat(ALenum format
, enum SrcFmtType
*type
,
1453 enum SrcFmtChannels
*order
)
1457 case AL_FORMAT_MONO8
:
1458 *type
= SrcFmtUByte
;
1459 *order
= SrcFmtMono
;
1461 case AL_FORMAT_MONO16
:
1462 *type
= SrcFmtShort
;
1463 *order
= SrcFmtMono
;
1465 case AL_FORMAT_MONO_FLOAT32
:
1466 *type
= SrcFmtFloat
;
1467 *order
= SrcFmtMono
;
1469 case AL_FORMAT_MONO_DOUBLE_EXT
:
1470 *type
= SrcFmtDouble
;
1471 *order
= SrcFmtMono
;
1473 case AL_FORMAT_STEREO8
:
1474 *type
= SrcFmtUByte
;
1475 *order
= SrcFmtStereo
;
1477 case AL_FORMAT_STEREO16
:
1478 *type
= SrcFmtShort
;
1479 *order
= SrcFmtStereo
;
1481 case AL_FORMAT_STEREO_FLOAT32
:
1482 *type
= SrcFmtFloat
;
1483 *order
= SrcFmtStereo
;
1485 case AL_FORMAT_STEREO_DOUBLE_EXT
:
1486 *type
= SrcFmtDouble
;
1487 *order
= SrcFmtStereo
;
1489 case AL_FORMAT_QUAD8_LOKI
:
1490 case AL_FORMAT_QUAD8
:
1491 *type
= SrcFmtUByte
;
1492 *order
= SrcFmtQuad
;
1494 case AL_FORMAT_QUAD16_LOKI
:
1495 case AL_FORMAT_QUAD16
:
1496 *type
= SrcFmtShort
;
1497 *order
= SrcFmtQuad
;
1499 case AL_FORMAT_QUAD32
:
1500 *type
= SrcFmtFloat
;
1501 *order
= SrcFmtQuad
;
1503 case AL_FORMAT_51CHN8
:
1504 *type
= SrcFmtUByte
;
1507 case AL_FORMAT_51CHN16
:
1508 *type
= SrcFmtShort
;
1511 case AL_FORMAT_51CHN32
:
1512 *type
= SrcFmtFloat
;
1515 case AL_FORMAT_61CHN8
:
1516 *type
= SrcFmtUByte
;
1519 case AL_FORMAT_61CHN16
:
1520 *type
= SrcFmtShort
;
1523 case AL_FORMAT_61CHN32
:
1524 *type
= SrcFmtFloat
;
1527 case AL_FORMAT_71CHN8
:
1528 *type
= SrcFmtUByte
;
1531 case AL_FORMAT_71CHN16
:
1532 *type
= SrcFmtShort
;
1535 case AL_FORMAT_71CHN32
:
1536 *type
= SrcFmtFloat
;
1541 AL_PRINT("Unhandled format specified: 0x%X\n", format
);
1546 void DecomposeFormat(ALenum format
, enum FmtType
*type
, enum FmtChannels
*order
)
1550 case AL_FORMAT_MONO8
:
1554 case AL_FORMAT_MONO16
:
1558 case AL_FORMAT_MONO_FLOAT32
:
1562 case AL_FORMAT_MONO_DOUBLE_EXT
:
1566 case AL_FORMAT_STEREO8
:
1570 case AL_FORMAT_STEREO16
:
1574 case AL_FORMAT_STEREO_FLOAT32
:
1578 case AL_FORMAT_STEREO_DOUBLE_EXT
:
1582 case AL_FORMAT_QUAD8_LOKI
:
1583 case AL_FORMAT_QUAD8
:
1587 case AL_FORMAT_QUAD16_LOKI
:
1588 case AL_FORMAT_QUAD16
:
1592 case AL_FORMAT_QUAD32
:
1596 case AL_FORMAT_51CHN8
:
1598 *order
= Fmt51ChanWFX
;
1600 case AL_FORMAT_51CHN16
:
1602 *order
= Fmt51ChanWFX
;
1604 case AL_FORMAT_51CHN32
:
1606 *order
= Fmt51ChanWFX
;
1608 case AL_FORMAT_61CHN8
:
1610 *order
= Fmt61ChanWFX
;
1612 case AL_FORMAT_61CHN16
:
1614 *order
= Fmt61ChanWFX
;
1616 case AL_FORMAT_61CHN32
:
1618 *order
= Fmt61ChanWFX
;
1620 case AL_FORMAT_71CHN8
:
1622 *order
= Fmt71ChanWFX
;
1624 case AL_FORMAT_71CHN16
:
1626 *order
= Fmt71ChanWFX
;
1628 case AL_FORMAT_71CHN32
:
1630 *order
= Fmt71ChanWFX
;
1634 AL_PRINT("Unhandled format specified: 0x%X\n", format
);
1641 * ReleaseALBuffers()
1643 * INTERNAL FN : Called by alcCloseDevice to destroy any buffers that still exist
1645 ALvoid
ReleaseALBuffers(ALCdevice
*device
)
1648 for(i
= 0;i
< device
->BufferMap
.size
;i
++)
1650 ALbuffer
*temp
= device
->BufferMap
.array
[i
].value
;
1651 device
->BufferMap
.array
[i
].value
= NULL
;
1653 // Release sample data
1656 // Release Buffer structure
1657 ALTHUNK_REMOVEENTRY(temp
->buffer
);
1658 memset(temp
, 0, sizeof(ALbuffer
));