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
36 static ALenum
LoadData(ALbuffer
*ALBuf
, ALuint freq
, ALenum NewFormat
, ALsizei frames
, enum UserFmtChannels chans
, enum UserFmtType type
, const ALvoid
*data
, ALboolean storesrc
);
37 static void ConvertData(ALvoid
*dst
, enum UserFmtType dstType
, const ALvoid
*src
, enum UserFmtType srcType
, ALsizei numchans
, ALsizei len
);
38 static ALboolean
IsValidType(ALenum type
);
39 static ALboolean
IsValidChannels(ALenum channels
);
41 #define LookupBuffer(m, k) ((ALbuffer*)LookupUIntMapKey(&(m), (k)))
48 /* IMA ADPCM Stepsize table */
49 static const long IMAStep_size
[89] = {
50 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19,
51 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55,
52 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157,
53 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449,
54 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
55 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660,
56 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,10442,
57 11487,12635,13899,15289,16818,18500,20350,22358,24633,27086,29794,
61 /* IMA4 ADPCM Codeword decode table */
62 static const long IMA4Codeword
[16] = {
63 1, 3, 5, 7, 9, 11, 13, 15,
64 -1,-3,-5,-7,-9,-11,-13,-15,
67 /* IMA4 ADPCM Step index adjust decode table */
68 static const long IMA4Index_adjust
[16] = {
69 -1,-1,-1,-1, 2, 4, 6, 8,
70 -1,-1,-1,-1, 2, 4, 6, 8
73 /* A quick'n'dirty lookup table to decode a muLaw-encoded byte sample into a
74 * signed 16-bit sample */
75 static const ALshort muLawDecompressionTable
[256] = {
76 -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
77 -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
78 -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
79 -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
80 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
81 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
82 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
83 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
84 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
85 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
86 -876, -844, -812, -780, -748, -716, -684, -652,
87 -620, -588, -556, -524, -492, -460, -428, -396,
88 -372, -356, -340, -324, -308, -292, -276, -260,
89 -244, -228, -212, -196, -180, -164, -148, -132,
90 -120, -112, -104, -96, -88, -80, -72, -64,
91 -56, -48, -40, -32, -24, -16, -8, 0,
92 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
93 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
94 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
95 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
96 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
97 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
98 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
99 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
100 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
101 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
102 876, 844, 812, 780, 748, 716, 684, 652,
103 620, 588, 556, 524, 492, 460, 428, 396,
104 372, 356, 340, 324, 308, 292, 276, 260,
105 244, 228, 212, 196, 180, 164, 148, 132,
106 120, 112, 104, 96, 88, 80, 72, 64,
107 56, 48, 40, 32, 24, 16, 8, 0
110 /* Values used when encoding a muLaw sample */
111 static const int muLawBias
= 0x84;
112 static const int muLawClip
= 32635;
113 static const char muLawCompressTable
[256] =
115 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
116 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
117 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
118 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
119 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
120 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
121 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
122 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
123 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
124 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
125 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
126 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
127 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
128 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
129 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
130 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
134 * alGenBuffers(ALsizei n, ALuint *buffers)
136 * Generates n AL Buffers, and stores the Buffers Names in the array pointed
139 AL_API ALvoid AL_APIENTRY
alGenBuffers(ALsizei n
, ALuint
*buffers
)
144 Context
= GetLockedContext();
147 /* Check that we are actually generating some Buffers */
148 if(n
< 0 || IsBadWritePtr((void*)buffers
, n
* sizeof(ALuint
)))
149 alSetError(Context
, AL_INVALID_VALUE
);
152 ALCdevice
*device
= Context
->Device
;
155 // Create all the new Buffers
158 ALbuffer
*buffer
= calloc(1, sizeof(ALbuffer
));
161 alSetError(Context
, AL_OUT_OF_MEMORY
);
162 alDeleteBuffers(i
, buffers
);
166 err
= NewThunkEntry(&buffer
->buffer
);
167 if(err
== AL_NO_ERROR
)
168 err
= InsertUIntMapEntry(&device
->BufferMap
, buffer
->buffer
, buffer
);
169 if(err
!= AL_NO_ERROR
)
171 FreeThunkEntry(buffer
->buffer
);
172 memset(buffer
, 0, sizeof(ALbuffer
));
175 alSetError(Context
, err
);
176 alDeleteBuffers(i
, buffers
);
179 buffers
[i
++] = buffer
->buffer
;
183 UnlockContext(Context
);
187 * alDeleteBuffers(ALsizei n, ALuint *buffers)
189 * Deletes the n AL Buffers pointed to by buffers
191 AL_API ALvoid AL_APIENTRY
alDeleteBuffers(ALsizei n
, const ALuint
*buffers
)
199 Context
= GetLockedContext();
203 device
= Context
->Device
;
204 /* Check we are actually Deleting some Buffers */
206 alSetError(Context
, AL_INVALID_VALUE
);
211 /* Check that all the buffers are valid and can actually be deleted */
217 /* Check for valid Buffer ID */
218 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffers
[i
])) == NULL
)
220 alSetError(Context
, AL_INVALID_NAME
);
224 else if(ALBuf
->refcount
!= 0)
226 /* Buffer still in use, cannot be deleted */
227 alSetError(Context
, AL_INVALID_OPERATION
);
234 /* If all the Buffers were valid (and have Reference Counts of 0), then we
240 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffers
[i
])) == NULL
)
243 /* Release the memory used to store audio data */
246 /* Release buffer structure */
247 RemoveUIntMapKey(&device
->BufferMap
, ALBuf
->buffer
);
248 FreeThunkEntry(ALBuf
->buffer
);
250 memset(ALBuf
, 0, sizeof(ALbuffer
));
255 UnlockContext(Context
);
259 * alIsBuffer(ALuint buffer)
261 * Checks if buffer is a valid Buffer Name
263 AL_API ALboolean AL_APIENTRY
alIsBuffer(ALuint buffer
)
268 Context
= GetLockedContext();
269 if(!Context
) return AL_FALSE
;
271 result
= ((!buffer
|| LookupBuffer(Context
->Device
->BufferMap
, buffer
)) ?
274 UnlockContext(Context
);
280 * alBufferData(ALuint buffer, ALenum format, const ALvoid *data,
281 * ALsizei size, ALsizei freq)
283 * Fill buffer with audio data
285 AL_API ALvoid AL_APIENTRY
alBufferData(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei size
,ALsizei freq
)
287 enum UserFmtChannels SrcChannels
;
288 enum UserFmtType SrcType
;
294 Context
= GetLockedContext();
297 device
= Context
->Device
;
298 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
299 alSetError(Context
, AL_INVALID_NAME
);
300 else if(ALBuf
->refcount
!= 0)
301 alSetError(Context
, AL_INVALID_VALUE
);
302 else if(size
< 0 || freq
< 0)
303 alSetError(Context
, AL_INVALID_VALUE
);
304 else if(DecomposeUserFormat(format
, &SrcChannels
, &SrcType
) == AL_FALSE
)
305 alSetError(Context
, AL_INVALID_ENUM
);
315 ALuint FrameSize
= FrameSizeFromUserFmt(SrcChannels
, SrcType
);
316 if((size
%FrameSize
) != 0)
317 err
= AL_INVALID_VALUE
;
319 err
= LoadData(ALBuf
, freq
, format
, size
/FrameSize
,
320 SrcChannels
, SrcType
, data
, AL_TRUE
);
321 if(err
!= AL_NO_ERROR
)
322 alSetError(Context
, err
);
327 case UserFmtDouble
: {
328 ALuint FrameSize
= FrameSizeFromUserFmt(SrcChannels
, SrcType
);
329 ALenum NewFormat
= AL_FORMAT_MONO_FLOAT32
;
332 case UserFmtMono
: NewFormat
= AL_FORMAT_MONO_FLOAT32
; break;
333 case UserFmtStereo
: NewFormat
= AL_FORMAT_STEREO_FLOAT32
; break;
334 case UserFmtRear
: NewFormat
= AL_FORMAT_REAR32
; break;
335 case UserFmtQuad
: NewFormat
= AL_FORMAT_QUAD32
; break;
336 case UserFmtX51
: NewFormat
= AL_FORMAT_51CHN32
; break;
337 case UserFmtX61
: NewFormat
= AL_FORMAT_61CHN32
; break;
338 case UserFmtX71
: NewFormat
= AL_FORMAT_71CHN32
; break;
340 if((size
%FrameSize
) != 0)
341 err
= AL_INVALID_VALUE
;
343 err
= LoadData(ALBuf
, freq
, NewFormat
, size
/FrameSize
,
344 SrcChannels
, SrcType
, data
, AL_TRUE
);
345 if(err
!= AL_NO_ERROR
)
346 alSetError(Context
, err
);
351 /* Here is where things vary:
352 * nVidia and Apple use 64+1 sample frames per block -> block_size=36 bytes per channel
353 * Most PC sound software uses 2040+1 sample frames per block -> block_size=1024 bytes per channel
355 ALuint FrameSize
= (SrcType
== UserFmtIMA4
) ?
356 (ChannelsFromUserFmt(SrcChannels
) * 36) :
357 FrameSizeFromUserFmt(SrcChannels
, SrcType
);
358 ALenum NewFormat
= AL_FORMAT_MONO16
;
361 case UserFmtMono
: NewFormat
= AL_FORMAT_MONO16
; break;
362 case UserFmtStereo
: NewFormat
= AL_FORMAT_STEREO16
; break;
363 case UserFmtRear
: NewFormat
= AL_FORMAT_REAR16
; break;
364 case UserFmtQuad
: NewFormat
= AL_FORMAT_QUAD16
; break;
365 case UserFmtX51
: NewFormat
= AL_FORMAT_51CHN16
; break;
366 case UserFmtX61
: NewFormat
= AL_FORMAT_61CHN16
; break;
367 case UserFmtX71
: NewFormat
= AL_FORMAT_71CHN16
; break;
369 if((size
%FrameSize
) != 0)
370 err
= AL_INVALID_VALUE
;
372 err
= LoadData(ALBuf
, freq
, NewFormat
, size
/FrameSize
,
373 SrcChannels
, SrcType
, data
, AL_TRUE
);
374 if(err
!= AL_NO_ERROR
)
375 alSetError(Context
, err
);
379 UnlockContext(Context
);
383 * alBufferSubDataSOFT(ALuint buffer, ALenum format, const ALvoid *data,
384 * ALsizei offset, ALsizei length)
386 * Update buffer's audio data
388 AL_API ALvoid AL_APIENTRY
alBufferSubDataSOFT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
390 enum UserFmtChannels SrcChannels
;
391 enum UserFmtType SrcType
;
396 Context
= GetLockedContext();
399 device
= Context
->Device
;
400 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
401 alSetError(Context
, AL_INVALID_NAME
);
402 else if(length
< 0 || offset
< 0 || (length
> 0 && data
== NULL
))
403 alSetError(Context
, AL_INVALID_VALUE
);
404 else if(DecomposeUserFormat(format
, &SrcChannels
, &SrcType
) == AL_FALSE
||
405 SrcChannels
!= ALBuf
->OriginalChannels
||
406 SrcType
!= ALBuf
->OriginalType
)
407 alSetError(Context
, AL_INVALID_ENUM
);
408 else if(offset
> ALBuf
->OriginalSize
||
409 length
> ALBuf
->OriginalSize
-offset
||
410 (offset
%ALBuf
->OriginalAlign
) != 0 ||
411 (length
%ALBuf
->OriginalAlign
) != 0)
412 alSetError(Context
, AL_INVALID_VALUE
);
415 ALuint Channels
= ChannelsFromFmt(ALBuf
->FmtChannels
);
416 ALuint Bytes
= BytesFromFmt(ALBuf
->FmtType
);
417 if(SrcType
== UserFmtIMA4
)
419 /* offset -> byte offset, length -> block count */
423 length
/= ALBuf
->OriginalAlign
;
427 ALuint OldBytes
= BytesFromUserFmt(SrcType
);
431 length
/= OldBytes
* Channels
;
433 ConvertData(&((ALubyte
*)ALBuf
->data
)[offset
], ALBuf
->FmtType
,
434 data
, SrcType
, Channels
, length
);
437 UnlockContext(Context
);
441 AL_API
void AL_APIENTRY
alBufferSamplesSOFT(ALuint buffer
,
442 ALuint samplerate
, ALenum internalformat
, ALsizei frames
,
443 ALenum channels
, ALenum type
, const ALvoid
*data
)
450 Context
= GetLockedContext();
453 device
= Context
->Device
;
454 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
455 alSetError(Context
, AL_INVALID_NAME
);
456 else if(ALBuf
->refcount
!= 0)
457 alSetError(Context
, AL_INVALID_VALUE
);
458 else if(frames
< 0 || samplerate
== 0)
459 alSetError(Context
, AL_INVALID_VALUE
);
460 else if(IsValidType(type
) == AL_FALSE
|| IsValidChannels(channels
) == AL_FALSE
)
461 alSetError(Context
, AL_INVALID_ENUM
);
465 if(type
== UserFmtIMA4
)
467 if((frames
%65) == 0) frames
/= 65;
468 else err
= AL_INVALID_VALUE
;
470 if(err
== AL_NO_ERROR
)
471 err
= LoadData(ALBuf
, samplerate
, internalformat
, frames
,
472 channels
, type
, data
, AL_FALSE
);
473 if(err
!= AL_NO_ERROR
)
474 alSetError(Context
, err
);
477 UnlockContext(Context
);
480 AL_API
void AL_APIENTRY
alBufferSubSamplesSOFT(ALuint buffer
,
481 ALsizei offset
, ALsizei frames
,
482 ALenum channels
, ALenum type
, const ALvoid
*data
)
488 Context
= GetLockedContext();
491 device
= Context
->Device
;
492 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
493 alSetError(Context
, AL_INVALID_NAME
);
494 else if(frames
< 0 || offset
< 0 || (frames
> 0 && data
== NULL
))
495 alSetError(Context
, AL_INVALID_VALUE
);
496 else if(channels
!= (ALenum
)ALBuf
->FmtChannels
||
497 IsValidType(type
) == AL_FALSE
)
498 alSetError(Context
, AL_INVALID_ENUM
);
501 ALuint FrameSize
= FrameSizeFromFmt(ALBuf
->FmtChannels
, ALBuf
->FmtType
);
502 ALuint FrameCount
= ALBuf
->size
/ FrameSize
;
503 if((ALuint
)offset
> FrameCount
|| (ALuint
)frames
> FrameCount
-offset
)
504 alSetError(Context
, AL_INVALID_VALUE
);
505 else if(type
== UserFmtIMA4
&& (frames
%65) != 0)
506 alSetError(Context
, AL_INVALID_VALUE
);
509 /* offset -> byte offset */
511 /* frames -> IMA4 block count */
512 if(type
== UserFmtIMA4
) frames
/= 65;
513 ConvertData(&((ALubyte
*)ALBuf
->data
)[offset
], ALBuf
->FmtType
,
515 ChannelsFromFmt(ALBuf
->FmtChannels
), frames
);
519 UnlockContext(Context
);
522 AL_API
void AL_APIENTRY
alGetBufferSamplesSOFT(ALuint buffer
,
523 ALsizei offset
, ALsizei frames
,
524 ALenum channels
, ALenum type
, ALvoid
*data
)
530 Context
= GetLockedContext();
533 device
= Context
->Device
;
534 if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
535 alSetError(Context
, AL_INVALID_NAME
);
536 else if(frames
< 0 || offset
< 0 || (frames
> 0 && data
== NULL
))
537 alSetError(Context
, AL_INVALID_VALUE
);
538 else if(channels
!= (ALenum
)ALBuf
->FmtChannels
||
539 IsValidType(type
) == AL_FALSE
)
540 alSetError(Context
, AL_INVALID_ENUM
);
543 ALuint FrameSize
= FrameSizeFromFmt(ALBuf
->FmtChannels
, ALBuf
->FmtType
);
544 ALuint FrameCount
= ALBuf
->size
/ FrameSize
;
545 if((ALuint
)offset
> FrameCount
|| (ALuint
)frames
> FrameCount
-offset
)
546 alSetError(Context
, AL_INVALID_VALUE
);
547 else if(type
== UserFmtIMA4
&& (frames
%65) != 0)
548 alSetError(Context
, AL_INVALID_VALUE
);
551 /* offset -> byte offset */
553 /* frames -> IMA4 block count */
554 if(type
== UserFmtIMA4
) frames
/= 65;
555 ConvertData(data
, type
,
556 &((ALubyte
*)ALBuf
->data
)[offset
], ALBuf
->FmtType
,
557 ChannelsFromFmt(ALBuf
->FmtChannels
), frames
);
561 UnlockContext(Context
);
564 AL_API ALboolean AL_APIENTRY
alIsBufferFormatSupportedSOFT(ALenum format
)
566 enum FmtChannels DstChannels
;
567 enum FmtType DstType
;
571 Context
= GetLockedContext();
572 if(!Context
) return AL_FALSE
;
574 ret
= DecomposeFormat(format
, &DstChannels
, &DstType
);
576 UnlockContext(Context
);
582 AL_API
void AL_APIENTRY
alBufferf(ALuint buffer
, ALenum eParam
, ALfloat flValue
)
584 ALCcontext
*pContext
;
589 pContext
= GetLockedContext();
590 if(!pContext
) return;
592 device
= pContext
->Device
;
593 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
594 alSetError(pContext
, AL_INVALID_NAME
);
600 alSetError(pContext
, AL_INVALID_ENUM
);
605 UnlockContext(pContext
);
609 AL_API
void AL_APIENTRY
alBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat flValue1
, ALfloat flValue2
, ALfloat flValue3
)
611 ALCcontext
*pContext
;
618 pContext
= GetLockedContext();
619 if(!pContext
) return;
621 device
= pContext
->Device
;
622 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
623 alSetError(pContext
, AL_INVALID_NAME
);
629 alSetError(pContext
, AL_INVALID_ENUM
);
634 UnlockContext(pContext
);
638 AL_API
void AL_APIENTRY
alBufferfv(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
)
640 ALCcontext
*pContext
;
643 pContext
= GetLockedContext();
644 if(!pContext
) return;
646 device
= pContext
->Device
;
648 alSetError(pContext
, AL_INVALID_VALUE
);
649 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
650 alSetError(pContext
, AL_INVALID_NAME
);
656 alSetError(pContext
, AL_INVALID_ENUM
);
661 UnlockContext(pContext
);
665 AL_API
void AL_APIENTRY
alBufferi(ALuint buffer
, ALenum eParam
, ALint lValue
)
667 ALCcontext
*pContext
;
672 pContext
= GetLockedContext();
673 if(!pContext
) return;
675 device
= pContext
->Device
;
676 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
677 alSetError(pContext
, AL_INVALID_NAME
);
683 alSetError(pContext
, AL_INVALID_ENUM
);
688 UnlockContext(pContext
);
692 AL_API
void AL_APIENTRY
alBuffer3i( ALuint buffer
, ALenum eParam
, ALint lValue1
, ALint lValue2
, ALint lValue3
)
694 ALCcontext
*pContext
;
701 pContext
= GetLockedContext();
702 if(!pContext
) return;
704 device
= pContext
->Device
;
705 if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
706 alSetError(pContext
, AL_INVALID_NAME
);
712 alSetError(pContext
, AL_INVALID_ENUM
);
717 UnlockContext(pContext
);
721 AL_API
void AL_APIENTRY
alBufferiv(ALuint buffer
, ALenum eParam
, const ALint
* plValues
)
723 ALCcontext
*pContext
;
727 pContext
= GetLockedContext();
728 if(!pContext
) return;
730 device
= pContext
->Device
;
732 alSetError(pContext
, AL_INVALID_VALUE
);
733 else if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
734 alSetError(pContext
, AL_INVALID_NAME
);
739 case AL_LOOP_POINTS_SOFT
:
740 if(ALBuf
->refcount
> 0)
741 alSetError(pContext
, AL_INVALID_OPERATION
);
742 else if(plValues
[0] < 0 || plValues
[1] < 0 ||
743 plValues
[0] >= plValues
[1] || ALBuf
->size
== 0)
744 alSetError(pContext
, AL_INVALID_VALUE
);
747 ALint maxlen
= ALBuf
->size
/
748 FrameSizeFromFmt(ALBuf
->FmtChannels
, ALBuf
->FmtType
);
749 if(plValues
[0] > maxlen
|| plValues
[1] > maxlen
)
750 alSetError(pContext
, AL_INVALID_VALUE
);
753 ALBuf
->LoopStart
= plValues
[0];
754 ALBuf
->LoopEnd
= plValues
[1];
760 alSetError(pContext
, AL_INVALID_ENUM
);
765 UnlockContext(pContext
);
769 AL_API ALvoid AL_APIENTRY
alGetBufferf(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
)
771 ALCcontext
*pContext
;
774 pContext
= GetLockedContext();
775 if(!pContext
) return;
777 device
= pContext
->Device
;
779 alSetError(pContext
, AL_INVALID_VALUE
);
780 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
781 alSetError(pContext
, AL_INVALID_NAME
);
787 alSetError(pContext
, AL_INVALID_ENUM
);
792 UnlockContext(pContext
);
796 AL_API
void AL_APIENTRY
alGetBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat
* pflValue1
, ALfloat
* pflValue2
, ALfloat
* pflValue3
)
798 ALCcontext
*pContext
;
801 pContext
= GetLockedContext();
802 if(!pContext
) return;
804 device
= pContext
->Device
;
805 if(!pflValue1
|| !pflValue2
|| !pflValue3
)
806 alSetError(pContext
, AL_INVALID_VALUE
);
807 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
808 alSetError(pContext
, AL_INVALID_NAME
);
814 alSetError(pContext
, AL_INVALID_ENUM
);
819 UnlockContext(pContext
);
823 AL_API
void AL_APIENTRY
alGetBufferfv(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
)
825 ALCcontext
*pContext
;
828 pContext
= GetLockedContext();
829 if(!pContext
) return;
831 device
= pContext
->Device
;
833 alSetError(pContext
, AL_INVALID_VALUE
);
834 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
835 alSetError(pContext
, AL_INVALID_NAME
);
841 alSetError(pContext
, AL_INVALID_ENUM
);
846 UnlockContext(pContext
);
850 AL_API ALvoid AL_APIENTRY
alGetBufferi(ALuint buffer
, ALenum eParam
, ALint
*plValue
)
852 ALCcontext
*pContext
;
856 pContext
= GetLockedContext();
857 if(!pContext
) return;
859 device
= pContext
->Device
;
861 alSetError(pContext
, AL_INVALID_VALUE
);
862 else if((pBuffer
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
863 alSetError(pContext
, AL_INVALID_NAME
);
869 *plValue
= pBuffer
->Frequency
;
873 *plValue
= BytesFromFmt(pBuffer
->FmtType
) * 8;
877 *plValue
= ChannelsFromFmt(pBuffer
->FmtChannels
);
881 *plValue
= pBuffer
->size
;
885 alSetError(pContext
, AL_INVALID_ENUM
);
890 UnlockContext(pContext
);
894 AL_API
void AL_APIENTRY
alGetBuffer3i(ALuint buffer
, ALenum eParam
, ALint
* plValue1
, ALint
* plValue2
, ALint
* plValue3
)
896 ALCcontext
*pContext
;
899 pContext
= GetLockedContext();
900 if(!pContext
) return;
902 device
= pContext
->Device
;
903 if(!plValue1
|| !plValue2
|| !plValue3
)
904 alSetError(pContext
, AL_INVALID_VALUE
);
905 else if(LookupBuffer(device
->BufferMap
, buffer
) == NULL
)
906 alSetError(pContext
, AL_INVALID_NAME
);
912 alSetError(pContext
, AL_INVALID_ENUM
);
917 UnlockContext(pContext
);
921 AL_API
void AL_APIENTRY
alGetBufferiv(ALuint buffer
, ALenum eParam
, ALint
* plValues
)
923 ALCcontext
*pContext
;
933 alGetBufferi(buffer
, eParam
, plValues
);
937 pContext
= GetLockedContext();
938 if(!pContext
) return;
940 device
= pContext
->Device
;
942 alSetError(pContext
, AL_INVALID_VALUE
);
943 else if((ALBuf
=LookupBuffer(device
->BufferMap
, buffer
)) == NULL
)
944 alSetError(pContext
, AL_INVALID_NAME
);
949 case AL_LOOP_POINTS_SOFT
:
950 plValues
[0] = ALBuf
->LoopStart
;
951 plValues
[1] = ALBuf
->LoopEnd
;
955 alSetError(pContext
, AL_INVALID_ENUM
);
960 UnlockContext(pContext
);
964 typedef ALubyte ALmulaw
;
965 typedef ALubyte ALima4
;
973 static __inline ALshort
DecodeMuLaw(ALmulaw val
)
974 { return muLawDecompressionTable
[val
]; }
976 static ALmulaw
EncodeMuLaw(ALshort val
)
978 ALint mant
, exp
, sign
;
980 sign
= (val
>>8) & 0x80;
983 /* -32768 doesn't properly negate on a short; it results in itself.
984 * So clamp to -32767 */
985 val
= maxi(val
, -32767);
989 val
= mini(val
, muLawClip
);
992 exp
= muLawCompressTable
[(val
>>7) & 0xff];
993 mant
= (val
>> (exp
+3)) & 0x0f;
995 return ~(sign
| (exp
<<4) | mant
);
998 static void DecodeIMA4Block(ALshort
*dst
, const ALima4
*src
, ALint numchans
)
1000 ALint sample
[MAXCHANNELS
], index
[MAXCHANNELS
];
1001 ALuint code
[MAXCHANNELS
];
1004 for(c
= 0;c
< numchans
;c
++)
1006 sample
[c
] = *(src
++);
1007 sample
[c
] |= *(src
++) << 8;
1008 sample
[c
] = (sample
[c
]^0x8000) - 32768;
1009 index
[c
] = *(src
++);
1010 index
[c
] |= *(src
++) << 8;
1011 index
[c
] = (index
[c
]^0x8000) - 32768;
1013 index
[c
] = clampi(index
[c
], 0, 88);
1021 for(c
= 0;c
< numchans
;c
++)
1024 code
[c
] |= *(src
++) << 8;
1025 code
[c
] |= *(src
++) << 16;
1026 code
[c
] |= *(src
++) << 24;
1029 for(k
= 0;k
< 8;k
++,j
++)
1031 for(c
= 0;c
< numchans
;c
++)
1033 int nibble
= code
[c
]&0xf;
1036 sample
[c
] += IMA4Codeword
[nibble
] * IMAStep_size
[index
[c
]] / 8;
1037 sample
[c
] = clampi(sample
[c
], -32768, 32767);
1039 index
[c
] += IMA4Index_adjust
[nibble
];
1040 index
[c
] = clampi(index
[c
], 0, 88);
1042 dst
[j
*numchans
+ c
] = sample
[c
];
1048 static void EncodeIMA4Block(ALima4
*dst
, const ALshort
*src
, ALint
*sample
, ALint
*index
, ALint numchans
)
1052 for(c
= 0;c
< numchans
;c
++)
1054 int diff
= src
[c
] - sample
[c
];
1055 int step
= IMAStep_size
[index
[c
]];
1065 diff
= mini(step
*2, diff
);
1066 nibble
|= (diff
*8/step
- 1) / 2;
1068 sample
[c
] += IMA4Codeword
[nibble
] * step
/ 8;
1069 sample
[c
] = clampi(sample
[c
], -32768, 32767);
1071 index
[c
] += IMA4Index_adjust
[nibble
];
1072 index
[c
] = clampi(index
[c
], 0, 88);
1074 *(dst
++) = sample
[c
] & 0xff;
1075 *(dst
++) = (sample
[c
]>>8) & 0xff;
1076 *(dst
++) = index
[c
] & 0xff;
1077 *(dst
++) = (index
[c
]>>8) & 0xff;
1083 for(c
= 0;c
< numchans
;c
++)
1085 for(k
= 0;k
< 8;k
++)
1087 int diff
= src
[(j
+k
)*numchans
+ c
] - sample
[c
];
1088 int step
= IMAStep_size
[index
[c
]];
1098 diff
= mini(step
*2, diff
);
1099 nibble
|= (diff
*8/step
- 1) / 2;
1101 sample
[c
] += IMA4Codeword
[nibble
] * step
/ 8;
1102 sample
[c
] = clampi(sample
[c
], -32768, 32767);
1104 index
[c
] += IMA4Index_adjust
[nibble
];
1105 index
[c
] = clampi(index
[c
], 0, 88);
1107 if(!(k
&1)) *dst
= nibble
;
1108 else *(dst
++) |= nibble
<<4;
1115 static const union {
1117 ALubyte b
[sizeof(ALuint
)];
1118 } EndianTest
= { 1 };
1119 #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1)
1121 static __inline ALint
DecodeByte3(ALbyte3 val
)
1123 if(IS_LITTLE_ENDIAN
)
1124 return (val
.b
[2]<<16) | (((ALubyte
)val
.b
[1])<<8) | ((ALubyte
)val
.b
[0]);
1125 return (val
.b
[0]<<16) | (((ALubyte
)val
.b
[1])<<8) | ((ALubyte
)val
.b
[2]);
1128 static __inline ALbyte3
EncodeByte3(ALint val
)
1130 if(IS_LITTLE_ENDIAN
)
1132 ALbyte3 ret
= {{ val
, val
>>8, val
>>16 }};
1137 ALbyte3 ret
= {{ val
>>16, val
>>8, val
}};
1142 static __inline ALint
DecodeUByte3(ALubyte3 val
)
1144 if(IS_LITTLE_ENDIAN
)
1145 return (val
.b
[2]<<16) | (val
.b
[1]<<8) | (val
.b
[0]);
1146 return (val
.b
[0]<<16) | (val
.b
[1]<<8) | val
.b
[2];
1149 static __inline ALubyte3
EncodeUByte3(ALint val
)
1151 if(IS_LITTLE_ENDIAN
)
1153 ALubyte3 ret
= {{ val
, val
>>8, val
>>16 }};
1158 ALubyte3 ret
= {{ val
>>16, val
>>8, val
}};
1164 static __inline ALbyte
Conv_ALbyte_ALbyte(ALbyte val
)
1166 static __inline ALbyte
Conv_ALbyte_ALubyte(ALubyte val
)
1168 static __inline ALbyte
Conv_ALbyte_ALshort(ALshort val
)
1170 static __inline ALbyte
Conv_ALbyte_ALushort(ALushort val
)
1171 { return (val
>>8)-128; }
1172 static __inline ALbyte
Conv_ALbyte_ALint(ALint val
)
1174 static __inline ALbyte
Conv_ALbyte_ALuint(ALuint val
)
1175 { return (val
>>24)-128; }
1176 static __inline ALbyte
Conv_ALbyte_ALfloat(ALfloat val
)
1178 if(val
> 1.0f
) return 127;
1179 if(val
< -1.0f
) return -128;
1180 return (ALint
)(val
* 127.0f
);
1182 static __inline ALbyte
Conv_ALbyte_ALdouble(ALdouble val
)
1184 if(val
> 1.0) return 127;
1185 if(val
< -1.0) return -128;
1186 return (ALint
)(val
* 127.0);
1188 static __inline ALbyte
Conv_ALbyte_ALmulaw(ALmulaw val
)
1189 { return Conv_ALbyte_ALshort(DecodeMuLaw(val
)); }
1190 static __inline ALbyte
Conv_ALbyte_ALbyte3(ALbyte3 val
)
1191 { return DecodeByte3(val
)>>16; }
1192 static __inline ALbyte
Conv_ALbyte_ALubyte3(ALubyte3 val
)
1193 { return (DecodeUByte3(val
)>>16)-128; }
1195 static __inline ALubyte
Conv_ALubyte_ALbyte(ALbyte val
)
1197 static __inline ALubyte
Conv_ALubyte_ALubyte(ALubyte val
)
1199 static __inline ALubyte
Conv_ALubyte_ALshort(ALshort val
)
1200 { return (val
>>8)+128; }
1201 static __inline ALubyte
Conv_ALubyte_ALushort(ALushort val
)
1203 static __inline ALubyte
Conv_ALubyte_ALint(ALint val
)
1204 { return (val
>>24)+128; }
1205 static __inline ALubyte
Conv_ALubyte_ALuint(ALuint val
)
1207 static __inline ALubyte
Conv_ALubyte_ALfloat(ALfloat val
)
1209 if(val
> 1.0f
) return 255;
1210 if(val
< -1.0f
) return 0;
1211 return (ALint
)(val
* 127.0f
) + 128;
1213 static __inline ALubyte
Conv_ALubyte_ALdouble(ALdouble val
)
1215 if(val
> 1.0) return 255;
1216 if(val
< -1.0) return 0;
1217 return (ALint
)(val
* 127.0) + 128;
1219 static __inline ALubyte
Conv_ALubyte_ALmulaw(ALmulaw val
)
1220 { return Conv_ALubyte_ALshort(DecodeMuLaw(val
)); }
1221 static __inline ALubyte
Conv_ALubyte_ALbyte3(ALbyte3 val
)
1222 { return (DecodeByte3(val
)>>16)+128; }
1223 static __inline ALubyte
Conv_ALubyte_ALubyte3(ALubyte3 val
)
1224 { return DecodeUByte3(val
)>>16; }
1226 static __inline ALshort
Conv_ALshort_ALbyte(ALbyte val
)
1228 static __inline ALshort
Conv_ALshort_ALubyte(ALubyte val
)
1229 { return (val
-128)<<8; }
1230 static __inline ALshort
Conv_ALshort_ALshort(ALshort val
)
1232 static __inline ALshort
Conv_ALshort_ALushort(ALushort val
)
1233 { return val
-32768; }
1234 static __inline ALshort
Conv_ALshort_ALint(ALint val
)
1236 static __inline ALshort
Conv_ALshort_ALuint(ALuint val
)
1237 { return (val
>>16)-32768; }
1238 static __inline ALshort
Conv_ALshort_ALfloat(ALfloat val
)
1240 if(val
> 1.0f
) return 32767;
1241 if(val
< -1.0f
) return -32768;
1242 return (ALint
)(val
* 32767.0f
);
1244 static __inline ALshort
Conv_ALshort_ALdouble(ALdouble val
)
1246 if(val
> 1.0) return 32767;
1247 if(val
< -1.0) return -32768;
1248 return (ALint
)(val
* 32767.0);
1250 static __inline ALshort
Conv_ALshort_ALmulaw(ALmulaw val
)
1251 { return Conv_ALshort_ALshort(DecodeMuLaw(val
)); }
1252 static __inline ALshort
Conv_ALshort_ALbyte3(ALbyte3 val
)
1253 { return DecodeByte3(val
)>>8; }
1254 static __inline ALshort
Conv_ALshort_ALubyte3(ALubyte3 val
)
1255 { return (DecodeUByte3(val
)>>8)-32768; }
1257 static __inline ALushort
Conv_ALushort_ALbyte(ALbyte val
)
1258 { return (val
+128)<<8; }
1259 static __inline ALushort
Conv_ALushort_ALubyte(ALubyte val
)
1261 static __inline ALushort
Conv_ALushort_ALshort(ALshort val
)
1262 { return val
+32768; }
1263 static __inline ALushort
Conv_ALushort_ALushort(ALushort val
)
1265 static __inline ALushort
Conv_ALushort_ALint(ALint val
)
1266 { return (val
>>16)+32768; }
1267 static __inline ALushort
Conv_ALushort_ALuint(ALuint val
)
1269 static __inline ALushort
Conv_ALushort_ALfloat(ALfloat val
)
1271 if(val
> 1.0f
) return 65535;
1272 if(val
< -1.0f
) return 0;
1273 return (ALint
)(val
* 32767.0f
) + 32768;
1275 static __inline ALushort
Conv_ALushort_ALdouble(ALdouble val
)
1277 if(val
> 1.0) return 65535;
1278 if(val
< -1.0) return 0;
1279 return (ALint
)(val
* 32767.0) + 32768;
1281 static __inline ALushort
Conv_ALushort_ALmulaw(ALmulaw val
)
1282 { return Conv_ALushort_ALshort(DecodeMuLaw(val
)); }
1283 static __inline ALushort
Conv_ALushort_ALbyte3(ALbyte3 val
)
1284 { return (DecodeByte3(val
)>>8)+32768; }
1285 static __inline ALushort
Conv_ALushort_ALubyte3(ALubyte3 val
)
1286 { return DecodeUByte3(val
)>>8; }
1288 static __inline ALint
Conv_ALint_ALbyte(ALbyte val
)
1290 static __inline ALint
Conv_ALint_ALubyte(ALubyte val
)
1291 { return (val
-128)<<24; }
1292 static __inline ALint
Conv_ALint_ALshort(ALshort val
)
1294 static __inline ALint
Conv_ALint_ALushort(ALushort val
)
1295 { return (val
-32768)<<16; }
1296 static __inline ALint
Conv_ALint_ALint(ALint val
)
1298 static __inline ALint
Conv_ALint_ALuint(ALuint val
)
1299 { return val
-2147483648u; }
1300 static __inline ALint
Conv_ALint_ALfloat(ALfloat val
)
1302 if(val
> 1.0f
) return 2147483647;
1303 if(val
< -1.0f
) return -2147483647-1;
1304 return (ALint
)(val
* 2147483647.0);
1306 static __inline ALint
Conv_ALint_ALdouble(ALdouble val
)
1308 if(val
> 1.0) return 2147483647;
1309 if(val
< -1.0) return -2147483647-1;
1310 return (ALint
)(val
* 2147483647.0);
1312 static __inline ALint
Conv_ALint_ALmulaw(ALmulaw val
)
1313 { return Conv_ALint_ALshort(DecodeMuLaw(val
)); }
1314 static __inline ALint
Conv_ALint_ALbyte3(ALbyte3 val
)
1315 { return DecodeByte3(val
)<<8; }
1316 static __inline ALint
Conv_ALint_ALubyte3(ALubyte3 val
)
1317 { return (DecodeUByte3(val
)-8388608)<<8; }
1319 static __inline ALuint
Conv_ALuint_ALbyte(ALbyte val
)
1320 { return (val
+128)<<24; }
1321 static __inline ALuint
Conv_ALuint_ALubyte(ALubyte val
)
1323 static __inline ALuint
Conv_ALuint_ALshort(ALshort val
)
1324 { return (val
+32768)<<16; }
1325 static __inline ALuint
Conv_ALuint_ALushort(ALushort val
)
1327 static __inline ALuint
Conv_ALuint_ALint(ALint val
)
1328 { return val
+2147483648u; }
1329 static __inline ALuint
Conv_ALuint_ALuint(ALuint val
)
1331 static __inline ALuint
Conv_ALuint_ALfloat(ALfloat val
)
1333 if(val
> 1.0f
) return 4294967295u;
1334 if(val
< -1.0f
) return 0;
1335 return (ALint
)(val
* 2147483647.0) + 2147483648u;
1337 static __inline ALuint
Conv_ALuint_ALdouble(ALdouble val
)
1339 if(val
> 1.0) return 4294967295u;
1340 if(val
< -1.0) return 0;
1341 return (ALint
)(val
* 2147483647.0) + 2147483648u;
1343 static __inline ALuint
Conv_ALuint_ALmulaw(ALmulaw val
)
1344 { return Conv_ALuint_ALshort(DecodeMuLaw(val
)); }
1345 static __inline ALuint
Conv_ALuint_ALbyte3(ALbyte3 val
)
1346 { return (DecodeByte3(val
)+8388608)<<8; }
1347 static __inline ALuint
Conv_ALuint_ALubyte3(ALubyte3 val
)
1348 { return DecodeUByte3(val
)<<8; }
1350 static __inline ALfloat
Conv_ALfloat_ALbyte(ALbyte val
)
1351 { return val
* (1.0f
/127.0f
); }
1352 static __inline ALfloat
Conv_ALfloat_ALubyte(ALubyte val
)
1353 { return (val
-128) * (1.0f
/127.0f
); }
1354 static __inline ALfloat
Conv_ALfloat_ALshort(ALshort val
)
1355 { return val
* (1.0f
/32767.0f
); }
1356 static __inline ALfloat
Conv_ALfloat_ALushort(ALushort val
)
1357 { return (val
-32768) * (1.0f
/32767.0f
); }
1358 static __inline ALfloat
Conv_ALfloat_ALint(ALint val
)
1359 { return val
* (1.0/2147483647.0); }
1360 static __inline ALfloat
Conv_ALfloat_ALuint(ALuint val
)
1361 { return (ALint
)(val
-2147483648u) * (1.0/2147483647.0); }
1362 static __inline ALfloat
Conv_ALfloat_ALfloat(ALfloat val
)
1363 { return (val
==val
) ? val
: 0.0f
; }
1364 static __inline ALfloat
Conv_ALfloat_ALdouble(ALdouble val
)
1365 { return (val
==val
) ? val
: 0.0; }
1366 static __inline ALfloat
Conv_ALfloat_ALmulaw(ALmulaw val
)
1367 { return Conv_ALfloat_ALshort(DecodeMuLaw(val
)); }
1368 static __inline ALfloat
Conv_ALfloat_ALbyte3(ALbyte3 val
)
1369 { return DecodeByte3(val
) * (1.0/8388607.0); }
1370 static __inline ALfloat
Conv_ALfloat_ALubyte3(ALubyte3 val
)
1371 { return (DecodeUByte3(val
)-8388608) * (1.0/8388607.0); }
1373 static __inline ALdouble
Conv_ALdouble_ALbyte(ALbyte val
)
1374 { return val
* (1.0/127.0); }
1375 static __inline ALdouble
Conv_ALdouble_ALubyte(ALubyte val
)
1376 { return (val
-128) * (1.0/127.0); }
1377 static __inline ALdouble
Conv_ALdouble_ALshort(ALshort val
)
1378 { return val
* (1.0/32767.0); }
1379 static __inline ALdouble
Conv_ALdouble_ALushort(ALushort val
)
1380 { return (val
-32768) * (1.0/32767.0); }
1381 static __inline ALdouble
Conv_ALdouble_ALint(ALint val
)
1382 { return val
* (1.0/2147483647.0); }
1383 static __inline ALdouble
Conv_ALdouble_ALuint(ALuint val
)
1384 { return (ALint
)(val
-2147483648u) * (1.0/2147483647.0); }
1385 static __inline ALdouble
Conv_ALdouble_ALfloat(ALfloat val
)
1386 { return (val
==val
) ? val
: 0.0f
; }
1387 static __inline ALdouble
Conv_ALdouble_ALdouble(ALdouble val
)
1388 { return (val
==val
) ? val
: 0.0; }
1389 static __inline ALdouble
Conv_ALdouble_ALmulaw(ALmulaw val
)
1390 { return Conv_ALdouble_ALshort(DecodeMuLaw(val
)); }
1391 static __inline ALdouble
Conv_ALdouble_ALbyte3(ALbyte3 val
)
1392 { return DecodeByte3(val
) * (1.0/8388607.0); }
1393 static __inline ALdouble
Conv_ALdouble_ALubyte3(ALubyte3 val
)
1394 { return (DecodeUByte3(val
)-8388608) * (1.0/8388607.0); }
1396 #define DECL_TEMPLATE(T) \
1397 static __inline ALmulaw Conv_ALmulaw_##T(T val) \
1398 { return EncodeMuLaw(Conv_ALshort_##T(val)); }
1400 DECL_TEMPLATE(ALbyte
)
1401 DECL_TEMPLATE(ALubyte
)
1402 DECL_TEMPLATE(ALshort
)
1403 DECL_TEMPLATE(ALushort
)
1404 DECL_TEMPLATE(ALint
)
1405 DECL_TEMPLATE(ALuint
)
1406 DECL_TEMPLATE(ALfloat
)
1407 DECL_TEMPLATE(ALdouble
)
1408 static __inline ALmulaw
Conv_ALmulaw_ALmulaw(ALmulaw val
)
1410 DECL_TEMPLATE(ALbyte3
)
1411 DECL_TEMPLATE(ALubyte3
)
1413 #undef DECL_TEMPLATE
1415 #define DECL_TEMPLATE(T) \
1416 static __inline ALbyte3 Conv_ALbyte3_##T(T val) \
1417 { return EncodeByte3(Conv_ALint_##T(val)>>8); }
1419 DECL_TEMPLATE(ALbyte
)
1420 DECL_TEMPLATE(ALubyte
)
1421 DECL_TEMPLATE(ALshort
)
1422 DECL_TEMPLATE(ALushort
)
1423 DECL_TEMPLATE(ALint
)
1424 DECL_TEMPLATE(ALuint
)
1425 DECL_TEMPLATE(ALfloat
)
1426 DECL_TEMPLATE(ALdouble
)
1427 DECL_TEMPLATE(ALmulaw
)
1428 static __inline ALbyte3
Conv_ALbyte3_ALbyte3(ALbyte3 val
)
1430 DECL_TEMPLATE(ALubyte3
)
1432 #undef DECL_TEMPLATE
1434 #define DECL_TEMPLATE(T) \
1435 static __inline ALubyte3 Conv_ALubyte3_##T(T val) \
1436 { return EncodeUByte3(Conv_ALuint_##T(val)>>8); }
1438 DECL_TEMPLATE(ALbyte
)
1439 DECL_TEMPLATE(ALubyte
)
1440 DECL_TEMPLATE(ALshort
)
1441 DECL_TEMPLATE(ALushort
)
1442 DECL_TEMPLATE(ALint
)
1443 DECL_TEMPLATE(ALuint
)
1444 DECL_TEMPLATE(ALfloat
)
1445 DECL_TEMPLATE(ALdouble
)
1446 DECL_TEMPLATE(ALmulaw
)
1447 DECL_TEMPLATE(ALbyte3
)
1448 static __inline ALubyte3
Conv_ALubyte3_ALubyte3(ALubyte3 val
)
1451 #undef DECL_TEMPLATE
1454 #define DECL_TEMPLATE(T1, T2) \
1455 static void Convert_##T1##_##T2(T1 *dst, const T2 *src, ALuint numchans, \
1459 for(i = 0;i < len;i++) \
1461 for(j = 0;j < numchans;j++) \
1462 *(dst++) = Conv_##T1##_##T2(*(src++)); \
1466 DECL_TEMPLATE(ALbyte
, ALbyte
)
1467 DECL_TEMPLATE(ALbyte
, ALubyte
)
1468 DECL_TEMPLATE(ALbyte
, ALshort
)
1469 DECL_TEMPLATE(ALbyte
, ALushort
)
1470 DECL_TEMPLATE(ALbyte
, ALint
)
1471 DECL_TEMPLATE(ALbyte
, ALuint
)
1472 DECL_TEMPLATE(ALbyte
, ALfloat
)
1473 DECL_TEMPLATE(ALbyte
, ALdouble
)
1474 DECL_TEMPLATE(ALbyte
, ALmulaw
)
1475 DECL_TEMPLATE(ALbyte
, ALbyte3
)
1476 DECL_TEMPLATE(ALbyte
, ALubyte3
)
1478 DECL_TEMPLATE(ALubyte
, ALbyte
)
1479 DECL_TEMPLATE(ALubyte
, ALubyte
)
1480 DECL_TEMPLATE(ALubyte
, ALshort
)
1481 DECL_TEMPLATE(ALubyte
, ALushort
)
1482 DECL_TEMPLATE(ALubyte
, ALint
)
1483 DECL_TEMPLATE(ALubyte
, ALuint
)
1484 DECL_TEMPLATE(ALubyte
, ALfloat
)
1485 DECL_TEMPLATE(ALubyte
, ALdouble
)
1486 DECL_TEMPLATE(ALubyte
, ALmulaw
)
1487 DECL_TEMPLATE(ALubyte
, ALbyte3
)
1488 DECL_TEMPLATE(ALubyte
, ALubyte3
)
1490 DECL_TEMPLATE(ALshort
, ALbyte
)
1491 DECL_TEMPLATE(ALshort
, ALubyte
)
1492 DECL_TEMPLATE(ALshort
, ALshort
)
1493 DECL_TEMPLATE(ALshort
, ALushort
)
1494 DECL_TEMPLATE(ALshort
, ALint
)
1495 DECL_TEMPLATE(ALshort
, ALuint
)
1496 DECL_TEMPLATE(ALshort
, ALfloat
)
1497 DECL_TEMPLATE(ALshort
, ALdouble
)
1498 DECL_TEMPLATE(ALshort
, ALmulaw
)
1499 DECL_TEMPLATE(ALshort
, ALbyte3
)
1500 DECL_TEMPLATE(ALshort
, ALubyte3
)
1502 DECL_TEMPLATE(ALushort
, ALbyte
)
1503 DECL_TEMPLATE(ALushort
, ALubyte
)
1504 DECL_TEMPLATE(ALushort
, ALshort
)
1505 DECL_TEMPLATE(ALushort
, ALushort
)
1506 DECL_TEMPLATE(ALushort
, ALint
)
1507 DECL_TEMPLATE(ALushort
, ALuint
)
1508 DECL_TEMPLATE(ALushort
, ALfloat
)
1509 DECL_TEMPLATE(ALushort
, ALdouble
)
1510 DECL_TEMPLATE(ALushort
, ALmulaw
)
1511 DECL_TEMPLATE(ALushort
, ALbyte3
)
1512 DECL_TEMPLATE(ALushort
, ALubyte3
)
1514 DECL_TEMPLATE(ALint
, ALbyte
)
1515 DECL_TEMPLATE(ALint
, ALubyte
)
1516 DECL_TEMPLATE(ALint
, ALshort
)
1517 DECL_TEMPLATE(ALint
, ALushort
)
1518 DECL_TEMPLATE(ALint
, ALint
)
1519 DECL_TEMPLATE(ALint
, ALuint
)
1520 DECL_TEMPLATE(ALint
, ALfloat
)
1521 DECL_TEMPLATE(ALint
, ALdouble
)
1522 DECL_TEMPLATE(ALint
, ALmulaw
)
1523 DECL_TEMPLATE(ALint
, ALbyte3
)
1524 DECL_TEMPLATE(ALint
, ALubyte3
)
1526 DECL_TEMPLATE(ALuint
, ALbyte
)
1527 DECL_TEMPLATE(ALuint
, ALubyte
)
1528 DECL_TEMPLATE(ALuint
, ALshort
)
1529 DECL_TEMPLATE(ALuint
, ALushort
)
1530 DECL_TEMPLATE(ALuint
, ALint
)
1531 DECL_TEMPLATE(ALuint
, ALuint
)
1532 DECL_TEMPLATE(ALuint
, ALfloat
)
1533 DECL_TEMPLATE(ALuint
, ALdouble
)
1534 DECL_TEMPLATE(ALuint
, ALmulaw
)
1535 DECL_TEMPLATE(ALuint
, ALbyte3
)
1536 DECL_TEMPLATE(ALuint
, ALubyte3
)
1538 DECL_TEMPLATE(ALfloat
, ALbyte
)
1539 DECL_TEMPLATE(ALfloat
, ALubyte
)
1540 DECL_TEMPLATE(ALfloat
, ALshort
)
1541 DECL_TEMPLATE(ALfloat
, ALushort
)
1542 DECL_TEMPLATE(ALfloat
, ALint
)
1543 DECL_TEMPLATE(ALfloat
, ALuint
)
1544 DECL_TEMPLATE(ALfloat
, ALfloat
)
1545 DECL_TEMPLATE(ALfloat
, ALdouble
)
1546 DECL_TEMPLATE(ALfloat
, ALmulaw
)
1547 DECL_TEMPLATE(ALfloat
, ALbyte3
)
1548 DECL_TEMPLATE(ALfloat
, ALubyte3
)
1550 DECL_TEMPLATE(ALdouble
, ALbyte
)
1551 DECL_TEMPLATE(ALdouble
, ALubyte
)
1552 DECL_TEMPLATE(ALdouble
, ALshort
)
1553 DECL_TEMPLATE(ALdouble
, ALushort
)
1554 DECL_TEMPLATE(ALdouble
, ALint
)
1555 DECL_TEMPLATE(ALdouble
, ALuint
)
1556 DECL_TEMPLATE(ALdouble
, ALfloat
)
1557 DECL_TEMPLATE(ALdouble
, ALdouble
)
1558 DECL_TEMPLATE(ALdouble
, ALmulaw
)
1559 DECL_TEMPLATE(ALdouble
, ALbyte3
)
1560 DECL_TEMPLATE(ALdouble
, ALubyte3
)
1562 DECL_TEMPLATE(ALmulaw
, ALbyte
)
1563 DECL_TEMPLATE(ALmulaw
, ALubyte
)
1564 DECL_TEMPLATE(ALmulaw
, ALshort
)
1565 DECL_TEMPLATE(ALmulaw
, ALushort
)
1566 DECL_TEMPLATE(ALmulaw
, ALint
)
1567 DECL_TEMPLATE(ALmulaw
, ALuint
)
1568 DECL_TEMPLATE(ALmulaw
, ALfloat
)
1569 DECL_TEMPLATE(ALmulaw
, ALdouble
)
1570 DECL_TEMPLATE(ALmulaw
, ALmulaw
)
1571 DECL_TEMPLATE(ALmulaw
, ALbyte3
)
1572 DECL_TEMPLATE(ALmulaw
, ALubyte3
)
1574 DECL_TEMPLATE(ALbyte3
, ALbyte
)
1575 DECL_TEMPLATE(ALbyte3
, ALubyte
)
1576 DECL_TEMPLATE(ALbyte3
, ALshort
)
1577 DECL_TEMPLATE(ALbyte3
, ALushort
)
1578 DECL_TEMPLATE(ALbyte3
, ALint
)
1579 DECL_TEMPLATE(ALbyte3
, ALuint
)
1580 DECL_TEMPLATE(ALbyte3
, ALfloat
)
1581 DECL_TEMPLATE(ALbyte3
, ALdouble
)
1582 DECL_TEMPLATE(ALbyte3
, ALmulaw
)
1583 DECL_TEMPLATE(ALbyte3
, ALbyte3
)
1584 DECL_TEMPLATE(ALbyte3
, ALubyte3
)
1586 DECL_TEMPLATE(ALubyte3
, ALbyte
)
1587 DECL_TEMPLATE(ALubyte3
, ALubyte
)
1588 DECL_TEMPLATE(ALubyte3
, ALshort
)
1589 DECL_TEMPLATE(ALubyte3
, ALushort
)
1590 DECL_TEMPLATE(ALubyte3
, ALint
)
1591 DECL_TEMPLATE(ALubyte3
, ALuint
)
1592 DECL_TEMPLATE(ALubyte3
, ALfloat
)
1593 DECL_TEMPLATE(ALubyte3
, ALdouble
)
1594 DECL_TEMPLATE(ALubyte3
, ALmulaw
)
1595 DECL_TEMPLATE(ALubyte3
, ALbyte3
)
1596 DECL_TEMPLATE(ALubyte3
, ALubyte3
)
1598 #undef DECL_TEMPLATE
1600 #define DECL_TEMPLATE(T) \
1601 static void Convert_##T##_ALima4(T *dst, const ALima4 *src, ALuint numchans, \
1605 ALshort tmp[65*MAXCHANNELS]; /* Max samples an IMA4 frame can be */ \
1606 for(i = 0;i < numblocks;i++) \
1608 DecodeIMA4Block(tmp, src, numchans); \
1609 src += 36*numchans; \
1610 for(j = 0;j < 65*numchans;j++) \
1611 *(dst++) = Conv_##T##_ALshort(tmp[j]); \
1615 DECL_TEMPLATE(ALbyte
)
1616 DECL_TEMPLATE(ALubyte
)
1617 DECL_TEMPLATE(ALshort
)
1618 DECL_TEMPLATE(ALushort
)
1619 DECL_TEMPLATE(ALint
)
1620 DECL_TEMPLATE(ALuint
)
1621 DECL_TEMPLATE(ALfloat
)
1622 DECL_TEMPLATE(ALdouble
)
1623 DECL_TEMPLATE(ALmulaw
)
1624 DECL_TEMPLATE(ALbyte3
)
1625 DECL_TEMPLATE(ALubyte3
)
1627 #undef DECL_TEMPLATE
1629 #define DECL_TEMPLATE(T) \
1630 static void Convert_ALima4_##T(ALima4 *dst, const T *src, ALuint numchans, \
1634 ALshort tmp[65*MAXCHANNELS]; /* Max samples an IMA4 frame can be */ \
1635 ALint sample[MAXCHANNELS] = {0,0,0,0,0,0,0,0}; \
1636 ALint index[MAXCHANNELS] = {0,0,0,0,0,0,0,0}; \
1637 for(i = 0;i < numblocks;i++) \
1639 for(j = 0;j < 65*numchans;j++) \
1640 tmp[j] = Conv_ALshort_##T(*(src++)); \
1641 EncodeIMA4Block(dst, tmp, sample, index, numchans); \
1642 dst += 36*numchans; \
1646 DECL_TEMPLATE(ALbyte
)
1647 DECL_TEMPLATE(ALubyte
)
1648 DECL_TEMPLATE(ALshort
)
1649 DECL_TEMPLATE(ALushort
)
1650 DECL_TEMPLATE(ALint
)
1651 DECL_TEMPLATE(ALuint
)
1652 DECL_TEMPLATE(ALfloat
)
1653 DECL_TEMPLATE(ALdouble
)
1654 DECL_TEMPLATE(ALmulaw
)
1655 static void Convert_ALima4_ALima4(ALima4
*dst
, const ALima4
*src
,
1656 ALuint numchans
, ALuint numblocks
)
1657 { memcpy(dst
, src
, numblocks
*36*numchans
); }
1658 DECL_TEMPLATE(ALbyte3
)
1659 DECL_TEMPLATE(ALubyte3
)
1661 #undef DECL_TEMPLATE
1663 #define DECL_TEMPLATE(T) \
1664 static void Convert_##T(T *dst, const ALvoid *src, enum UserFmtType srcType, \
1665 ALsizei numchans, ALsizei len) \
1670 Convert_##T##_ALbyte(dst, src, numchans, len); \
1672 case UserFmtUByte: \
1673 Convert_##T##_ALubyte(dst, src, numchans, len); \
1675 case UserFmtShort: \
1676 Convert_##T##_ALshort(dst, src, numchans, len); \
1678 case UserFmtUShort: \
1679 Convert_##T##_ALushort(dst, src, numchans, len); \
1682 Convert_##T##_ALint(dst, src, numchans, len); \
1685 Convert_##T##_ALuint(dst, src, numchans, len); \
1687 case UserFmtFloat: \
1688 Convert_##T##_ALfloat(dst, src, numchans, len); \
1690 case UserFmtDouble: \
1691 Convert_##T##_ALdouble(dst, src, numchans, len); \
1693 case UserFmtMulaw: \
1694 Convert_##T##_ALmulaw(dst, src, numchans, len); \
1697 Convert_##T##_ALima4(dst, src, numchans, len); \
1699 case UserFmtByte3: \
1700 Convert_##T##_ALbyte3(dst, src, numchans, len); \
1702 case UserFmtUByte3: \
1703 Convert_##T##_ALubyte3(dst, src, numchans, len); \
1708 DECL_TEMPLATE(ALbyte
)
1709 DECL_TEMPLATE(ALubyte
)
1710 DECL_TEMPLATE(ALshort
)
1711 DECL_TEMPLATE(ALushort
)
1712 DECL_TEMPLATE(ALint
)
1713 DECL_TEMPLATE(ALuint
)
1714 DECL_TEMPLATE(ALfloat
)
1715 DECL_TEMPLATE(ALdouble
)
1716 DECL_TEMPLATE(ALmulaw
)
1717 DECL_TEMPLATE(ALima4
)
1718 DECL_TEMPLATE(ALbyte3
)
1719 DECL_TEMPLATE(ALubyte3
)
1721 #undef DECL_TEMPLATE
1724 static void ConvertData(ALvoid
*dst
, enum UserFmtType dstType
, const ALvoid
*src
, enum UserFmtType srcType
, ALsizei numchans
, ALsizei len
)
1729 Convert_ALbyte(dst
, src
, srcType
, numchans
, len
);
1732 Convert_ALubyte(dst
, src
, srcType
, numchans
, len
);
1735 Convert_ALshort(dst
, src
, srcType
, numchans
, len
);
1738 Convert_ALushort(dst
, src
, srcType
, numchans
, len
);
1741 Convert_ALint(dst
, src
, srcType
, numchans
, len
);
1744 Convert_ALuint(dst
, src
, srcType
, numchans
, len
);
1747 Convert_ALfloat(dst
, src
, srcType
, numchans
, len
);
1750 Convert_ALdouble(dst
, src
, srcType
, numchans
, len
);
1753 Convert_ALmulaw(dst
, src
, srcType
, numchans
, len
);
1756 Convert_ALima4(dst
, src
, srcType
, numchans
, len
);
1759 Convert_ALbyte3(dst
, src
, srcType
, numchans
, len
);
1762 Convert_ALubyte3(dst
, src
, srcType
, numchans
, len
);
1771 * Loads the specified data into the buffer, using the specified formats.
1772 * Currently, the new format must have the same channel configuration as the
1775 static ALenum
LoadData(ALbuffer
*ALBuf
, ALuint freq
, ALenum NewFormat
, ALsizei frames
, enum UserFmtChannels SrcChannels
, enum UserFmtType SrcType
, const ALvoid
*data
, ALboolean storesrc
)
1777 ALuint NewChannels
, NewBytes
;
1778 enum FmtChannels DstChannels
;
1779 enum FmtType DstType
;
1783 if(DecomposeFormat(NewFormat
, &DstChannels
, &DstType
) == AL_FALSE
||
1784 (long)SrcChannels
!= (long)DstChannels
)
1785 return AL_INVALID_ENUM
;
1787 NewChannels
= ChannelsFromFmt(DstChannels
);
1788 NewBytes
= BytesFromFmt(DstType
);
1790 if(SrcType
== UserFmtIMA4
)
1792 ALuint OrigChannels
= ChannelsFromUserFmt(SrcChannels
);
1796 newsize
*= NewBytes
;
1797 newsize
*= NewChannels
;
1798 if(newsize
> INT_MAX
)
1799 return AL_OUT_OF_MEMORY
;
1801 temp
= realloc(ALBuf
->data
, newsize
);
1802 if(!temp
&& newsize
) return AL_OUT_OF_MEMORY
;
1804 ALBuf
->size
= newsize
;
1807 ConvertData(ALBuf
->data
, DstType
, data
, SrcType
, NewChannels
, frames
);
1811 ALBuf
->OriginalChannels
= SrcChannels
;
1812 ALBuf
->OriginalType
= SrcType
;
1813 ALBuf
->OriginalSize
= frames
* 36 * OrigChannels
;
1814 ALBuf
->OriginalAlign
= 36 * OrigChannels
;
1819 ALuint OrigBytes
= BytesFromUserFmt(SrcType
);
1820 ALuint OrigChannels
= ChannelsFromUserFmt(SrcChannels
);
1823 newsize
*= NewBytes
;
1824 newsize
*= NewChannels
;
1825 if(newsize
> INT_MAX
)
1826 return AL_OUT_OF_MEMORY
;
1828 temp
= realloc(ALBuf
->data
, newsize
);
1829 if(!temp
&& newsize
) return AL_OUT_OF_MEMORY
;
1831 ALBuf
->size
= newsize
;
1834 ConvertData(ALBuf
->data
, DstType
, data
, SrcType
, NewChannels
, frames
);
1838 ALBuf
->OriginalChannels
= SrcChannels
;
1839 ALBuf
->OriginalType
= SrcType
;
1840 ALBuf
->OriginalSize
= frames
* OrigBytes
* OrigChannels
;
1841 ALBuf
->OriginalAlign
= OrigBytes
* OrigChannels
;
1847 ALBuf
->OriginalChannels
= DstChannels
;
1848 ALBuf
->OriginalType
= DstType
;
1849 ALBuf
->OriginalSize
= frames
* NewBytes
* NewChannels
;
1850 ALBuf
->OriginalAlign
= NewBytes
* NewChannels
;
1852 ALBuf
->Frequency
= freq
;
1853 ALBuf
->FmtChannels
= DstChannels
;
1854 ALBuf
->FmtType
= DstType
;
1856 ALBuf
->LoopStart
= 0;
1857 ALBuf
->LoopEnd
= newsize
/ NewChannels
/ NewBytes
;
1863 ALuint
BytesFromUserFmt(enum UserFmtType type
)
1867 case UserFmtByte
: return sizeof(ALbyte
);
1868 case UserFmtUByte
: return sizeof(ALubyte
);
1869 case UserFmtShort
: return sizeof(ALshort
);
1870 case UserFmtUShort
: return sizeof(ALushort
);
1871 case UserFmtInt
: return sizeof(ALint
);
1872 case UserFmtUInt
: return sizeof(ALuint
);
1873 case UserFmtFloat
: return sizeof(ALfloat
);
1874 case UserFmtDouble
: return sizeof(ALdouble
);
1875 case UserFmtByte3
: return sizeof(ALbyte3
);
1876 case UserFmtUByte3
: return sizeof(ALubyte3
);
1877 case UserFmtMulaw
: return sizeof(ALubyte
);
1878 case UserFmtIMA4
: break; /* not handled here */
1882 ALuint
ChannelsFromUserFmt(enum UserFmtChannels chans
)
1886 case UserFmtMono
: return 1;
1887 case UserFmtStereo
: return 2;
1888 case UserFmtRear
: return 2;
1889 case UserFmtQuad
: return 4;
1890 case UserFmtX51
: return 6;
1891 case UserFmtX61
: return 7;
1892 case UserFmtX71
: return 8;
1896 ALboolean
DecomposeUserFormat(ALenum format
, enum UserFmtChannels
*chans
,
1897 enum UserFmtType
*type
)
1901 case AL_FORMAT_MONO8
:
1902 *chans
= UserFmtMono
;
1903 *type
= UserFmtUByte
;
1905 case AL_FORMAT_MONO16
:
1906 *chans
= UserFmtMono
;
1907 *type
= UserFmtShort
;
1909 case AL_FORMAT_MONO_FLOAT32
:
1910 *chans
= UserFmtMono
;
1911 *type
= UserFmtFloat
;
1913 case AL_FORMAT_MONO_DOUBLE_EXT
:
1914 *chans
= UserFmtMono
;
1915 *type
= UserFmtDouble
;
1917 case AL_FORMAT_MONO_IMA4
:
1918 *chans
= UserFmtMono
;
1919 *type
= UserFmtIMA4
;
1921 case AL_FORMAT_STEREO8
:
1922 *chans
= UserFmtStereo
;
1923 *type
= UserFmtUByte
;
1925 case AL_FORMAT_STEREO16
:
1926 *chans
= UserFmtStereo
;
1927 *type
= UserFmtShort
;
1929 case AL_FORMAT_STEREO_FLOAT32
:
1930 *chans
= UserFmtStereo
;
1931 *type
= UserFmtFloat
;
1933 case AL_FORMAT_STEREO_DOUBLE_EXT
:
1934 *chans
= UserFmtStereo
;
1935 *type
= UserFmtDouble
;
1937 case AL_FORMAT_STEREO_IMA4
:
1938 *chans
= UserFmtStereo
;
1939 *type
= UserFmtIMA4
;
1941 case AL_FORMAT_QUAD8_LOKI
:
1942 case AL_FORMAT_QUAD8
:
1943 *chans
= UserFmtQuad
;
1944 *type
= UserFmtUByte
;
1946 case AL_FORMAT_QUAD16_LOKI
:
1947 case AL_FORMAT_QUAD16
:
1948 *chans
= UserFmtQuad
;
1949 *type
= UserFmtShort
;
1951 case AL_FORMAT_QUAD32
:
1952 *chans
= UserFmtQuad
;
1953 *type
= UserFmtFloat
;
1955 case AL_FORMAT_REAR8
:
1956 *chans
= UserFmtRear
;
1957 *type
= UserFmtUByte
;
1959 case AL_FORMAT_REAR16
:
1960 *chans
= UserFmtRear
;
1961 *type
= UserFmtShort
;
1963 case AL_FORMAT_REAR32
:
1964 *chans
= UserFmtRear
;
1965 *type
= UserFmtFloat
;
1967 case AL_FORMAT_51CHN8
:
1968 *chans
= UserFmtX51
;
1969 *type
= UserFmtUByte
;
1971 case AL_FORMAT_51CHN16
:
1972 *chans
= UserFmtX51
;
1973 *type
= UserFmtShort
;
1975 case AL_FORMAT_51CHN32
:
1976 *chans
= UserFmtX51
;
1977 *type
= UserFmtFloat
;
1979 case AL_FORMAT_61CHN8
:
1980 *chans
= UserFmtX61
;
1981 *type
= UserFmtUByte
;
1983 case AL_FORMAT_61CHN16
:
1984 *chans
= UserFmtX61
;
1985 *type
= UserFmtShort
;
1987 case AL_FORMAT_61CHN32
:
1988 *chans
= UserFmtX61
;
1989 *type
= UserFmtFloat
;
1991 case AL_FORMAT_71CHN8
:
1992 *chans
= UserFmtX71
;
1993 *type
= UserFmtUByte
;
1995 case AL_FORMAT_71CHN16
:
1996 *chans
= UserFmtX71
;
1997 *type
= UserFmtShort
;
1999 case AL_FORMAT_71CHN32
:
2000 *chans
= UserFmtX71
;
2001 *type
= UserFmtFloat
;
2003 case AL_FORMAT_MONO_MULAW
:
2004 *chans
= UserFmtMono
;
2005 *type
= UserFmtMulaw
;
2007 case AL_FORMAT_STEREO_MULAW
:
2008 *chans
= UserFmtStereo
;
2009 *type
= UserFmtMulaw
;
2011 case AL_FORMAT_QUAD_MULAW
:
2012 *chans
= UserFmtQuad
;
2013 *type
= UserFmtMulaw
;
2015 case AL_FORMAT_REAR_MULAW
:
2016 *chans
= UserFmtRear
;
2017 *type
= UserFmtMulaw
;
2019 case AL_FORMAT_51CHN_MULAW
:
2020 *chans
= UserFmtX51
;
2021 *type
= UserFmtMulaw
;
2023 case AL_FORMAT_61CHN_MULAW
:
2024 *chans
= UserFmtX61
;
2025 *type
= UserFmtMulaw
;
2027 case AL_FORMAT_71CHN_MULAW
:
2028 *chans
= UserFmtX71
;
2029 *type
= UserFmtMulaw
;
2035 ALuint
BytesFromFmt(enum FmtType type
)
2039 case FmtByte
: return sizeof(ALbyte
);
2040 case FmtShort
: return sizeof(ALshort
);
2041 case FmtFloat
: return sizeof(ALfloat
);
2045 ALuint
ChannelsFromFmt(enum FmtChannels chans
)
2049 case FmtMono
: return 1;
2050 case FmtStereo
: return 2;
2051 case FmtRear
: return 2;
2052 case FmtQuad
: return 4;
2053 case FmtX51
: return 6;
2054 case FmtX61
: return 7;
2055 case FmtX71
: return 8;
2059 ALboolean
DecomposeFormat(ALenum format
, enum FmtChannels
*chans
, enum FmtType
*type
)
2087 case AL_FORMAT_QUAD8_LOKI
:
2092 case AL_FORMAT_QUAD16_LOKI
:
2121 case AL_5POINT1_32F
:
2133 case AL_6POINT1_32F
:
2145 case AL_7POINT1_32F
:
2154 static ALboolean
IsValidType(ALenum type
)
2159 case AL_UNSIGNED_BYTE
:
2161 case AL_UNSIGNED_SHORT
:
2163 case AL_UNSIGNED_INT
:
2169 case AL_UNSIGNED_BYTE3
:
2175 static ALboolean
IsValidChannels(ALenum channels
)
2193 * ReleaseALBuffers()
2195 * INTERNAL: Called to destroy any buffers that still exist on the device
2197 ALvoid
ReleaseALBuffers(ALCdevice
*device
)
2200 for(i
= 0;i
< device
->BufferMap
.size
;i
++)
2202 ALbuffer
*temp
= device
->BufferMap
.array
[i
].value
;
2203 device
->BufferMap
.array
[i
].value
= NULL
;
2207 FreeThunkEntry(temp
->buffer
);
2208 memset(temp
, 0, sizeof(ALbuffer
));