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
31 #include "alDatabuffer.h"
35 static void LoadData(ALbuffer
*ALBuf
, const ALubyte
*data
, ALsizei size
, ALuint freq
, ALenum OrigFormat
, ALenum NewFormat
);
36 static void ConvertData(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
);
37 static void ConvertDataRear(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
);
38 static void ConvertDataIMA4(ALshort
*dst
, const ALvoid
*src
, ALint origChans
, ALsizei len
);
43 * AL Buffers are shared amoung Contexts, so we store the list of generated Buffers
44 * as a global variable in this module. (A valid context is not required to make
45 * AL Buffer function calls
53 static const long g_IMAStep_size
[89]={ // IMA ADPCM Stepsize table
54 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19, 21, 23, 25, 28, 31,
55 34, 37, 41, 45, 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143,
56 157, 173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449, 494, 544, 598, 658,
57 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024,
58 3327, 3660, 4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,10442,11487,12635,13899,
59 15289,16818,18500,20350,22358,24633,27086,29794,32767
62 static const long g_IMACodeword_4
[16]={ // IMA4 ADPCM Codeword decode table
63 1, 3, 5, 7, 9, 11, 13, 15,
64 -1,-3,-5,-7,-9,-11,-13,-15,
67 static const long g_IMAIndex_adjust_4
[16]={ // IMA4 ADPCM Step index adjust decode table
68 -1,-1,-1,-1, 2, 4, 6, 8,
69 -1,-1,-1,-1, 2, 4, 6, 8
73 * alGenBuffers(ALsizei n, ALuint *puiBuffers)
75 * Generates n AL Buffers, and stores the Buffers Names in the array pointed to by puiBuffers
77 ALAPI ALvoid ALAPIENTRY
alGenBuffers(ALsizei n
,ALuint
*puiBuffers
)
82 Context
= GetContextSuspended();
85 // Check that we are actually generation some Buffers
88 ALCdevice
*device
= Context
->Device
;
90 // Check the pointer is valid (and points to enough memory to store Buffer Names)
91 if (!IsBadWritePtr((void*)puiBuffers
, n
* sizeof(ALuint
)))
93 ALbuffer
**list
= &device
->Buffers
;
95 list
= &(*list
)->next
;
97 // Create all the new Buffers
100 *list
= calloc(1, sizeof(ALbuffer
));
103 alDeleteBuffers(i
, puiBuffers
);
104 alSetError(AL_OUT_OF_MEMORY
);
108 puiBuffers
[i
] = (ALuint
)ALTHUNK_ADDENTRY(*list
);
109 (*list
)->state
= UNUSED
;
110 device
->BufferCount
++;
113 list
= &(*list
)->next
;
118 // Pointer does not point to enough memory to write Buffer names
119 alSetError(AL_INVALID_VALUE
);
123 ProcessContext(Context
);
129 * alDeleteBuffers(ALsizei n, ALuint *puiBuffers)
131 * Deletes the n AL Buffers pointed to by puiBuffers
133 ALAPI ALvoid ALAPIENTRY
alDeleteBuffers(ALsizei n
, const ALuint
*puiBuffers
)
138 ALboolean bFailed
= AL_FALSE
;
140 Context
= GetContextSuspended();
143 // Check we are actually Deleting some Buffers
146 ALCdevice
*device
= Context
->Device
;
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
= &device
->Buffers
;
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
));
196 device
->BufferCount
--;
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
= GetContextSuspended();
224 if(!Context
) return AL_FALSE
;
228 ALCdevice
*device
= Context
->Device
;
230 TgtALBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(uiBuffer
);
232 // Check through list of generated buffers for uiBuffer
233 ALBuf
= device
->Buffers
;
236 if (ALBuf
== TgtALBuf
)
251 ProcessContext(Context
);
257 * alBufferData(ALuint buffer,ALenum format,ALvoid *data,ALsizei size,ALsizei freq)
259 * Fill buffer with audio data
261 ALAPI ALvoid ALAPIENTRY
alBufferData(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei size
,ALsizei freq
)
268 Context
= GetContextSuspended();
271 if (alIsBuffer(buffer
) && (buffer
!= 0))
273 ALBuf
=((ALbuffer
*)ALTHUNK_LOOKUPENTRY(buffer
));
275 if(Context
->SampleSource
)
279 if(Context
->SampleSource
->state
== MAPPED
)
281 alSetError(AL_INVALID_OPERATION
);
282 ProcessContext(Context
);
286 offset
= (ALuint
)data
;
287 data
= Context
->SampleSource
->data
+ offset
;
290 if ((ALBuf
->refcount
==0)&&(data
))
294 case AL_FORMAT_MONO8
:
295 case AL_FORMAT_MONO16
:
296 case AL_FORMAT_MONO_FLOAT32
:
297 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_MONO16
);
300 case AL_FORMAT_STEREO8
:
301 case AL_FORMAT_STEREO16
:
302 case AL_FORMAT_STEREO_FLOAT32
:
303 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_STEREO16
);
306 case AL_FORMAT_REAR8
:
307 case AL_FORMAT_REAR16
:
308 case AL_FORMAT_REAR32
: {
309 ALuint NewFormat
= AL_FORMAT_QUAD16
;
310 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
311 ALuint OrigBytes
= ((format
==AL_FORMAT_REAR8
) ? 1 :
312 ((format
==AL_FORMAT_REAR16
) ? 2 :
315 assert(aluBytesFromFormat(NewFormat
) == 2);
317 if((size
%(OrigBytes
*2)) != 0)
319 alSetError(AL_INVALID_VALUE
);
326 // Samples are converted to 16 bit here
327 temp
= realloc(ALBuf
->data
, (padding
*NewChannels
+ size
) * sizeof(ALshort
));
331 ConvertDataRear(ALBuf
->data
, data
, OrigBytes
, size
);
333 memset(&(ALBuf
->data
[size
]), 0, padding
*NewChannels
*sizeof(ALshort
));
335 ALBuf
->format
= NewFormat
;
336 ALBuf
->eOriginalFormat
= format
;
337 ALBuf
->size
= size
*sizeof(ALshort
);
338 ALBuf
->frequency
= freq
;
339 ALBuf
->padding
= padding
;
342 alSetError(AL_OUT_OF_MEMORY
);
345 case AL_FORMAT_QUAD8_LOKI
:
346 case AL_FORMAT_QUAD16_LOKI
:
347 case AL_FORMAT_QUAD8
:
348 case AL_FORMAT_QUAD16
:
349 case AL_FORMAT_QUAD32
:
350 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_QUAD16
);
353 case AL_FORMAT_51CHN8
:
354 case AL_FORMAT_51CHN16
:
355 case AL_FORMAT_51CHN32
:
356 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_51CHN16
);
359 case AL_FORMAT_61CHN8
:
360 case AL_FORMAT_61CHN16
:
361 case AL_FORMAT_61CHN32
:
362 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_61CHN16
);
365 case AL_FORMAT_71CHN8
:
366 case AL_FORMAT_71CHN16
:
367 case AL_FORMAT_71CHN32
:
368 LoadData(ALBuf
, data
, size
, freq
, format
, AL_FORMAT_71CHN16
);
371 case AL_FORMAT_MONO_IMA4
:
372 case AL_FORMAT_STEREO_IMA4
: {
373 int OrigChans
= ((format
==AL_FORMAT_MONO_IMA4
) ? 1 : 2);
375 // Here is where things vary:
376 // nVidia and Apple use 64+1 samples per channel per block => block_size=36*chans bytes
377 // Most PC sound software uses 2040+1 samples per channel per block -> block_size=1024*chans bytes
378 if((size
%(36*OrigChans
)) != 0)
380 alSetError(AL_INVALID_VALUE
);
387 // Allocate extra padding samples
388 temp
= realloc(ALBuf
->data
, (padding
*OrigChans
+ size
)*sizeof(ALshort
));
392 ConvertDataIMA4(ALBuf
->data
, data
, OrigChans
, size
/65);
394 memset(&(ALBuf
->data
[size
]), 0, padding
*sizeof(ALshort
)*OrigChans
);
396 ALBuf
->format
= ((OrigChans
==1) ? AL_FORMAT_MONO16
: AL_FORMAT_STEREO16
);
397 ALBuf
->eOriginalFormat
= format
;
398 ALBuf
->size
= size
*sizeof(ALshort
);
399 ALBuf
->frequency
= freq
;
400 ALBuf
->padding
= padding
;
403 alSetError(AL_OUT_OF_MEMORY
);
407 alSetError(AL_INVALID_ENUM
);
413 // Buffer is in use, or data is a NULL pointer
414 alSetError(AL_INVALID_VALUE
);
419 // Invalid Buffer Name
420 alSetError(AL_INVALID_NAME
);
423 ProcessContext(Context
);
427 * alBufferSubDataEXT(ALuint buffer,ALenum format,ALvoid *data,ALsizei offset,ALsizei length)
429 * Fill buffer with audio data
431 ALvoid ALAPIENTRY
alBufferSubDataEXT(ALuint buffer
,ALenum format
,const ALvoid
*data
,ALsizei offset
,ALsizei length
)
436 Context
= GetContextSuspended();
439 if(alIsBuffer(buffer
) && buffer
!= 0)
441 ALBuf
= (ALbuffer
*)ALTHUNK_LOOKUPENTRY(buffer
);
443 if(Context
->SampleSource
)
447 if(Context
->SampleSource
->state
== MAPPED
)
449 alSetError(AL_INVALID_OPERATION
);
450 ProcessContext(Context
);
454 offset
= (ALuint
)data
;
455 data
= Context
->SampleSource
->data
+ offset
;
458 if(ALBuf
->data
== NULL
)
460 // buffer does not have any data
461 alSetError(AL_INVALID_NAME
);
463 else if(length
< 0 || offset
< 0 || (length
> 0 && data
== NULL
))
465 // data is NULL or offset/length is negative
466 alSetError(AL_INVALID_VALUE
);
472 case AL_FORMAT_REAR8
:
473 case AL_FORMAT_REAR16
:
474 case AL_FORMAT_REAR32
: {
475 ALuint OrigBytes
= ((format
==AL_FORMAT_REAR8
) ? 1 :
476 ((format
==AL_FORMAT_REAR16
) ? 2 :
479 if(ALBuf
->eOriginalFormat
!= AL_FORMAT_REAR8
&&
480 ALBuf
->eOriginalFormat
!= AL_FORMAT_REAR16
&&
481 ALBuf
->eOriginalFormat
!= AL_FORMAT_REAR32
)
483 alSetError(AL_INVALID_ENUM
);
487 if(ALBuf
->size
/4/sizeof(ALshort
) < (ALuint
)offset
+length
)
489 alSetError(AL_INVALID_VALUE
);
493 ConvertDataRear(&ALBuf
->data
[offset
*4], data
, OrigBytes
, length
*2);
496 case AL_FORMAT_MONO_IMA4
:
497 case AL_FORMAT_STEREO_IMA4
: {
498 int Channels
= aluChannelsFromFormat(ALBuf
->format
);
500 if(ALBuf
->eOriginalFormat
!= format
)
502 alSetError(AL_INVALID_ENUM
);
506 if((offset
%65) != 0 || (length
%65) != 0 ||
507 ALBuf
->size
/Channels
/sizeof(ALshort
) < (ALuint
)offset
+length
)
509 alSetError(AL_INVALID_VALUE
);
513 ConvertDataIMA4(&ALBuf
->data
[offset
*Channels
], data
, Channels
, length
/65*Channels
);
517 ALuint Channels
= aluChannelsFromFormat(format
);
518 ALuint Bytes
= aluBytesFromFormat(format
);
520 if(Channels
!= aluChannelsFromFormat(ALBuf
->format
))
522 alSetError(AL_INVALID_ENUM
);
526 if(ALBuf
->size
/Channels
/sizeof(ALshort
) < (ALuint
)offset
+length
)
528 alSetError(AL_INVALID_VALUE
);
532 ConvertData(&ALBuf
->data
[offset
*Channels
], data
, Bytes
, length
*Channels
);
539 // Invalid Buffer Name
540 alSetError(AL_INVALID_NAME
);
543 ProcessContext(Context
);
547 ALAPI
void ALAPIENTRY
alBufferf(ALuint buffer
, ALenum eParam
, ALfloat flValue
)
549 ALCcontext
*pContext
;
553 pContext
= GetContextSuspended();
554 if(!pContext
) return;
556 if (alIsBuffer(buffer
) && (buffer
!= 0))
561 alSetError(AL_INVALID_ENUM
);
567 alSetError(AL_INVALID_NAME
);
570 ProcessContext(pContext
);
574 ALAPI
void ALAPIENTRY
alBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat flValue1
, ALfloat flValue2
, ALfloat flValue3
)
576 ALCcontext
*pContext
;
582 pContext
= GetContextSuspended();
583 if(!pContext
) return;
585 if (alIsBuffer(buffer
) && (buffer
!= 0))
590 alSetError(AL_INVALID_ENUM
);
596 alSetError(AL_INVALID_NAME
);
599 ProcessContext(pContext
);
603 ALAPI
void ALAPIENTRY
alBufferfv(ALuint buffer
, ALenum eParam
, const ALfloat
* flValues
)
605 ALCcontext
*pContext
;
609 pContext
= GetContextSuspended();
610 if(!pContext
) return;
612 if (alIsBuffer(buffer
) && (buffer
!= 0))
617 alSetError(AL_INVALID_ENUM
);
623 alSetError(AL_INVALID_NAME
);
626 ProcessContext(pContext
);
630 ALAPI
void ALAPIENTRY
alBufferi(ALuint buffer
, ALenum eParam
, ALint lValue
)
632 ALCcontext
*pContext
;
636 pContext
= GetContextSuspended();
637 if(!pContext
) return;
639 if (alIsBuffer(buffer
) && (buffer
!= 0))
644 alSetError(AL_INVALID_ENUM
);
650 alSetError(AL_INVALID_NAME
);
653 ProcessContext(pContext
);
657 ALAPI
void ALAPIENTRY
alBuffer3i( ALuint buffer
, ALenum eParam
, ALint lValue1
, ALint lValue2
, ALint lValue3
)
659 ALCcontext
*pContext
;
665 pContext
= GetContextSuspended();
666 if(!pContext
) return;
668 if (alIsBuffer(buffer
) && (buffer
!= 0))
673 alSetError(AL_INVALID_ENUM
);
679 alSetError(AL_INVALID_NAME
);
682 ProcessContext(pContext
);
686 ALAPI
void ALAPIENTRY
alBufferiv(ALuint buffer
, ALenum eParam
, const ALint
* plValues
)
688 ALCcontext
*pContext
;
692 pContext
= GetContextSuspended();
693 if(!pContext
) return;
695 if (alIsBuffer(buffer
) && (buffer
!= 0))
700 alSetError(AL_INVALID_ENUM
);
706 alSetError(AL_INVALID_NAME
);
709 ProcessContext(pContext
);
713 ALAPI ALvoid ALAPIENTRY
alGetBufferf(ALuint buffer
, ALenum eParam
, ALfloat
*pflValue
)
715 ALCcontext
*pContext
;
717 pContext
= GetContextSuspended();
718 if(!pContext
) return;
722 if (alIsBuffer(buffer
) && (buffer
!= 0))
727 alSetError(AL_INVALID_ENUM
);
733 alSetError(AL_INVALID_NAME
);
738 alSetError(AL_INVALID_VALUE
);
741 ProcessContext(pContext
);
745 ALAPI
void ALAPIENTRY
alGetBuffer3f(ALuint buffer
, ALenum eParam
, ALfloat
* pflValue1
, ALfloat
* pflValue2
, ALfloat
* pflValue3
)
747 ALCcontext
*pContext
;
749 pContext
= GetContextSuspended();
750 if(!pContext
) return;
752 if ((pflValue1
) && (pflValue2
) && (pflValue3
))
754 if (alIsBuffer(buffer
) && (buffer
!= 0))
759 alSetError(AL_INVALID_ENUM
);
765 alSetError(AL_INVALID_NAME
);
770 alSetError(AL_INVALID_VALUE
);
773 ProcessContext(pContext
);
777 ALAPI
void ALAPIENTRY
alGetBufferfv(ALuint buffer
, ALenum eParam
, ALfloat
* pflValues
)
779 ALCcontext
*pContext
;
781 pContext
= GetContextSuspended();
782 if(!pContext
) return;
786 if (alIsBuffer(buffer
) && (buffer
!= 0))
791 alSetError(AL_INVALID_ENUM
);
797 alSetError(AL_INVALID_NAME
);
802 alSetError(AL_INVALID_VALUE
);
805 ProcessContext(pContext
);
809 ALAPI ALvoid ALAPIENTRY
alGetBufferi(ALuint buffer
, ALenum eParam
, ALint
*plValue
)
811 ALCcontext
*pContext
;
814 pContext
= GetContextSuspended();
815 if(!pContext
) return;
819 if (alIsBuffer(buffer
) && (buffer
!= 0))
821 pBuffer
= ((ALbuffer
*)ALTHUNK_LOOKUPENTRY(buffer
));
826 *plValue
= pBuffer
->frequency
;
830 *plValue
= aluBytesFromFormat(pBuffer
->format
) * 8;
834 *plValue
= aluChannelsFromFormat(pBuffer
->format
);
838 *plValue
= pBuffer
->size
;
842 alSetError(AL_INVALID_ENUM
);
848 alSetError(AL_INVALID_NAME
);
853 alSetError(AL_INVALID_VALUE
);
856 ProcessContext(pContext
);
860 ALAPI
void ALAPIENTRY
alGetBuffer3i(ALuint buffer
, ALenum eParam
, ALint
* plValue1
, ALint
* plValue2
, ALint
* plValue3
)
862 ALCcontext
*pContext
;
864 pContext
= GetContextSuspended();
865 if(!pContext
) return;
867 if ((plValue1
) && (plValue2
) && (plValue3
))
869 if (alIsBuffer(buffer
) && (buffer
!= 0))
874 alSetError(AL_INVALID_ENUM
);
880 alSetError(AL_INVALID_NAME
);
885 alSetError(AL_INVALID_VALUE
);
888 ProcessContext(pContext
);
892 ALAPI
void ALAPIENTRY
alGetBufferiv(ALuint buffer
, ALenum eParam
, ALint
* plValues
)
894 ALCcontext
*pContext
;
896 pContext
= GetContextSuspended();
897 if(!pContext
) return;
901 if (alIsBuffer(buffer
) && (buffer
!= 0))
909 alGetBufferi(buffer
, eParam
, plValues
);
913 alSetError(AL_INVALID_ENUM
);
919 alSetError(AL_INVALID_NAME
);
924 alSetError(AL_INVALID_VALUE
);
927 ProcessContext(pContext
);
933 * Loads the specified data into the buffer, using the specified formats.
934 * Currently, the new format must be 16-bit, and must have the same channel
935 * configuration as the original format. This does NOT handle compressed
936 * formats (eg. IMA4).
938 static void LoadData(ALbuffer
*ALBuf
, const ALubyte
*data
, ALsizei size
, ALuint freq
, ALenum OrigFormat
, ALenum NewFormat
)
940 ALuint NewChannels
= aluChannelsFromFormat(NewFormat
);
941 ALuint OrigBytes
= aluBytesFromFormat(OrigFormat
);
942 ALuint OrigChannels
= aluChannelsFromFormat(OrigFormat
);
946 assert(aluBytesFromFormat(NewFormat
) == 2);
947 assert(NewChannels
== OrigChannels
);
949 if ((size
%(OrigBytes
*OrigChannels
)) != 0)
951 alSetError(AL_INVALID_VALUE
);
955 // Samples are converted to 16 bit here
957 temp
= realloc(ALBuf
->data
, (padding
*NewChannels
+ size
) * sizeof(ALshort
));
961 ConvertData(ALBuf
->data
, data
, OrigBytes
, size
);
963 memset(&(ALBuf
->data
[size
]), 0, padding
*NewChannels
*sizeof(ALshort
));
965 ALBuf
->format
= NewFormat
;
966 ALBuf
->eOriginalFormat
= OrigFormat
;
967 ALBuf
->size
= size
*sizeof(ALshort
);
968 ALBuf
->frequency
= freq
;
969 ALBuf
->padding
= padding
;
972 alSetError(AL_OUT_OF_MEMORY
);
975 static void ConvertData(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
)
981 for(i
= 0;i
< len
;i
++)
982 dst
[i
] = ((ALshort
)((ALubyte
*)src
)[i
] - 128) << 8;
986 memcpy(dst
, src
, len
*sizeof(ALshort
));
990 for(i
= 0;i
< len
;i
++)
993 smp
= (((ALfloat
*)src
)[i
] * 32767.5f
- 0.5f
);
994 smp
= min(smp
, 32767);
995 smp
= max(smp
, -32768);
996 dst
[i
] = (ALshort
)smp
;
1005 static void ConvertDataRear(ALshort
*dst
, const ALvoid
*src
, ALint origBytes
, ALsizei len
)
1011 for(i
= 0;i
< len
;i
+=4)
1015 dst
[i
+2] = ((ALshort
)((ALubyte
*)src
)[i
/2+0] - 128) << 8;
1016 dst
[i
+3] = ((ALshort
)((ALubyte
*)src
)[i
/2+1] - 128) << 8;
1021 for(i
= 0;i
< len
;i
+=4)
1025 dst
[i
+2] = ((ALshort
*)src
)[i
/2+0];
1026 dst
[i
+3] = ((ALshort
*)src
)[i
/2+1];
1031 for(i
= 0;i
< len
;i
+=4)
1036 smp
= (((ALfloat
*)src
)[i
/2+0] * 32767.5f
- 0.5);
1037 smp
= min(smp
, 32767);
1038 smp
= max(smp
, -32768);
1039 dst
[i
+2] = (ALshort
)smp
;
1040 smp
= (((ALfloat
*)src
)[i
/2+1] * 32767.5f
- 0.5);
1041 smp
= min(smp
, 32767);
1042 smp
= max(smp
, -32768);
1043 dst
[i
+3] = (ALshort
)smp
;
1052 static void ConvertDataIMA4(ALshort
*dst
, const ALvoid
*src
, ALint origChans
, ALsizei len
)
1054 const ALuint
*IMAData
;
1055 ALint Sample
[2],Index
[2];
1059 assert(origChans
<= 2);
1062 for(i
= 0;i
< len
/origChans
;i
++)
1064 for(c
= 0;c
< origChans
;c
++)
1066 Sample
[c
] = ((ALshort
*)IMAData
)[0];
1067 Index
[c
] = ((ALshort
*)IMAData
)[1];
1069 Index
[c
] = ((Index
[c
]<0) ? 0 : Index
[c
]);
1070 Index
[c
] = ((Index
[c
]>88) ? 88 : Index
[c
]);
1072 dst
[i
*65*origChans
+ c
] = (ALshort
)Sample
[c
];
1077 for(j
= 1;j
< 65;j
+= 8)
1079 for(c
= 0;c
< origChans
;c
++)
1080 IMACode
[c
] = *(IMAData
++);
1082 for(k
= 0;k
< 8;k
++)
1084 for(c
= 0;c
< origChans
;c
++)
1086 Sample
[c
] += ((g_IMAStep_size
[Index
[c
]]*g_IMACodeword_4
[IMACode
[c
]&15])/8);
1087 Index
[c
] += g_IMAIndex_adjust_4
[IMACode
[c
]&15];
1089 if(Sample
[c
] < -32768) Sample
[c
] = -32768;
1090 else if(Sample
[c
] > 32767) Sample
[c
] = 32767;
1092 if(Index
[c
]<0) Index
[c
] = 0;
1093 else if(Index
[c
]>88) Index
[c
] = 88;
1095 dst
[(i
*65+j
+k
)*origChans
+ c
] = (ALshort
)Sample
[c
];
1104 * ReleaseALBuffers()
1106 * INTERNAL FN : Called by DLLMain on exit to destroy any buffers that still exist
1108 ALvoid
ReleaseALBuffers(ALCdevice
*device
)
1111 ALbuffer
*ALBufferTemp
;
1113 ALBuffer
= device
->Buffers
;
1116 // Release sample data
1117 free(ALBuffer
->data
);
1119 // Release Buffer structure
1120 ALBufferTemp
= ALBuffer
;
1121 ALBuffer
= ALBuffer
->next
;
1122 memset(ALBufferTemp
, 0, sizeof(ALbuffer
));
1125 device
->Buffers
= NULL
;
1126 device
->BufferCount
= 0;