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
, ALuint freq
, ALenum NewFormat
, ALsizei size
, enum SrcFmtChannels chans
, enum SrcFmtType type
, const ALvoid
*data
);
38 static void ConvertData(ALvoid
*dst
, enum FmtType dstType
, const ALvoid
*src
, enum SrcFmtType srcType
, ALsizei len
);
39 static void ConvertDataIMA4(ALvoid
*dst
, enum FmtType dstType
, const ALvoid
*src
, ALint chans
, ALsizei len
);
41 #define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k)))
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
67 static const ALshort muLawDecompressionTable
[256] = {
68 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
69 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
70 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
71 -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
72 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
73 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
74 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
75 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
76 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
77 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
78 -876, -844, -812, -780, -748, -716, -684, -652,
79 -620, -588, -556, -524, -492, -460, -428, -396,
80 -372, -356, -340, -324, -308, -292, -276, -260,
81 -244, -228, -212, -196, -180, -164, -148, -132,
82 -120, -112, -104, -96, -88, -80, -72, -64,
83 -56, -48, -40, -32, -24, -16, -8, 0,
84 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
85 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
86 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
87 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
88 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
89 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
90 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
91 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
92 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
93 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
94 876, 844, 812, 780, 748, 716, 684, 652,
95 620, 588, 556, 524, 492, 460, 428, 396,
96 372, 356, 340, 324, 308, 292, 276, 260,
97 244, 228, 212, 196, 180, 164, 148, 132,
98 120, 112, 104, 96, 88, 80, 72, 64,
99 56, 48, 40, 32, 24, 16, 8, 0
103 * alGenBuffers(ALsizei n, ALuint *buffers)
105 * Generates n AL Buffers, and stores the Buffers Names in the array pointed to by buffers
107 AL_API ALvoid AL_APIENTRY
alGenBuffers(ALsizei n
, ALuint
*buffers
)
112 Context
= GetContextSuspended();
115 // Check that we are actually generating some Buffers
116 if(n
< 0 || IsBadWritePtr((void*)buffers
, n
* sizeof(ALuint
)))
117 alSetError(Context
, AL_INVALID_VALUE
);
120 ALCdevice
*device
= Context
->Device
;
123 // Create all the new Buffers
126 ALbuffer
*buffer
= calloc(1, sizeof(ALbuffer
));
129 alSetError(Context
, AL_OUT_OF_MEMORY
);
130 alDeleteBuffers(i
, buffers
);
134 buffer
->buffer
= (ALuint
)ALTHUNK_ADDENTRY(buffer
);
135 err
= InsertUIntMapEntry(&device
->BufferMap
, buffer
->buffer
, buffer
);
136 if(err
!= AL_NO_ERROR
)
138 ALTHUNK_REMOVEENTRY(buffer
->buffer
);
139 memset(buffer
, 0, sizeof(ALbuffer
));
142 alSetError(Context
, err
);
143 alDeleteBuffers(i
, buffers
);
146 buffers
[i
++] = buffer
->buffer
;
150 ProcessContext(Context
);
154 * alDeleteBuffers(ALsizei n, ALuint *buffers)
156 * Deletes the n AL Buffers pointed to by buffers
158 AL_API ALvoid AL_APIENTRY
alDeleteBuffers(ALsizei n
, const ALuint
*buffers
)
166 Context
= GetContextSuspended();
170 device
= Context
->Device
;
171 /* Check we are actually Deleting some Buffers */
173 alSetError(Context
, AL_INVALID_VALUE
);
178 /* Check that all the buffers are valid and can actually be deleted */
184 /* Check for valid Buffer ID */
185 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffers
[i
])) == NULL
)
187 alSetError(Context
, AL_INVALID_NAME
);
191 else if(ALBuf
->refcount
!= 0)
193 /* Buffer still in use, cannot be deleted */
194 alSetError(Context
, AL_INVALID_OPERATION
);
201 /* If all the Buffers were valid (and have Reference Counts of 0), then we can delete them */
206 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffers
[i
])) == NULL
)
209 /* Release the memory used to store audio data */
212 /* Release buffer structure */
213 RemoveUIntMapKey(&device
->BufferMap
, ALBuf
->buffer
);
214 ALTHUNK_REMOVEENTRY(ALBuf
->buffer
);
216 memset(ALBuf
, 0, sizeof(ALbuffer
));
221 ProcessContext(Context
);
225 * alIsBuffer(ALuint buffer)
227 * Checks if buffer is a valid Buffer Name
229 AL_API ALboolean AL_APIENTRY
alIsBuffer(ALuint buffer
)
234 Context
= GetContextSuspended();
235 if(!Context
) return AL_FALSE
;
237 result
= ((!buffer
|| LookupBuffer(Context
->Device
->BufferMap
, buffer
)) ?
240 ProcessContext(Context
);
246 * alBufferData(ALuint buffer,ALenum format,const ALvoid *data,ALsizei size,ALsizei freq)
248 * Fill buffer with audio data
250 AL_API ALvoid AL_APIENTRY
alBufferData(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei size
,ALsizei freq
)
252 enum SrcFmtChannels SrcChannels
;
253 enum SrcFmtType SrcType
;
259 Context
= GetContextSuspended();
262 if(Context
->SampleSource
)
266 if(Context
->SampleSource
->state
== MAPPED
)
268 alSetError(Context
, AL_INVALID_OPERATION
);
269 ProcessContext(Context
);
273 offset
= (const ALubyte
*)data
- (ALubyte
*)NULL
;
274 data
= Context
->SampleSource
->data
+ offset
;
277 device
= Context
->Device
;
278 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
279 alSetError(Context
, AL_INVALID_NAME
);
280 else if(ALBuf
->refcount
!= 0)
281 alSetError(Context
, AL_INVALID_VALUE
);
282 else if(size
< 0 || freq
< 0)
283 alSetError(Context
, AL_INVALID_VALUE
);
284 else if(DecomposeInputFormat(format
, &SrcChannels
, &SrcType
) == AL_FALSE
)
285 alSetError(Context
, AL_INVALID_ENUM
);
295 err
= LoadData(ALBuf
, freq
, format
, size
, SrcChannels
, SrcType
, data
);
296 if(err
!= AL_NO_ERROR
)
297 alSetError(Context
, err
);
301 if(SrcChannels
== SrcFmtMono
)
302 err
= LoadData(ALBuf
, freq
, AL_FORMAT_MONO_FLOAT32
, size
, SrcChannels
, SrcType
, data
);
304 err
= LoadData(ALBuf
, freq
, AL_FORMAT_STEREO_FLOAT32
, size
, SrcChannels
, SrcType
, data
);
305 if(err
!= AL_NO_ERROR
)
306 alSetError(Context
, err
);
311 ALenum NewFormat
= AL_FORMAT_MONO16
;
314 case SrcFmtMono
: NewFormat
= AL_FORMAT_MONO16
; break;
315 case SrcFmtStereo
: NewFormat
= AL_FORMAT_STEREO16
; break;
316 case SrcFmtRear
: NewFormat
= AL_FORMAT_REAR16
; break;
317 case SrcFmtQuad
: NewFormat
= AL_FORMAT_QUAD16
; break;
318 case SrcFmtX51
: NewFormat
= AL_FORMAT_51CHN16
; break;
319 case SrcFmtX61
: NewFormat
= AL_FORMAT_61CHN16
; break;
320 case SrcFmtX71
: NewFormat
= AL_FORMAT_71CHN16
; break;
322 err
= LoadData(ALBuf
, freq
, NewFormat
, size
, SrcChannels
, SrcType
, data
);
323 if(err
!= AL_NO_ERROR
)
324 alSetError(Context
, err
);
328 ProcessContext(Context
);
332 * alBufferSubDataSOFT(ALuint buffer,ALenum format,const ALvoid *data,ALsizei offset,ALsizei length)
334 * Update buffer's audio data
336 AL_API ALvoid AL_APIENTRY
alBufferSubDataSOFT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
338 enum SrcFmtChannels SrcChannels
;
339 enum SrcFmtType SrcType
;
344 Context
= GetContextSuspended();
347 if(Context
->SampleSource
)
351 if(Context
->SampleSource
->state
== MAPPED
)
353 alSetError(Context
, AL_INVALID_OPERATION
);
354 ProcessContext(Context
);
358 offset
= (const ALubyte
*)data
- (ALubyte
*)NULL
;
359 data
= Context
->SampleSource
->data
+ offset
;
362 device
= Context
->Device
;
363 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
364 alSetError(Context
, AL_INVALID_NAME
);
365 else if(length
< 0 || offset
< 0 || (length
> 0 && data
== NULL
))
366 alSetError(Context
, AL_INVALID_VALUE
);
367 else if(DecomposeInputFormat(format
, &SrcChannels
, &SrcType
) == AL_FALSE
||
368 SrcChannels
!= ALBuf
->OriginalChannels
||
369 SrcType
!= ALBuf
->OriginalType
)
370 alSetError(Context
, AL_INVALID_ENUM
);
371 else if(offset
> ALBuf
->OriginalSize
||
372 length
> ALBuf
->OriginalSize
-offset
||
373 (offset
%ALBuf
->OriginalAlign
) != 0 ||
374 (length
%ALBuf
->OriginalAlign
) != 0)
375 alSetError(Context
, AL_INVALID_VALUE
);
378 if(SrcType
== SrcFmtIMA4
)
380 ALuint Channels
= ChannelsFromFmt(ALBuf
->FmtChannels
);
381 ALuint Bytes
= BytesFromFmt(ALBuf
->FmtType
);
383 /* offset -> byte offset, length -> block count */
387 length
/= ALBuf
->OriginalAlign
;
389 ConvertDataIMA4(&((ALubyte
*)ALBuf
->data
)[offset
], ALBuf
->FmtType
,
390 data
, Channels
, length
);
394 ALuint OldBytes
= BytesFromFmt(SrcType
);
395 ALuint Bytes
= BytesFromFmt(ALBuf
->FmtType
);
401 ConvertData(&((ALubyte
*)ALBuf
->data
)[offset
], ALBuf
->FmtType
,
402 data
, SrcType
, length
);
406 ProcessContext(Context
);
409 AL_API ALvoid AL_APIENTRY
alBufferSubDataEXT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
411 alBufferSubDataSOFT(buffer
, format
, data
, offset
, length
);
415 AL_API
void AL_APIENTRY
alBufferf(ALuint buffer
, ALenum eParam
, ALfloat flValue
)
417 ALCcontext
*pContext
;
422 pContext
= GetContextSuspended();
423 if(!pContext
) return;
425 device
= pContext
->Device
;
426 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
427 alSetError(pContext
, AL_INVALID_NAME
);
433 alSetError(pContext
, AL_INVALID_ENUM
);
438 ProcessContext(pContext
);
442 AL_API
void AL_APIENTRY
alBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat flValue1
, ALfloat flValue2
, ALfloat flValue3
)
444 ALCcontext
*pContext
;
451 pContext
= GetContextSuspended();
452 if(!pContext
) return;
454 device
= pContext
->Device
;
455 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
456 alSetError(pContext
, AL_INVALID_NAME
);
462 alSetError(pContext
, AL_INVALID_ENUM
);
467 ProcessContext(pContext
);
471 AL_API
void AL_APIENTRY
alBufferfv(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
)
473 ALCcontext
*pContext
;
476 pContext
= GetContextSuspended();
477 if(!pContext
) return;
479 device
= pContext
->Device
;
481 alSetError(pContext
, AL_INVALID_VALUE
);
482 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
483 alSetError(pContext
, AL_INVALID_NAME
);
489 alSetError(pContext
, AL_INVALID_ENUM
);
494 ProcessContext(pContext
);
498 AL_API
void AL_APIENTRY
alBufferi(ALuint buffer
, ALenum eParam
, ALint lValue
)
500 ALCcontext
*pContext
;
505 pContext
= GetContextSuspended();
506 if(!pContext
) return;
508 device
= pContext
->Device
;
509 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
510 alSetError(pContext
, AL_INVALID_NAME
);
516 alSetError(pContext
, AL_INVALID_ENUM
);
521 ProcessContext(pContext
);
525 AL_API
void AL_APIENTRY
alBuffer3i( ALuint buffer
, ALenum eParam
, ALint lValue1
, ALint lValue2
, ALint lValue3
)
527 ALCcontext
*pContext
;
534 pContext
= GetContextSuspended();
535 if(!pContext
) return;
537 device
= pContext
->Device
;
538 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
539 alSetError(pContext
, AL_INVALID_NAME
);
545 alSetError(pContext
, AL_INVALID_ENUM
);
550 ProcessContext(pContext
);
554 AL_API
void AL_APIENTRY
alBufferiv(ALuint buffer
, ALenum eParam
, const ALint
* plValues
)
556 ALCcontext
*pContext
;
560 pContext
= GetContextSuspended();
561 if(!pContext
) return;
563 device
= pContext
->Device
;
565 alSetError(pContext
, AL_INVALID_VALUE
);
566 else if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
567 alSetError(pContext
, AL_INVALID_NAME
);
573 if(ALBuf
->refcount
> 0)
574 alSetError(pContext
, AL_INVALID_OPERATION
);
575 else if(plValues
[0] < 0 || plValues
[1] < 0 ||
576 plValues
[0] >= plValues
[1] || ALBuf
->size
== 0)
577 alSetError(pContext
, AL_INVALID_VALUE
);
580 ALint maxlen
= ALBuf
->size
/
581 FrameSizeFromFmt(ALBuf
->FmtChannels
, ALBuf
->FmtType
);
582 if(plValues
[0] > maxlen
|| plValues
[1] > maxlen
)
583 alSetError(pContext
, AL_INVALID_VALUE
);
586 ALBuf
->LoopStart
= plValues
[0];
587 ALBuf
->LoopEnd
= plValues
[1];
593 alSetError(pContext
, AL_INVALID_ENUM
);
598 ProcessContext(pContext
);
602 AL_API ALvoid AL_APIENTRY
alGetBufferf(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
)
604 ALCcontext
*pContext
;
607 pContext
= GetContextSuspended();
608 if(!pContext
) return;
610 device
= pContext
->Device
;
612 alSetError(pContext
, AL_INVALID_VALUE
);
613 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
614 alSetError(pContext
, AL_INVALID_NAME
);
620 alSetError(pContext
, AL_INVALID_ENUM
);
625 ProcessContext(pContext
);
629 AL_API
void AL_APIENTRY
alGetBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat
* pflValue1
, ALfloat
* pflValue2
, ALfloat
* pflValue3
)
631 ALCcontext
*pContext
;
634 pContext
= GetContextSuspended();
635 if(!pContext
) return;
637 device
= pContext
->Device
;
638 if(!pflValue1
|| !pflValue2
|| !pflValue3
)
639 alSetError(pContext
, AL_INVALID_VALUE
);
640 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
641 alSetError(pContext
, AL_INVALID_NAME
);
647 alSetError(pContext
, AL_INVALID_ENUM
);
652 ProcessContext(pContext
);
656 AL_API
void AL_APIENTRY
alGetBufferfv(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
)
658 ALCcontext
*pContext
;
661 pContext
= GetContextSuspended();
662 if(!pContext
) return;
664 device
= pContext
->Device
;
666 alSetError(pContext
, AL_INVALID_VALUE
);
667 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
668 alSetError(pContext
, AL_INVALID_NAME
);
674 alSetError(pContext
, AL_INVALID_ENUM
);
679 ProcessContext(pContext
);
683 AL_API ALvoid AL_APIENTRY
alGetBufferi(ALuint buffer
, ALenum eParam
, ALint
*plValue
)
685 ALCcontext
*pContext
;
689 pContext
= GetContextSuspended();
690 if(!pContext
) return;
692 device
= pContext
->Device
;
694 alSetError(pContext
, AL_INVALID_VALUE
);
695 else if((pBuffer
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
696 alSetError(pContext
, AL_INVALID_NAME
);
702 *plValue
= pBuffer
->Frequency
;
706 *plValue
= BytesFromFmt(pBuffer
->FmtType
) * 8;
710 *plValue
= ChannelsFromFmt(pBuffer
->FmtChannels
);
714 *plValue
= pBuffer
->size
;
718 alSetError(pContext
, AL_INVALID_ENUM
);
723 ProcessContext(pContext
);
727 AL_API
void AL_APIENTRY
alGetBuffer3i(ALuint buffer
, ALenum eParam
, ALint
* plValue1
, ALint
* plValue2
, ALint
* plValue3
)
729 ALCcontext
*pContext
;
732 pContext
= GetContextSuspended();
733 if(!pContext
) return;
735 device
= pContext
->Device
;
736 if(!plValue1
|| !plValue2
|| !plValue3
)
737 alSetError(pContext
, AL_INVALID_VALUE
);
738 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
739 alSetError(pContext
, AL_INVALID_NAME
);
745 alSetError(pContext
, AL_INVALID_ENUM
);
750 ProcessContext(pContext
);
754 AL_API
void AL_APIENTRY
alGetBufferiv(ALuint buffer
, ALenum eParam
, ALint
* plValues
)
756 ALCcontext
*pContext
;
760 pContext
= GetContextSuspended();
761 if(!pContext
) return;
763 device
= pContext
->Device
;
765 alSetError(pContext
, AL_INVALID_VALUE
);
766 else if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
767 alSetError(pContext
, AL_INVALID_NAME
);
776 alGetBufferi(buffer
, eParam
, plValues
);
780 plValues
[0] = ALBuf
->LoopStart
;
781 plValues
[1] = ALBuf
->LoopEnd
;
785 alSetError(pContext
, AL_INVALID_ENUM
);
790 ProcessContext(pContext
);
794 static void ConvertIMA4Block(ALshort
*dst
, const ALubyte
*IMAData
, ALint numchans
)
796 ALint Sample
[2],Index
[2];
800 for(c
= 0;c
< numchans
;c
++)
802 Sample
[c
] = *(IMAData
++);
803 Sample
[c
] |= *(IMAData
++) << 8;
804 Sample
[c
] = (Sample
[c
]^0x8000) - 32768;
805 Index
[c
] = *(IMAData
++);
806 Index
[c
] |= *(IMAData
++) << 8;
807 Index
[c
] = (Index
[c
]^0x8000) - 32768;
809 Index
[c
] = ((Index
[c
]<0) ? 0 : Index
[c
]);
810 Index
[c
] = ((Index
[c
]>88) ? 88 : Index
[c
]);
818 for(c
= 0;c
< numchans
;c
++)
820 IMACode
[c
] = *(IMAData
++);
821 IMACode
[c
] |= *(IMAData
++) << 8;
822 IMACode
[c
] |= *(IMAData
++) << 16;
823 IMACode
[c
] |= *(IMAData
++) << 24;
826 for(k
= 0;k
< 8;k
++,j
++)
828 for(c
= 0;c
< numchans
;c
++)
830 Sample
[c
] += ((g_IMAStep_size
[Index
[c
]]*g_IMACodeword_4
[IMACode
[c
]&15])/8);
831 Index
[c
] += g_IMAIndex_adjust_4
[IMACode
[c
]&15];
833 if(Sample
[c
] < -32768) Sample
[c
] = -32768;
834 else if(Sample
[c
] > 32767) Sample
[c
] = 32767;
836 if(Index
[c
]<0) Index
[c
] = 0;
837 else if(Index
[c
]>88) Index
[c
] = 88;
839 dst
[(j
+k
)*numchans
+ c
] = Sample
[c
];
847 typedef ALubyte ALmulaw
;
849 static __inline ALbyte
Conv_ALbyte_ALbyte(ALbyte val
)
851 static __inline ALbyte
Conv_ALbyte_ALubyte(ALubyte val
)
853 static __inline ALbyte
Conv_ALbyte_ALshort(ALshort val
)
855 static __inline ALbyte
Conv_ALbyte_ALushort(ALushort val
)
856 { return (val
>>8)-128; }
857 static __inline ALbyte
Conv_ALbyte_ALint(ALint val
)
859 static __inline ALbyte
Conv_ALbyte_ALuint(ALuint val
)
860 { return (val
>>24)-128; }
861 static __inline ALbyte
Conv_ALbyte_ALfloat(ALfloat val
)
863 if(val
>= 1.0f
) return 127;
864 if(val
<= -1.0f
) return -128;
865 return (ALint
)(val
* 127.0f
);
867 static __inline ALbyte
Conv_ALbyte_ALdouble(ALdouble val
)
869 if(val
>= 1.0) return 127;
870 if(val
<= -1.0) return -128;
871 return (ALint
)(val
* 127.0);
873 static __inline ALbyte
Conv_ALbyte_ALmulaw(ALmulaw val
)
874 { return muLawDecompressionTable
[val
]>>8; }
876 static __inline ALubyte
Conv_ALubyte_ALbyte(ALbyte val
)
878 static __inline ALubyte
Conv_ALubyte_ALubyte(ALubyte val
)
880 static __inline ALubyte
Conv_ALubyte_ALshort(ALshort val
)
881 { return (val
>>8)+128; }
882 static __inline ALubyte
Conv_ALubyte_ALushort(ALushort val
)
884 static __inline ALubyte
Conv_ALubyte_ALint(ALint val
)
885 { return (val
>>24)+128; }
886 static __inline ALubyte
Conv_ALubyte_ALuint(ALuint val
)
888 static __inline ALubyte
Conv_ALubyte_ALfloat(ALfloat val
)
890 if(val
>= 1.0f
) return 255;
891 if(val
<= -1.0f
) return 0;
892 return (ALint
)(val
* 127.0f
) + 128;
894 static __inline ALubyte
Conv_ALubyte_ALdouble(ALdouble val
)
896 if(val
>= 1.0) return 255;
897 if(val
<= -1.0) return 0;
898 return (ALint
)(val
* 127.0) + 128;
900 static __inline ALubyte
Conv_ALubyte_ALmulaw(ALmulaw val
)
901 { return (muLawDecompressionTable
[val
]>>8)+128; }
903 static __inline ALshort
Conv_ALshort_ALbyte(ALbyte val
)
905 static __inline ALshort
Conv_ALshort_ALubyte(ALubyte val
)
906 { return (val
-128)<<8; }
907 static __inline ALshort
Conv_ALshort_ALshort(ALshort val
)
909 static __inline ALshort
Conv_ALshort_ALushort(ALushort val
)
910 { return val
^0x8000; }
911 static __inline ALshort
Conv_ALshort_ALint(ALint val
)
913 static __inline ALshort
Conv_ALshort_ALuint(ALuint val
)
914 { return (val
>>16)-32768; }
915 static __inline ALshort
Conv_ALshort_ALfloat(ALfloat val
)
917 if(val
>= 1.0f
) return 32767;
918 if(val
<= -1.0f
) return -32768;
919 return (ALint
)(val
* 32767.0f
);
921 static __inline ALshort
Conv_ALshort_ALdouble(ALdouble val
)
923 if(val
>= 1.0) return 32767;
924 if(val
<= -1.0) return -32768;
925 return (ALint
)(val
* 32767.0);
927 static __inline ALshort
Conv_ALshort_ALmulaw(ALmulaw val
)
928 { return muLawDecompressionTable
[val
]; }
930 static __inline ALushort
Conv_ALushort_ALbyte(ALbyte val
)
931 { return (val
+128)<<8; }
932 static __inline ALushort
Conv_ALushort_ALubyte(ALubyte val
)
934 static __inline ALushort
Conv_ALushort_ALshort(ALshort val
)
935 { return val
^0x8000; }
936 static __inline ALushort
Conv_ALushort_ALushort(ALushort val
)
938 static __inline ALushort
Conv_ALushort_ALint(ALint val
)
939 { return (val
>>16)+32768; }
940 static __inline ALushort
Conv_ALushort_ALuint(ALuint val
)
942 static __inline ALushort
Conv_ALushort_ALfloat(ALfloat val
)
944 if(val
>= 1.0f
) return 65535;
945 if(val
<= -1.0f
) return 0;
946 return (ALint
)(val
* 32767.0f
) + 32768;
948 static __inline ALushort
Conv_ALushort_ALdouble(ALdouble val
)
950 if(val
>= 1.0) return 65535;
951 if(val
<= -1.0) return 0;
952 return (ALint
)(val
* 32767.0) + 32768;
954 static __inline ALushort
Conv_ALushort_ALmulaw(ALmulaw val
)
955 { return muLawDecompressionTable
[val
]^0x8000; }
957 static __inline ALint
Conv_ALint_ALbyte(ALbyte val
)
959 static __inline ALint
Conv_ALint_ALubyte(ALubyte val
)
960 { return (val
-128)<<24; }
961 static __inline ALint
Conv_ALint_ALshort(ALshort val
)
963 static __inline ALint
Conv_ALint_ALushort(ALushort val
)
964 { return (val
-32768)<<16; }
965 static __inline ALint
Conv_ALint_ALint(ALint val
)
967 static __inline ALint
Conv_ALint_ALuint(ALuint val
)
968 { return val
-2147483648u; }
969 static __inline ALint
Conv_ALint_ALfloat(ALfloat val
)
971 if(val
>= 1.0f
) return 2147483647;
972 if(val
<= -1.0f
) return -2147483648u;
973 return (ALint
)(val
* 2147483647.0);
975 static __inline ALint
Conv_ALint_ALdouble(ALdouble val
)
977 if(val
>= 1.0) return 2147483647;
978 if(val
<= -1.0) return -2147483648u;
979 return (ALint
)(val
* 2147483647.0);
981 static __inline ALint
Conv_ALint_ALmulaw(ALmulaw val
)
982 { return muLawDecompressionTable
[val
]<<16; }
984 static __inline ALuint
Conv_ALuint_ALbyte(ALbyte val
)
985 { return (val
+128)<<24; }
986 static __inline ALuint
Conv_ALuint_ALubyte(ALubyte val
)
988 static __inline ALuint
Conv_ALuint_ALshort(ALshort val
)
989 { return (val
+32768)<<16; }
990 static __inline ALuint
Conv_ALuint_ALushort(ALushort val
)
992 static __inline ALuint
Conv_ALuint_ALint(ALint val
)
993 { return val
+2147483648u; }
994 static __inline ALuint
Conv_ALuint_ALuint(ALuint val
)
996 static __inline ALuint
Conv_ALuint_ALfloat(ALfloat val
)
998 if(val
>= 1.0f
) return 4294967295u;
999 if(val
<= -1.0f
) return 0;
1000 return (ALint
)(val
* 2147483647.0) + 2147483648u;
1002 static __inline ALuint
Conv_ALuint_ALdouble(ALdouble val
)
1004 if(val
>= 1.0) return 4294967295u;
1005 if(val
<= -1.0) return 0;
1006 return (ALint
)(val
* 2147483647.0) + 2147483648u;
1008 static __inline ALuint
Conv_ALuint_ALmulaw(ALmulaw val
)
1009 { return (muLawDecompressionTable
[val
]+32768)<<16; }
1011 static __inline ALfloat
Conv_ALfloat_ALbyte(ALbyte val
)
1012 { return val
* (1.0f
/127.0f
); }
1013 static __inline ALfloat
Conv_ALfloat_ALubyte(ALubyte val
)
1014 { return (val
-128) * (1.0f
/127.0f
); }
1015 static __inline ALfloat
Conv_ALfloat_ALshort(ALshort val
)
1016 { return val
* (1.0f
/32767.0f
); }
1017 static __inline ALfloat
Conv_ALfloat_ALushort(ALushort val
)
1018 { return (val
-32768) * (1.0f
/32767.0f
); }
1019 static __inline ALfloat
Conv_ALfloat_ALint(ALint val
)
1020 { return val
* (1.0/2147483647.0); }
1021 static __inline ALfloat
Conv_ALfloat_ALuint(ALuint val
)
1022 { return (ALint
)(val
-2147483648u) * (1.0/2147483647.0); }
1023 static __inline ALfloat
Conv_ALfloat_ALfloat(ALfloat val
)
1025 static __inline ALfloat
Conv_ALfloat_ALdouble(ALdouble val
)
1027 static __inline ALfloat
Conv_ALfloat_ALmulaw(ALmulaw val
)
1028 { return muLawDecompressionTable
[val
] * (1.0f
/32767.0f
); }
1030 static __inline ALdouble
Conv_ALdouble_ALbyte(ALbyte val
)
1031 { return val
* (1.0/127.0); }
1032 static __inline ALdouble
Conv_ALdouble_ALubyte(ALubyte val
)
1033 { return (val
-128) * (1.0/127.0); }
1034 static __inline ALdouble
Conv_ALdouble_ALshort(ALshort val
)
1035 { return val
* (1.0/32767.0); }
1036 static __inline ALdouble
Conv_ALdouble_ALushort(ALushort val
)
1037 { return (val
-32768) * (1.0/32767.0); }
1038 static __inline ALdouble
Conv_ALdouble_ALint(ALint val
)
1039 { return val
* (1.0/214748364.0); }
1040 static __inline ALdouble
Conv_ALdouble_ALuint(ALuint val
)
1041 { return (ALint
)(val
-2147483648u) * (1.0/2147483647.0); }
1042 static __inline ALdouble
Conv_ALdouble_ALfloat(ALfloat val
)
1044 static __inline ALdouble
Conv_ALdouble_ALdouble(ALdouble val
)
1046 static __inline ALdouble
Conv_ALdouble_ALmulaw(ALmulaw val
)
1047 { return muLawDecompressionTable
[val
] * (1.0/32767.0); }
1050 #define DECL_TEMPLATE(T1, T2) \
1051 static void Convert_##T1##_##T2(T1 *dst, const T2 *src, ALuint len) \
1054 for(i = 0;i < len;i++) \
1055 *(dst++) = Conv_##T1##_##T2(*(src++)); \
1058 DECL_TEMPLATE(ALbyte
, ALbyte
)
1059 DECL_TEMPLATE(ALbyte
, ALubyte
)
1060 DECL_TEMPLATE(ALbyte
, ALshort
)
1061 DECL_TEMPLATE(ALbyte
, ALushort
)
1062 DECL_TEMPLATE(ALbyte
, ALint
)
1063 DECL_TEMPLATE(ALbyte
, ALuint
)
1064 DECL_TEMPLATE(ALbyte
, ALfloat
)
1065 DECL_TEMPLATE(ALbyte
, ALdouble
)
1066 DECL_TEMPLATE(ALbyte
, ALmulaw
)
1068 DECL_TEMPLATE(ALubyte
, ALbyte
)
1069 DECL_TEMPLATE(ALubyte
, ALubyte
)
1070 DECL_TEMPLATE(ALubyte
, ALshort
)
1071 DECL_TEMPLATE(ALubyte
, ALushort
)
1072 DECL_TEMPLATE(ALubyte
, ALint
)
1073 DECL_TEMPLATE(ALubyte
, ALuint
)
1074 DECL_TEMPLATE(ALubyte
, ALfloat
)
1075 DECL_TEMPLATE(ALubyte
, ALdouble
)
1076 DECL_TEMPLATE(ALubyte
, ALmulaw
)
1078 DECL_TEMPLATE(ALshort
, ALbyte
)
1079 DECL_TEMPLATE(ALshort
, ALubyte
)
1080 DECL_TEMPLATE(ALshort
, ALshort
)
1081 DECL_TEMPLATE(ALshort
, ALushort
)
1082 DECL_TEMPLATE(ALshort
, ALint
)
1083 DECL_TEMPLATE(ALshort
, ALuint
)
1084 DECL_TEMPLATE(ALshort
, ALfloat
)
1085 DECL_TEMPLATE(ALshort
, ALdouble
)
1086 DECL_TEMPLATE(ALshort
, ALmulaw
)
1088 DECL_TEMPLATE(ALushort
, ALbyte
)
1089 DECL_TEMPLATE(ALushort
, ALubyte
)
1090 DECL_TEMPLATE(ALushort
, ALshort
)
1091 DECL_TEMPLATE(ALushort
, ALushort
)
1092 DECL_TEMPLATE(ALushort
, ALint
)
1093 DECL_TEMPLATE(ALushort
, ALuint
)
1094 DECL_TEMPLATE(ALushort
, ALfloat
)
1095 DECL_TEMPLATE(ALushort
, ALdouble
)
1096 DECL_TEMPLATE(ALushort
, ALmulaw
)
1098 DECL_TEMPLATE(ALint
, ALbyte
)
1099 DECL_TEMPLATE(ALint
, ALubyte
)
1100 DECL_TEMPLATE(ALint
, ALshort
)
1101 DECL_TEMPLATE(ALint
, ALushort
)
1102 DECL_TEMPLATE(ALint
, ALint
)
1103 DECL_TEMPLATE(ALint
, ALuint
)
1104 DECL_TEMPLATE(ALint
, ALfloat
)
1105 DECL_TEMPLATE(ALint
, ALdouble
)
1106 DECL_TEMPLATE(ALint
, ALmulaw
)
1108 DECL_TEMPLATE(ALuint
, ALbyte
)
1109 DECL_TEMPLATE(ALuint
, ALubyte
)
1110 DECL_TEMPLATE(ALuint
, ALshort
)
1111 DECL_TEMPLATE(ALuint
, ALushort
)
1112 DECL_TEMPLATE(ALuint
, ALint
)
1113 DECL_TEMPLATE(ALuint
, ALuint
)
1114 DECL_TEMPLATE(ALuint
, ALfloat
)
1115 DECL_TEMPLATE(ALuint
, ALdouble
)
1116 DECL_TEMPLATE(ALuint
, ALmulaw
)
1118 DECL_TEMPLATE(ALfloat
, ALbyte
)
1119 DECL_TEMPLATE(ALfloat
, ALubyte
)
1120 DECL_TEMPLATE(ALfloat
, ALshort
)
1121 DECL_TEMPLATE(ALfloat
, ALushort
)
1122 DECL_TEMPLATE(ALfloat
, ALint
)
1123 DECL_TEMPLATE(ALfloat
, ALuint
)
1124 DECL_TEMPLATE(ALfloat
, ALfloat
)
1125 DECL_TEMPLATE(ALfloat
, ALdouble
)
1126 DECL_TEMPLATE(ALfloat
, ALmulaw
)
1128 DECL_TEMPLATE(ALdouble
, ALbyte
)
1129 DECL_TEMPLATE(ALdouble
, ALubyte
)
1130 DECL_TEMPLATE(ALdouble
, ALshort
)
1131 DECL_TEMPLATE(ALdouble
, ALushort
)
1132 DECL_TEMPLATE(ALdouble
, ALint
)
1133 DECL_TEMPLATE(ALdouble
, ALuint
)
1134 DECL_TEMPLATE(ALdouble
, ALfloat
)
1135 DECL_TEMPLATE(ALdouble
, ALdouble
)
1136 DECL_TEMPLATE(ALdouble
, ALmulaw
)
1138 #undef DECL_TEMPLATE
1140 #define DECL_TEMPLATE(T) \
1141 static void Convert_##T##_IMA4(T *dst, const ALubyte *src, ALuint numchans, \
1144 ALshort tmp[65*2]; /* Max samples an IMA4 frame can be */ \
1146 for(i = 0;i < numblocks;i++) \
1148 ConvertIMA4Block(tmp, src, numchans); \
1149 src += 36*numchans; \
1150 for(j = 0;j < 65*numchans;j++) \
1151 *(dst++) = Conv_##T##_ALshort(tmp[j]); \
1155 DECL_TEMPLATE(ALbyte
)
1156 DECL_TEMPLATE(ALubyte
)
1157 DECL_TEMPLATE(ALshort
)
1158 DECL_TEMPLATE(ALushort
)
1159 DECL_TEMPLATE(ALint
)
1160 DECL_TEMPLATE(ALuint
)
1161 DECL_TEMPLATE(ALfloat
)
1162 DECL_TEMPLATE(ALdouble
)
1164 #undef DECL_TEMPLATE
1166 #define DECL_TEMPLATE(T) \
1167 static void Convert_##T(T *dst, const ALvoid *src, enum SrcFmtType srcType, \
1173 Convert_##T##_ALbyte(dst, src, len); \
1176 Convert_##T##_ALubyte(dst, src, len); \
1179 Convert_##T##_ALshort(dst, src, len); \
1181 case SrcFmtUShort: \
1182 Convert_##T##_ALushort(dst, src, len); \
1185 Convert_##T##_ALint(dst, src, len); \
1188 Convert_##T##_ALuint(dst, src, len); \
1191 Convert_##T##_ALfloat(dst, src, len); \
1193 case SrcFmtDouble: \
1194 Convert_##T##_ALdouble(dst, src, len); \
1197 Convert_##T##_ALmulaw(dst, src, len); \
1200 break; /* not handled here */ \
1204 DECL_TEMPLATE(ALbyte
)
1205 DECL_TEMPLATE(ALubyte
)
1206 DECL_TEMPLATE(ALshort
)
1207 DECL_TEMPLATE(ALushort
)
1208 DECL_TEMPLATE(ALint
)
1209 DECL_TEMPLATE(ALuint
)
1210 DECL_TEMPLATE(ALfloat
)
1211 DECL_TEMPLATE(ALdouble
)
1213 #undef DECL_TEMPLATE
1216 static void ConvertData(ALvoid
*dst
, enum FmtType dstType
, const ALvoid
*src
, enum SrcFmtType srcType
, ALsizei len
)
1220 (void)Convert_ALbyte
;
1222 Convert_ALubyte(dst
, src
, srcType
, len
);
1225 Convert_ALshort(dst
, src
, srcType
, len
);
1227 (void)Convert_ALushort
;
1228 (void)Convert_ALint
;
1229 (void)Convert_ALuint
;
1231 Convert_ALfloat(dst
, src
, srcType
, len
);
1233 (void)Convert_ALdouble
;
1237 static void ConvertDataIMA4(ALvoid
*dst
, enum FmtType dstType
, const ALvoid
*src
, ALint chans
, ALsizei len
)
1241 (void)Convert_ALbyte_IMA4
;
1243 Convert_ALubyte_IMA4(dst
, src
, chans
, len
);
1246 Convert_ALshort_IMA4(dst
, src
, chans
, len
);
1248 (void)Convert_ALushort_IMA4
;
1249 (void)Convert_ALint_IMA4
;
1250 (void)Convert_ALuint_IMA4
;
1252 Convert_ALfloat_IMA4(dst
, src
, chans
, len
);
1254 (void)Convert_ALdouble_IMA4
;
1262 * Loads the specified data into the buffer, using the specified formats.
1263 * Currently, the new format must have the same channel configuration as the
1266 static ALenum
LoadData(ALbuffer
*ALBuf
, ALuint freq
, ALenum NewFormat
, ALsizei size
, enum SrcFmtChannels SrcChannels
, enum SrcFmtType SrcType
, const ALvoid
*data
)
1268 ALuint NewChannels
, NewBytes
;
1269 enum FmtChannels DstChannels
;
1270 enum FmtType DstType
;
1274 DecomposeFormat(NewFormat
, &DstChannels
, &DstType
);
1275 NewChannels
= ChannelsFromFmt(DstChannels
);
1276 NewBytes
= BytesFromFmt(DstType
);
1278 assert(SrcChannels
== DstChannels
);
1280 if(SrcType
== SrcFmtIMA4
)
1282 ALuint OrigChannels
= ChannelsFromSrcFmt(SrcChannels
);
1284 /* Here is where things vary:
1285 * nVidia and Apple use 64+1 sample frames per block => block_size=36*chans bytes
1286 * Most PC sound software uses 2040+1 sample frames per block -> block_size=1024*chans bytes
1288 if((size
%(36*OrigChannels
)) != 0)
1289 return AL_INVALID_VALUE
;
1291 newsize
= size
/ 36;
1293 newsize
*= NewBytes
;
1294 if(newsize
> INT_MAX
)
1295 return AL_OUT_OF_MEMORY
;
1297 temp
= realloc(ALBuf
->data
, newsize
);
1298 if(!temp
) return AL_OUT_OF_MEMORY
;
1300 ALBuf
->size
= newsize
;
1303 ConvertDataIMA4(ALBuf
->data
, DstType
, data
, OrigChannels
,
1304 newsize
/(65*NewChannels
*NewBytes
));
1306 ALBuf
->OriginalChannels
= SrcChannels
;
1307 ALBuf
->OriginalType
= SrcType
;
1308 ALBuf
->OriginalSize
= size
;
1309 ALBuf
->OriginalAlign
= 36 * OrigChannels
;
1313 ALuint OrigBytes
= BytesFromSrcFmt(SrcType
);
1314 ALuint OrigChannels
= ChannelsFromSrcFmt(SrcChannels
);
1316 if((size
%(OrigBytes
*OrigChannels
)) != 0)
1317 return AL_INVALID_VALUE
;
1319 newsize
= size
/ OrigBytes
;
1320 newsize
*= NewBytes
;
1321 if(newsize
> INT_MAX
)
1322 return AL_OUT_OF_MEMORY
;
1324 temp
= realloc(ALBuf
->data
, newsize
);
1325 if(!temp
) return AL_OUT_OF_MEMORY
;
1327 ALBuf
->size
= newsize
;
1330 ConvertData(ALBuf
->data
, DstType
, data
, SrcType
, newsize
/NewBytes
);
1332 ALBuf
->OriginalChannels
= SrcChannels
;
1333 ALBuf
->OriginalType
= SrcType
;
1334 ALBuf
->OriginalSize
= size
;
1335 ALBuf
->OriginalAlign
= OrigBytes
* OrigChannels
;
1338 ALBuf
->Frequency
= freq
;
1339 ALBuf
->FmtChannels
= DstChannels
;
1340 ALBuf
->FmtType
= DstType
;
1342 ALBuf
->LoopStart
= 0;
1343 ALBuf
->LoopEnd
= newsize
/ NewChannels
/ NewBytes
;
1349 ALuint
BytesFromSrcFmt(enum SrcFmtType type
)
1353 case SrcFmtByte
: return sizeof(ALbyte
);
1354 case SrcFmtUByte
: return sizeof(ALubyte
);
1355 case SrcFmtShort
: return sizeof(ALshort
);
1356 case SrcFmtUShort
: return sizeof(ALushort
);
1357 case SrcFmtInt
: return sizeof(ALint
);
1358 case SrcFmtUInt
: return sizeof(ALuint
);
1359 case SrcFmtFloat
: return sizeof(ALfloat
);
1360 case SrcFmtDouble
: return sizeof(ALdouble
);
1361 case SrcFmtMulaw
: return sizeof(ALubyte
);
1362 case SrcFmtIMA4
: break; /* not handled here */
1366 ALuint
ChannelsFromSrcFmt(enum SrcFmtChannels chans
)
1370 case SrcFmtMono
: return 1;
1371 case SrcFmtStereo
: return 2;
1372 case SrcFmtRear
: return 2;
1373 case SrcFmtQuad
: return 4;
1374 case SrcFmtX51
: return 6;
1375 case SrcFmtX61
: return 7;
1376 case SrcFmtX71
: return 8;
1380 ALboolean
DecomposeInputFormat(ALenum format
, enum SrcFmtChannels
*chans
,
1381 enum SrcFmtType
*type
)
1385 case AL_FORMAT_MONO8
:
1386 *chans
= SrcFmtMono
;
1387 *type
= SrcFmtUByte
;
1389 case AL_FORMAT_MONO16
:
1390 *chans
= SrcFmtMono
;
1391 *type
= SrcFmtShort
;
1393 case AL_FORMAT_MONO_FLOAT32
:
1394 *chans
= SrcFmtMono
;
1395 *type
= SrcFmtFloat
;
1397 case AL_FORMAT_MONO_DOUBLE_EXT
:
1398 *chans
= SrcFmtMono
;
1399 *type
= SrcFmtDouble
;
1401 case AL_FORMAT_MONO_IMA4
:
1402 *chans
= SrcFmtMono
;
1405 case AL_FORMAT_STEREO8
:
1406 *chans
= SrcFmtStereo
;
1407 *type
= SrcFmtUByte
;
1409 case AL_FORMAT_STEREO16
:
1410 *chans
= SrcFmtStereo
;
1411 *type
= SrcFmtShort
;
1413 case AL_FORMAT_STEREO_FLOAT32
:
1414 *chans
= SrcFmtStereo
;
1415 *type
= SrcFmtFloat
;
1417 case AL_FORMAT_STEREO_DOUBLE_EXT
:
1418 *chans
= SrcFmtStereo
;
1419 *type
= SrcFmtDouble
;
1421 case AL_FORMAT_STEREO_IMA4
:
1422 *chans
= SrcFmtStereo
;
1425 case AL_FORMAT_QUAD8_LOKI
:
1426 case AL_FORMAT_QUAD8
:
1427 *chans
= SrcFmtQuad
;
1428 *type
= SrcFmtUByte
;
1430 case AL_FORMAT_QUAD16_LOKI
:
1431 case AL_FORMAT_QUAD16
:
1432 *chans
= SrcFmtQuad
;
1433 *type
= SrcFmtShort
;
1435 case AL_FORMAT_QUAD32
:
1436 *chans
= SrcFmtQuad
;
1437 *type
= SrcFmtFloat
;
1439 case AL_FORMAT_REAR8
:
1440 *chans
= SrcFmtRear
;
1441 *type
= SrcFmtUByte
;
1443 case AL_FORMAT_REAR16
:
1444 *chans
= SrcFmtRear
;
1445 *type
= SrcFmtShort
;
1447 case AL_FORMAT_REAR32
:
1448 *chans
= SrcFmtRear
;
1449 *type
= SrcFmtFloat
;
1451 case AL_FORMAT_51CHN8
:
1453 *type
= SrcFmtUByte
;
1455 case AL_FORMAT_51CHN16
:
1457 *type
= SrcFmtShort
;
1459 case AL_FORMAT_51CHN32
:
1461 *type
= SrcFmtFloat
;
1463 case AL_FORMAT_61CHN8
:
1465 *type
= SrcFmtUByte
;
1467 case AL_FORMAT_61CHN16
:
1469 *type
= SrcFmtShort
;
1471 case AL_FORMAT_61CHN32
:
1473 *type
= SrcFmtFloat
;
1475 case AL_FORMAT_71CHN8
:
1477 *type
= SrcFmtUByte
;
1479 case AL_FORMAT_71CHN16
:
1481 *type
= SrcFmtShort
;
1483 case AL_FORMAT_71CHN32
:
1485 *type
= SrcFmtFloat
;
1487 case AL_FORMAT_MONO_MULAW
:
1488 *chans
= SrcFmtMono
;
1489 *type
= SrcFmtMulaw
;
1491 case AL_FORMAT_STEREO_MULAW
:
1492 *chans
= SrcFmtStereo
;
1493 *type
= SrcFmtMulaw
;
1495 case AL_FORMAT_QUAD_MULAW
:
1496 *chans
= SrcFmtQuad
;
1497 *type
= SrcFmtMulaw
;
1499 case AL_FORMAT_REAR_MULAW
:
1500 *chans
= SrcFmtRear
;
1501 *type
= SrcFmtMulaw
;
1503 case AL_FORMAT_51CHN_MULAW
:
1505 *type
= SrcFmtMulaw
;
1507 case AL_FORMAT_61CHN_MULAW
:
1509 *type
= SrcFmtMulaw
;
1511 case AL_FORMAT_71CHN_MULAW
:
1513 *type
= SrcFmtMulaw
;
1519 ALuint
BytesFromFmt(enum FmtType type
)
1523 case FmtUByte
: return sizeof(ALubyte
);
1524 case FmtShort
: return sizeof(ALshort
);
1525 case FmtFloat
: return sizeof(ALfloat
);
1529 ALuint
ChannelsFromFmt(enum FmtChannels chans
)
1533 case FmtMono
: return 1;
1534 case FmtStereo
: return 2;
1535 case FmtRear
: return 2;
1536 case FmtQuad
: return 4;
1537 case FmtX51
: return 6;
1538 case FmtX61
: return 7;
1539 case FmtX71
: return 8;
1543 ALboolean
DecomposeFormat(ALenum format
, enum FmtChannels
*chans
, enum FmtType
*type
)
1547 case AL_FORMAT_MONO8
:
1551 case AL_FORMAT_MONO16
:
1555 case AL_FORMAT_MONO_FLOAT32
:
1559 case AL_FORMAT_STEREO8
:
1563 case AL_FORMAT_STEREO16
:
1567 case AL_FORMAT_STEREO_FLOAT32
:
1571 case AL_FORMAT_QUAD8_LOKI
:
1572 case AL_FORMAT_QUAD8
:
1576 case AL_FORMAT_QUAD16_LOKI
:
1577 case AL_FORMAT_QUAD16
:
1581 case AL_FORMAT_QUAD32
:
1585 case AL_FORMAT_REAR8
:
1589 case AL_FORMAT_REAR16
:
1593 case AL_FORMAT_REAR32
:
1597 case AL_FORMAT_51CHN8
:
1601 case AL_FORMAT_51CHN16
:
1605 case AL_FORMAT_51CHN32
:
1609 case AL_FORMAT_61CHN8
:
1613 case AL_FORMAT_61CHN16
:
1617 case AL_FORMAT_61CHN32
:
1621 case AL_FORMAT_71CHN8
:
1625 case AL_FORMAT_71CHN16
:
1629 case AL_FORMAT_71CHN32
:
1639 * ReleaseALBuffers()
1641 * INTERNAL FN : Called by alcCloseDevice to destroy any buffers that still exist
1643 ALvoid
ReleaseALBuffers(ALCdevice
*device
)
1646 for(i
= 0;i
< device
->BufferMap
.size
;i
++)
1648 ALbuffer
*temp
= device
->BufferMap
.array
[i
].value
;
1649 device
->BufferMap
.array
[i
].value
= NULL
;
1651 // Release sample data
1654 // Release Buffer structure
1655 ALTHUNK_REMOVEENTRY(temp
->buffer
);
1656 memset(temp
, 0, sizeof(ALbuffer
));