2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
21 #define _CRT_SECURE_NO_DEPRECATE // get rid of sprintf security warnings on VS2005
36 static void LoadData(ALbuffer
*ALBuf
, const ALubyte
*data
, ALsizei size
, ALuint freq
, ALenum OrigFormat
, ALenum NewFormat
);
37 static void ConvertData(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
);
38 static void ConvertDataRear(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
);
39 static void ConvertDataIMA4(ALshort
*dst
, const ALvoid
*src
, ALint origChans
, ALsizei len
);
44 * AL Buffers are shared amoung Contexts, so we store the list of generated Buffers
45 * as a global variable in this module. (A valid context is not required to make
46 * AL Buffer function calls
54 static ALbuffer
*g_pBuffers
= NULL
; // Linked List of Buffers
55 static ALuint g_uiBufferCount
= 0; // Buffer Count
57 static const long g_IMAStep_size
[89]={ // IMA ADPCM Stepsize table
58 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
59 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
60 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
61 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
62 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,10442,11487,12635,13899,
63 15289,16818,18500,20350,22358,24633,27086,29794,32767
66 static const long g_IMACodeword_4
[16]={ // IMA4 ADPCM Codeword decode table
67 1, 3, 5, 7, 9, 11, 13, 15,
68 -1,-3,-5,-7,-9,-11,-13,-15,
71 static const long g_IMAIndex_adjust_4
[16]={ // IMA4 ADPCM Step index adjust decode table
72 -1,-1,-1,-1, 2, 4, 6, 8,
73 -1,-1,-1,-1, 2, 4, 6, 8
77 * alGenBuffers(ALsizei n, ALuint *puiBuffers)
79 * Generates n AL Buffers, and stores the Buffers Names in the array pointed to by puiBuffers
81 ALAPI ALvoid ALAPIENTRY
alGenBuffers(ALsizei n
,ALuint
*puiBuffers
)
86 Context
= alcGetCurrentContext();
87 SuspendContext(Context
);
89 // Check that we are actually generation some Buffers
92 // Check the pointer is valid (and points to enough memory to store Buffer Names)
93 if (!IsBadWritePtr((void*)puiBuffers
, n
* sizeof(ALuint
)))
95 ALbuffer
**list
= &g_pBuffers
;
97 list
= &(*list
)->next
;
99 // Create all the new Buffers
102 *list
= calloc(1, sizeof(ALbuffer
));
105 alDeleteBuffers(i
, puiBuffers
);
106 alSetError(AL_OUT_OF_MEMORY
);
110 puiBuffers
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
111 (*list
)->state
= UNUSED
;
115 list
= &(*list
)->next
;
120 // Pointer does not point to enough memory to write Buffer names
121 alSetError(AL_INVALID_VALUE
);
125 ProcessContext(Context
);
131 * alDeleteBuffers(ALsizei n, ALuint *puiBuffers)
133 * Deletes the n AL Buffers pointed to by puiBuffers
135 ALAPI ALvoid ALAPIENTRY
alDeleteBuffers(ALsizei n
, const ALuint
*puiBuffers
)
140 ALboolean bFailed
= AL_FALSE
;
142 Context
= alcGetCurrentContext();
143 SuspendContext(Context
);
145 // Check we are actually Deleting some Buffers
148 // Check that all the buffers are valid and can actually be deleted
149 for (i
= 0; i
< n
; i
++)
151 // Check for valid Buffer ID (can be NULL buffer)
152 if (alIsBuffer(puiBuffers
[i
]))
154 // If not the NULL buffer, check that the reference count is 0
155 ALBuf
= ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(puiBuffers
[i
]));
158 if (ALBuf
->refcount
!= 0)
160 // Buffer still in use, cannot be deleted
161 alSetError(AL_INVALID_OPERATION
);
169 alSetError(AL_INVALID_NAME
);
174 // If all the Buffers were valid (and have Reference Counts of 0), then we can delete them
177 for (i
= 0; i
< n
; i
++)
179 if (puiBuffers
[i
] && alIsBuffer(puiBuffers
[i
]))
181 ALbuffer
**list
= &g_pBuffers
;
183 ALBuf
=((ALbuffer
*)ALTHUNK_LOOKUPENTRY(puiBuffers
[i
]));
184 while(*list
&& *list
!= ALBuf
)
185 list
= &(*list
)->next
;
188 *list
= (*list
)->next
;
190 // Release the memory used to store audio data
193 // Release buffer structure
194 ALTHUNK_REMOVEENTRY(puiBuffers
[i
]);
195 memset(ALBuf
, 0, sizeof(ALbuffer
));
203 alSetError(AL_INVALID_VALUE
);
205 ProcessContext(Context
);
212 * alIsBuffer(ALuint uiBuffer)
214 * Checks if ulBuffer is a valid Buffer Name
216 ALAPI ALboolean ALAPIENTRY
alIsBuffer(ALuint uiBuffer
)
219 ALboolean result
=AL_FALSE
;
223 Context
= alcGetCurrentContext();
224 SuspendContext(Context
);
228 TgtALBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(uiBuffer
);
230 // Check through list of generated buffers for uiBuffer
234 if (ALBuf
== TgtALBuf
)
249 ProcessContext(Context
);
255 * alBufferData(ALuint buffer,ALenum format,ALvoid *data,ALsizei size,ALsizei freq)
257 * Fill buffer with audio data
259 ALAPI ALvoid ALAPIENTRY
alBufferData(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei size
,ALsizei freq
)
266 Context
= alcGetCurrentContext();
267 SuspendContext(Context
);
269 if (alIsBuffer(buffer
) && (buffer
!= 0))
271 ALBuf
=((ALbuffer
*)ALTHUNK_LOOKUPENTRY(buffer
));
272 if ((ALBuf
->refcount
==0)&&(data
))
276 case AL_FORMAT_MONO8
:
277 case AL_FORMAT_MONO16
:
278 case AL_FORMAT_MONO_FLOAT32
:
279 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_MONO16
);
282 case AL_FORMAT_STEREO8
:
283 case AL_FORMAT_STEREO16
:
284 case AL_FORMAT_STEREO_FLOAT32
:
285 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_STEREO16
);
288 case AL_FORMAT_REAR8
:
289 case AL_FORMAT_REAR16
:
290 case AL_FORMAT_REAR32
: {
291 ALuint NewFormat
= AL_FORMAT_QUAD16
;
292 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
293 ALuint OrigBytes
= ((format
==AL_FORMAT_REAR8
) ? 1 :
294 ((format
==AL_FORMAT_REAR16
) ? 2 :
297 assert(aluBytesFromFormat(NewFormat
) == 2);
299 if((size
%(OrigBytes
*2)) != 0)
301 alSetError(AL_INVALID_VALUE
);
308 // Samples are converted to 16 bit here
309 temp
= realloc(ALBuf
->data
, (padding
*NewChannels
+ size
) * sizeof(ALshort
));
313 ConvertDataRear(ALBuf
->data
, data
, OrigBytes
, size
);
315 memset(&(ALBuf
->data
[size
]), 0, padding
*NewChannels
*sizeof(ALshort
));
317 ALBuf
->format
= NewFormat
;
318 ALBuf
->eOriginalFormat
= format
;
319 ALBuf
->size
= size
*sizeof(ALshort
);
320 ALBuf
->frequency
= freq
;
321 ALBuf
->padding
= padding
;
324 alSetError(AL_OUT_OF_MEMORY
);
327 case AL_FORMAT_QUAD8_LOKI
:
328 case AL_FORMAT_QUAD16_LOKI
:
329 case AL_FORMAT_QUAD8
:
330 case AL_FORMAT_QUAD16
:
331 case AL_FORMAT_QUAD32
:
332 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_QUAD16
);
335 case AL_FORMAT_51CHN8
:
336 case AL_FORMAT_51CHN16
:
337 case AL_FORMAT_51CHN32
:
338 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_51CHN16
);
341 case AL_FORMAT_61CHN8
:
342 case AL_FORMAT_61CHN16
:
343 case AL_FORMAT_61CHN32
:
344 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_61CHN16
);
347 case AL_FORMAT_71CHN8
:
348 case AL_FORMAT_71CHN16
:
349 case AL_FORMAT_71CHN32
:
350 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_71CHN16
);
353 case AL_FORMAT_MONO_IMA4
:
354 case AL_FORMAT_STEREO_IMA4
: {
355 int OrigChans
= ((format
==AL_FORMAT_MONO_IMA4
) ? 1 : 2);
357 // Here is where things vary:
358 // nVidia and Apple use 64+1 samples per channel per block => block_size=36*chans bytes
359 // Most PC sound software uses 2040+1 samples per channel per block -> block_size=1024*chans bytes
360 if((size
%(36*OrigChans
)) != 0)
362 alSetError(AL_INVALID_VALUE
);
369 // Allocate extra padding samples
370 temp
= realloc(ALBuf
->data
, (padding
*OrigChans
+ size
)*sizeof(ALshort
));
374 ConvertDataIMA4(ALBuf
->data
, data
, OrigChans
, size
/65);
376 memset(&(ALBuf
->data
[size
]), 0, padding
*sizeof(ALshort
)*OrigChans
);
378 ALBuf
->format
= ((OrigChans
==1) ? AL_FORMAT_MONO16
: AL_FORMAT_STEREO16
);
379 ALBuf
->eOriginalFormat
= format
;
380 ALBuf
->size
= size
*sizeof(ALshort
);
381 ALBuf
->frequency
= freq
;
382 ALBuf
->padding
= padding
;
385 alSetError(AL_OUT_OF_MEMORY
);
389 alSetError(AL_INVALID_ENUM
);
395 // Buffer is in use, or data is a NULL pointer
396 alSetError(AL_INVALID_VALUE
);
401 // Invalid Buffer Name
402 alSetError(AL_INVALID_NAME
);
405 ProcessContext(Context
);
409 * alBufferSubDataEXT(ALuint buffer,ALenum format,ALvoid *data,ALsizei offset,ALsizei length)
411 * Fill buffer with audio data
413 ALvoid ALAPIENTRY
alBufferSubDataEXT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
418 Context
= alcGetCurrentContext();
419 SuspendContext(Context
);
421 if(alIsBuffer(buffer
) && buffer
!= 0)
423 ALBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(buffer
);
424 if(ALBuf
->data
== NULL
)
426 // buffer does not have any data
427 alSetError(AL_INVALID_NAME
);
429 else if(length
< 0 || offset
< 0 || (length
> 0 && data
== NULL
))
431 // data is NULL or offset/length is negative
432 alSetError(AL_INVALID_VALUE
);
438 case AL_FORMAT_REAR8
:
439 case AL_FORMAT_REAR16
:
440 case AL_FORMAT_REAR32
: {
441 ALuint OrigBytes
= ((format
==AL_FORMAT_REAR8
) ? 1 :
442 ((format
==AL_FORMAT_REAR16
) ? 2 :
445 if(ALBuf
->eOriginalFormat
!= AL_FORMAT_REAR8
&&
446 ALBuf
->eOriginalFormat
!= AL_FORMAT_REAR16
&&
447 ALBuf
->eOriginalFormat
!= AL_FORMAT_REAR32
)
449 alSetError(AL_INVALID_ENUM
);
453 if(ALBuf
->size
/4/sizeof(ALshort
) < (ALuint
)offset
+length
)
455 alSetError(AL_INVALID_VALUE
);
459 ConvertDataRear(&ALBuf
->data
[offset
*4], data
, OrigBytes
, length
*2);
462 case AL_FORMAT_MONO_IMA4
:
463 case AL_FORMAT_STEREO_IMA4
: {
464 int Channels
= aluChannelsFromFormat(ALBuf
->format
);
466 if(ALBuf
->eOriginalFormat
!= format
)
468 alSetError(AL_INVALID_ENUM
);
472 if((offset
%65) != 0 || (length
%65) != 0 ||
473 ALBuf
->size
/Channels
/sizeof(ALshort
) < (ALuint
)offset
+length
)
475 alSetError(AL_INVALID_VALUE
);
479 ConvertDataIMA4(&ALBuf
->data
[offset
*Channels
], data
, Channels
, length
/65*Channels
);
483 ALuint Channels
= aluChannelsFromFormat(format
);
484 ALuint Bytes
= aluBytesFromFormat(format
);
486 if(Channels
!= aluChannelsFromFormat(ALBuf
->format
))
488 alSetError(AL_INVALID_ENUM
);
492 if(ALBuf
->size
/Channels
/sizeof(ALshort
) < (ALuint
)offset
+length
)
494 alSetError(AL_INVALID_VALUE
);
498 ConvertData(&ALBuf
->data
[offset
*Channels
], data
, Bytes
, length
*Channels
);
505 // Invalid Buffer Name
506 alSetError(AL_INVALID_NAME
);
509 ProcessContext(Context
);
513 ALAPI
void ALAPIENTRY
alBufferf(ALuint buffer
, ALenum eParam
, ALfloat flValue
)
515 ALCcontext
*pContext
;
519 pContext
= alcGetCurrentContext();
520 SuspendContext(pContext
);
522 if (alIsBuffer(buffer
) && (buffer
!= 0))
527 alSetError(AL_INVALID_ENUM
);
533 alSetError(AL_INVALID_NAME
);
536 ProcessContext(pContext
);
540 ALAPI
void ALAPIENTRY
alBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat flValue1
, ALfloat flValue2
, ALfloat flValue3
)
542 ALCcontext
*pContext
;
548 pContext
= alcGetCurrentContext();
549 SuspendContext(pContext
);
551 if (alIsBuffer(buffer
) && (buffer
!= 0))
556 alSetError(AL_INVALID_ENUM
);
562 alSetError(AL_INVALID_NAME
);
565 ProcessContext(pContext
);
569 ALAPI
void ALAPIENTRY
alBufferfv(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
)
571 ALCcontext
*pContext
;
575 pContext
= alcGetCurrentContext();
576 SuspendContext(pContext
);
578 if (alIsBuffer(buffer
) && (buffer
!= 0))
583 alSetError(AL_INVALID_ENUM
);
589 alSetError(AL_INVALID_NAME
);
592 ProcessContext(pContext
);
596 ALAPI
void ALAPIENTRY
alBufferi(ALuint buffer
, ALenum eParam
, ALint lValue
)
598 ALCcontext
*pContext
;
602 pContext
= alcGetCurrentContext();
603 SuspendContext(pContext
);
605 if (alIsBuffer(buffer
) && (buffer
!= 0))
610 alSetError(AL_INVALID_ENUM
);
616 alSetError(AL_INVALID_NAME
);
619 ProcessContext(pContext
);
623 ALAPI
void ALAPIENTRY
alBuffer3i( ALuint buffer
, ALenum eParam
, ALint lValue1
, ALint lValue2
, ALint lValue3
)
625 ALCcontext
*pContext
;
631 pContext
= alcGetCurrentContext();
632 SuspendContext(pContext
);
634 if (alIsBuffer(buffer
) && (buffer
!= 0))
639 alSetError(AL_INVALID_ENUM
);
645 alSetError(AL_INVALID_NAME
);
648 ProcessContext(pContext
);
652 ALAPI
void ALAPIENTRY
alBufferiv(ALuint buffer
, ALenum eParam
, const ALint
* plValues
)
654 ALCcontext
*pContext
;
658 pContext
= alcGetCurrentContext();
659 SuspendContext(pContext
);
661 if (alIsBuffer(buffer
) && (buffer
!= 0))
666 alSetError(AL_INVALID_ENUM
);
672 alSetError(AL_INVALID_NAME
);
675 ProcessContext(pContext
);
679 ALAPI ALvoid ALAPIENTRY
alGetBufferf(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
)
681 ALCcontext
*pContext
;
683 pContext
= alcGetCurrentContext();
684 SuspendContext(pContext
);
688 if (alIsBuffer(buffer
) && (buffer
!= 0))
693 alSetError(AL_INVALID_ENUM
);
699 alSetError(AL_INVALID_NAME
);
704 alSetError(AL_INVALID_VALUE
);
707 ProcessContext(pContext
);
711 ALAPI
void ALAPIENTRY
alGetBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat
* pflValue1
, ALfloat
* pflValue2
, ALfloat
* pflValue3
)
713 ALCcontext
*pContext
;
715 pContext
= alcGetCurrentContext();
716 SuspendContext(pContext
);
718 if ((pflValue1
) && (pflValue2
) && (pflValue3
))
720 if (alIsBuffer(buffer
) && (buffer
!= 0))
725 alSetError(AL_INVALID_ENUM
);
731 alSetError(AL_INVALID_NAME
);
736 alSetError(AL_INVALID_VALUE
);
739 ProcessContext(pContext
);
743 ALAPI
void ALAPIENTRY
alGetBufferfv(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
)
745 ALCcontext
*pContext
;
747 pContext
= alcGetCurrentContext();
748 SuspendContext(pContext
);
752 if (alIsBuffer(buffer
) && (buffer
!= 0))
757 alSetError(AL_INVALID_ENUM
);
763 alSetError(AL_INVALID_NAME
);
768 alSetError(AL_INVALID_VALUE
);
771 ProcessContext(pContext
);
775 ALAPI ALvoid ALAPIENTRY
alGetBufferi(ALuint buffer
, ALenum eParam
, ALint
*plValue
)
777 ALCcontext
*pContext
;
780 pContext
= alcGetCurrentContext();
781 SuspendContext(pContext
);
785 if (alIsBuffer(buffer
) && (buffer
!= 0))
787 pBuffer
= ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(buffer
));
792 *plValue
= pBuffer
->frequency
;
796 *plValue
= aluBytesFromFormat(pBuffer
->format
) * 8;
800 *plValue
= aluChannelsFromFormat(pBuffer
->format
);
804 *plValue
= pBuffer
->size
;
808 alSetError(AL_INVALID_ENUM
);
814 alSetError(AL_INVALID_NAME
);
819 alSetError(AL_INVALID_VALUE
);
822 ProcessContext(pContext
);
826 ALAPI
void ALAPIENTRY
alGetBuffer3i(ALuint buffer
, ALenum eParam
, ALint
* plValue1
, ALint
* plValue2
, ALint
* plValue3
)
828 ALCcontext
*pContext
;
830 pContext
= alcGetCurrentContext();
831 SuspendContext(pContext
);
833 if ((plValue1
) && (plValue2
) && (plValue3
))
835 if (alIsBuffer(buffer
) && (buffer
!= 0))
840 alSetError(AL_INVALID_ENUM
);
846 alSetError(AL_INVALID_NAME
);
851 alSetError(AL_INVALID_VALUE
);
854 ProcessContext(pContext
);
858 ALAPI
void ALAPIENTRY
alGetBufferiv(ALuint buffer
, ALenum eParam
, ALint
* plValues
)
860 ALCcontext
*pContext
;
862 pContext
= alcGetCurrentContext();
863 SuspendContext(pContext
);
867 if (alIsBuffer(buffer
) && (buffer
!= 0))
875 alGetBufferi(buffer
, eParam
, plValues
);
879 alSetError(AL_INVALID_ENUM
);
885 alSetError(AL_INVALID_NAME
);
890 alSetError(AL_INVALID_VALUE
);
893 ProcessContext(pContext
);
899 * Loads the specified data into the buffer, using the specified formats.
900 * Currently, the new format must be 16-bit, and must have the same channel
901 * configuration as the original format. This does NOT handle compressed
902 * formats (eg. IMA4).
904 static void LoadData(ALbuffer
*ALBuf
, const ALubyte
*data
, ALsizei size
, ALuint freq
, ALenum OrigFormat
, ALenum NewFormat
)
906 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
907 ALuint OrigBytes
= aluBytesFromFormat(OrigFormat
);
908 ALuint OrigChannels
= aluChannelsFromFormat(OrigFormat
);
912 assert(aluBytesFromFormat(NewFormat
) == 2);
913 assert(NewChannels
== OrigChannels
);
915 if ((size
%(OrigBytes
*OrigChannels
)) != 0)
917 alSetError(AL_INVALID_VALUE
);
921 // Samples are converted to 16 bit here
923 temp
= realloc(ALBuf
->data
, (padding
*NewChannels
+ size
) * sizeof(ALshort
));
927 ConvertData(ALBuf
->data
, data
, OrigBytes
, size
);
929 memset(&(ALBuf
->data
[size
]), 0, padding
*NewChannels
*sizeof(ALshort
));
931 ALBuf
->format
= NewFormat
;
932 ALBuf
->eOriginalFormat
= OrigFormat
;
933 ALBuf
->size
= size
*sizeof(ALshort
);
934 ALBuf
->frequency
= freq
;
935 ALBuf
->padding
= padding
;
938 alSetError(AL_OUT_OF_MEMORY
);
941 static void ConvertData(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
)
947 for(i
= 0;i
< len
;i
++)
948 dst
[i
] = ((ALshort
)((ALubyte
*)src
)[i
] - 128) << 8;
952 memcpy(dst
, src
, len
*sizeof(ALshort
));
956 for(i
= 0;i
< len
;i
++)
959 smp
= (((ALfloat
*)src
)[i
] * 32767.5f
- 0.5f
);
960 smp
= min(smp
, 32767);
961 smp
= max(smp
, -32768);
962 dst
[i
] = (ALshort
)smp
;
971 static void ConvertDataRear(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
)
977 for(i
= 0;i
< len
;i
+=4)
981 dst
[i
+2] = ((ALshort
)((ALubyte
*)src
)[i
/2+0] - 128) << 8;
982 dst
[i
+3] = ((ALshort
)((ALubyte
*)src
)[i
/2+1] - 128) << 8;
987 for(i
= 0;i
< len
;i
+=4)
991 dst
[i
+2] = ((ALshort
*)src
)[i
/2+0];
992 dst
[i
+3] = ((ALshort
*)src
)[i
/2+1];
997 for(i
= 0;i
< len
;i
+=4)
1002 smp
= (((ALfloat
*)src
)[i
/2+0] * 32767.5f
- 0.5);
1003 smp
= min(smp
, 32767);
1004 smp
= max(smp
, -32768);
1005 dst
[i
+2] = (ALshort
)smp
;
1006 smp
= (((ALfloat
*)src
)[i
/2+1] * 32767.5f
- 0.5);
1007 smp
= min(smp
, 32767);
1008 smp
= max(smp
, -32768);
1009 dst
[i
+3] = (ALshort
)smp
;
1018 static void ConvertDataIMA4(ALshort
*dst
, const ALvoid
*src
, ALint origChans
, ALsizei len
)
1020 const ALuint
*IMAData
;
1021 ALint Sample
[2],Index
[2];
1025 assert(origChans
<= 2);
1028 for(i
= 0;i
< len
/origChans
;i
++)
1030 for(c
= 0;c
< origChans
;c
++)
1032 Sample
[c
] = ((ALshort
*)IMAData
)[0];
1033 Index
[c
] = ((ALshort
*)IMAData
)[1];
1035 Index
[c
] = ((Index
[c
]<0) ? 0 : Index
[c
]);
1036 Index
[c
] = ((Index
[c
]>88) ? 88 : Index
[c
]);
1038 dst
[i
*65*origChans
+ c
] = (ALshort
)Sample
[c
];
1043 for(j
= 1;j
< 65;j
+= 8)
1045 for(c
= 0;c
< origChans
;c
++)
1046 IMACode
[c
] = *(IMAData
++);
1048 for(k
= 0;k
< 8;k
++)
1050 for(c
= 0;c
< origChans
;c
++)
1052 Sample
[c
] += ((g_IMAStep_size
[Index
[c
]]*g_IMACodeword_4
[IMACode
[c
]&15])/8);
1053 Index
[c
] += g_IMAIndex_adjust_4
[IMACode
[c
]&15];
1055 if(Sample
[c
] < -32768) Sample
[c
] = -32768;
1056 else if(Sample
[c
] > 32767) Sample
[c
] = 32767;
1058 if(Index
[c
]<0) Index
[c
] = 0;
1059 else if(Index
[c
]>88) Index
[c
] = 88;
1061 dst
[(i
*65+j
+k
)*origChans
+ c
] = (ALshort
)Sample
[c
];
1070 * ReleaseALBuffers()
1072 * INTERNAL FN : Called by DLLMain on exit to destroy any buffers that still exist
1074 ALvoid
ReleaseALBuffers(ALvoid
)
1077 ALbuffer
*ALBufferTemp
;
1080 if(g_uiBufferCount
> 0)
1081 AL_PRINT("exit(): deleting %d Buffer(s)\n", g_uiBufferCount
);
1084 ALBuffer
= g_pBuffers
;
1087 // Release sample data
1088 free(ALBuffer
->data
);
1090 // Release Buffer structure
1091 ALBufferTemp
= ALBuffer
;
1092 ALBuffer
= ALBuffer
->next
;
1093 memset(ALBufferTemp
, 0, sizeof(ALbuffer
));
1097 g_uiBufferCount
= 0;