zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
alBuffer.c
Go to the documentation of this file.
1 
21 #include "config.h"
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <assert.h>
26 #include <limits.h>
27 
28 #include "alMain.h"
29 #include "alu.h"
30 #include "alError.h"
31 #include "alBuffer.h"
32 #include "alThunk.h"
33 
34 
35 static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels chans, enum UserFmtType type, const ALvoid *data, ALboolean storesrc);
36 static void ConvertData(ALvoid *dst, enum UserFmtType dstType, const ALvoid *src, enum UserFmtType srcType, ALsizei numchans, ALsizei len);
38 static ALboolean IsValidChannels(ALenum channels);
40 static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum FmtType *type);
41 
42 
43 /*
44  * Global Variables
45  */
46 
47 /* IMA ADPCM Stepsize table */
48 static const int IMAStep_size[89] = {
49  7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19,
50  21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55,
51  60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157,
52  173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449,
53  494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282,
54  1411, 1552, 1707, 1878, 2066, 2272, 2499, 2749, 3024, 3327, 3660,
55  4026, 4428, 4871, 5358, 5894, 6484, 7132, 7845, 8630, 9493,10442,
56  11487,12635,13899,15289,16818,18500,20350,22358,24633,27086,29794,
57  32767
58 };
59 
60 /* IMA4 ADPCM Codeword decode table */
61 static const int IMA4Codeword[16] = {
62  1, 3, 5, 7, 9, 11, 13, 15,
63  -1,-3,-5,-7,-9,-11,-13,-15,
64 };
65 
66 /* IMA4 ADPCM Step index adjust decode table */
67 static const int IMA4Index_adjust[16] = {
68  -1,-1,-1,-1, 2, 4, 6, 8,
69  -1,-1,-1,-1, 2, 4, 6, 8
70 };
71 
72 /* A quick'n'dirty lookup table to decode a muLaw-encoded byte sample into a
73  * signed 16-bit sample */
74 static const ALshort muLawDecompressionTable[256] = {
75  -32124,-31100,-30076,-29052,-28028,-27004,-25980,-24956,
76  -23932,-22908,-21884,-20860,-19836,-18812,-17788,-16764,
77  -15996,-15484,-14972,-14460,-13948,-13436,-12924,-12412,
78  -11900,-11388,-10876,-10364, -9852, -9340, -8828, -8316,
79  -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
80  -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
81  -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
82  -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
83  -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
84  -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
85  -876, -844, -812, -780, -748, -716, -684, -652,
86  -620, -588, -556, -524, -492, -460, -428, -396,
87  -372, -356, -340, -324, -308, -292, -276, -260,
88  -244, -228, -212, -196, -180, -164, -148, -132,
89  -120, -112, -104, -96, -88, -80, -72, -64,
90  -56, -48, -40, -32, -24, -16, -8, 0,
91  32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
92  23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
93  15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
94  11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
95  7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
96  5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
97  3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
98  2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
99  1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
100  1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
101  876, 844, 812, 780, 748, 716, 684, 652,
102  620, 588, 556, 524, 492, 460, 428, 396,
103  372, 356, 340, 324, 308, 292, 276, 260,
104  244, 228, 212, 196, 180, 164, 148, 132,
105  120, 112, 104, 96, 88, 80, 72, 64,
106  56, 48, 40, 32, 24, 16, 8, 0
107 };
108 
109 /* Values used when encoding a muLaw sample */
110 static const int muLawBias = 0x84;
111 static const int muLawClip = 32635;
112 static const char muLawCompressTable[256] = {
113  0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
114  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
115  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
116  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
117  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
118  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
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  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
122  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
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 };
130 
131 
132 /* A quick'n'dirty lookup table to decode an aLaw-encoded byte sample into a
133  * signed 16-bit sample */
134 static const ALshort aLawDecompressionTable[256] = {
135  -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
136  -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
137  -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
138  -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
139  -22016,-20992,-24064,-23040,-17920,-16896,-19968,-18944,
140  -30208,-29184,-32256,-31232,-26112,-25088,-28160,-27136,
141  -11008,-10496,-12032,-11520, -8960, -8448, -9984, -9472,
142  -15104,-14592,-16128,-15616,-13056,-12544,-14080,-13568,
143  -344, -328, -376, -360, -280, -264, -312, -296,
144  -472, -456, -504, -488, -408, -392, -440, -424,
145  -88, -72, -120, -104, -24, -8, -56, -40,
146  -216, -200, -248, -232, -152, -136, -184, -168,
147  -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
148  -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
149  -688, -656, -752, -720, -560, -528, -624, -592,
150  -944, -912, -1008, -976, -816, -784, -880, -848,
151  5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
152  7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
153  2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
154  3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
155  22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
156  30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
157  11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
158  15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
159  344, 328, 376, 360, 280, 264, 312, 296,
160  472, 456, 504, 488, 408, 392, 440, 424,
161  88, 72, 120, 104, 24, 8, 56, 40,
162  216, 200, 248, 232, 152, 136, 184, 168,
163  1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
164  1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
165  688, 656, 752, 720, 560, 528, 624, 592,
166  944, 912, 1008, 976, 816, 784, 880, 848
167 };
168 
169 /* Values used when encoding an aLaw sample */
170 static const int aLawClip = 32635;
171 static const char aLawCompressTable[128] = {
172  1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
173  5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
174  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
175  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
176  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
177  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
178  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
179  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
180 };
181 
182 
184 {
185  ALCcontext *Context;
186  ALsizei cur = 0;
187 
188  Context = GetContextRef();
189  if(!Context) return;
190 
191  al_try
192  {
193  ALCdevice *device = Context->Device;
194  ALenum err;
195 
196  CHECK_VALUE(Context, n >= 0);
197  for(cur = 0;cur < n;cur++)
198  {
199  ALbuffer *buffer = calloc(1, sizeof(ALbuffer));
200  if(!buffer)
201  al_throwerr(Context, AL_OUT_OF_MEMORY);
202  RWLockInit(&buffer->lock);
203 
204  err = NewThunkEntry(&buffer->id);
205  if(err == AL_NO_ERROR)
206  err = InsertUIntMapEntry(&device->BufferMap, buffer->id, buffer);
207  if(err != AL_NO_ERROR)
208  {
209  FreeThunkEntry(buffer->id);
210  memset(buffer, 0, sizeof(ALbuffer));
211  free(buffer);
212 
213  al_throwerr(Context, err);
214  }
215 
216  buffers[cur] = buffer->id;
217  }
218  }
219  al_catchany()
220  {
221  if(cur > 0)
222  alDeleteBuffers(cur, buffers);
223  }
224  al_endtry;
225 
226  ALCcontext_DecRef(Context);
227 }
228 
230 {
231  ALCcontext *Context;
232  ALbuffer *ALBuf;
233  ALsizei i;
234 
235  Context = GetContextRef();
236  if(!Context) return;
237 
238  al_try
239  {
240  ALCdevice *device = Context->Device;
241 
242  CHECK_VALUE(Context, n >= 0);
243  for(i = 0;i < n;i++)
244  {
245  if(!buffers[i])
246  continue;
247 
248  /* Check for valid Buffer ID */
249  if((ALBuf=LookupBuffer(device, buffers[i])) == NULL)
250  al_throwerr(Context, AL_INVALID_NAME);
251  if(ALBuf->ref != 0)
253  }
254 
255  for(i = 0;i < n;i++)
256  {
257  if((ALBuf=RemoveBuffer(device, buffers[i])) == NULL)
258  continue;
259  FreeThunkEntry(ALBuf->id);
260 
261  free(ALBuf->data);
262 
263  memset(ALBuf, 0, sizeof(*ALBuf));
264  free(ALBuf);
265  }
266  }
267  al_endtry;
268 
269  ALCcontext_DecRef(Context);
270 }
271 
273 {
274  ALCcontext *Context;
276 
277  Context = GetContextRef();
278  if(!Context) return AL_FALSE;
279 
280  result = ((!buffer || LookupBuffer(Context->Device, buffer)) ?
281  AL_TRUE : AL_FALSE);
282 
283  ALCcontext_DecRef(Context);
284 
285  return result;
286 }
287 
288 
290 {
291  enum UserFmtChannels SrcChannels;
292  enum UserFmtType SrcType;
293  ALCcontext *Context;
294  ALuint FrameSize;
295  ALenum NewFormat;
296  ALbuffer *ALBuf;
297  ALenum err;
298 
299  Context = GetContextRef();
300  if(!Context) return;
301 
302  al_try
303  {
304  ALCdevice *device = Context->Device;
305  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
306  al_throwerr(Context, AL_INVALID_NAME);
307  CHECK_VALUE(Context, size >= 0 && freq >= 0);
308  if(DecomposeUserFormat(format, &SrcChannels, &SrcType) == AL_FALSE)
309  al_throwerr(Context, AL_INVALID_ENUM);
310  switch(SrcType)
311  {
312  case UserFmtByte:
313  case UserFmtUByte:
314  case UserFmtShort:
315  case UserFmtUShort:
316  case UserFmtFloat:
317  FrameSize = FrameSizeFromUserFmt(SrcChannels, SrcType);
318  CHECK_VALUE(Context, (size%FrameSize) == 0);
319 
320  err = LoadData(ALBuf, freq, format, size/FrameSize,
321  SrcChannels, SrcType, data, AL_TRUE);
322  if(err != AL_NO_ERROR)
323  al_throwerr(Context, err);
324  break;
325 
326  case UserFmtInt:
327  case UserFmtUInt:
328  case UserFmtByte3:
329  case UserFmtUByte3:
330  case UserFmtDouble:
331  FrameSize = FrameSizeFromUserFmt(SrcChannels, SrcType);
332  CHECK_VALUE(Context, (size%FrameSize) == 0);
333 
334  NewFormat = AL_FORMAT_MONO_FLOAT32;
335  switch(SrcChannels)
336  {
337  case UserFmtMono: NewFormat = AL_FORMAT_MONO_FLOAT32; break;
338  case UserFmtStereo: NewFormat = AL_FORMAT_STEREO_FLOAT32; break;
339  case UserFmtRear: NewFormat = AL_FORMAT_REAR32; break;
340  case UserFmtQuad: NewFormat = AL_FORMAT_QUAD32; break;
341  case UserFmtX51: NewFormat = AL_FORMAT_51CHN32; break;
342  case UserFmtX61: NewFormat = AL_FORMAT_61CHN32; break;
343  case UserFmtX71: NewFormat = AL_FORMAT_71CHN32; break;
344  }
345  err = LoadData(ALBuf, freq, NewFormat, size/FrameSize,
346  SrcChannels, SrcType, data, AL_TRUE);
347  if(err != AL_NO_ERROR)
348  al_throwerr(Context, err);
349  break;
350 
351  case UserFmtMulaw:
352  case UserFmtAlaw:
353  FrameSize = FrameSizeFromUserFmt(SrcChannels, SrcType);
354  CHECK_VALUE(Context, (size%FrameSize) == 0);
355 
356  NewFormat = AL_FORMAT_MONO16;
357  switch(SrcChannels)
358  {
359  case UserFmtMono: NewFormat = AL_FORMAT_MONO16; break;
360  case UserFmtStereo: NewFormat = AL_FORMAT_STEREO16; break;
361  case UserFmtRear: NewFormat = AL_FORMAT_REAR16; break;
362  case UserFmtQuad: NewFormat = AL_FORMAT_QUAD16; break;
363  case UserFmtX51: NewFormat = AL_FORMAT_51CHN16; break;
364  case UserFmtX61: NewFormat = AL_FORMAT_61CHN16; break;
365  case UserFmtX71: NewFormat = AL_FORMAT_71CHN16; break;
366  }
367  err = LoadData(ALBuf, freq, NewFormat, size/FrameSize,
368  SrcChannels, SrcType, data, AL_TRUE);
369  if(err != AL_NO_ERROR)
370  al_throwerr(Context, err);
371  break;
372 
373  case UserFmtIMA4:
374  /* Here is where things vary:
375  * nVidia and Apple use 64+1 sample frames per block -> block_size=36 bytes per channel
376  * Most PC sound software uses 2040+1 sample frames per block -> block_size=1024 bytes per channel
377  */
378  FrameSize = ChannelsFromUserFmt(SrcChannels) * 36;
379  CHECK_VALUE(Context, (size%FrameSize) == 0);
380 
381  NewFormat = AL_FORMAT_MONO16;
382  switch(SrcChannels)
383  {
384  case UserFmtMono: NewFormat = AL_FORMAT_MONO16; break;
385  case UserFmtStereo: NewFormat = AL_FORMAT_STEREO16; break;
386  case UserFmtRear: NewFormat = AL_FORMAT_REAR16; break;
387  case UserFmtQuad: NewFormat = AL_FORMAT_QUAD16; break;
388  case UserFmtX51: NewFormat = AL_FORMAT_51CHN16; break;
389  case UserFmtX61: NewFormat = AL_FORMAT_61CHN16; break;
390  case UserFmtX71: NewFormat = AL_FORMAT_71CHN16; break;
391  }
392  err = LoadData(ALBuf, freq, NewFormat, size/FrameSize*65,
393  SrcChannels, SrcType, data, AL_TRUE);
394  if(err != AL_NO_ERROR)
395  al_throwerr(Context, err);
396  break;
397  }
398  }
399  al_endtry;
400 
401  ALCcontext_DecRef(Context);
402 }
403 
405 {
406  enum UserFmtChannels SrcChannels;
407  enum UserFmtType SrcType;
408  ALCcontext *Context;
409  ALbuffer *ALBuf;
410 
411  Context = GetContextRef();
412  if(!Context) return;
413 
414  al_try
415  {
416  ALCdevice *device = Context->Device;
417  ALuint original_align;
418  ALuint Channels;
419  ALuint Bytes;
420 
421  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
422  al_throwerr(Context, AL_INVALID_NAME);
423  CHECK_VALUE(Context, length >= 0 && offset >= 0);
424  if(DecomposeUserFormat(format, &SrcChannels, &SrcType) == AL_FALSE)
425  al_throwerr(Context, AL_INVALID_ENUM);
426 
427  WriteLock(&ALBuf->lock);
428  original_align = ((ALBuf->OriginalType == UserFmtIMA4) ?
431  ALBuf->OriginalType));
432 
433  if(SrcChannels != ALBuf->OriginalChannels || SrcType != ALBuf->OriginalType)
434  {
435  WriteUnlock(&ALBuf->lock);
436  al_throwerr(Context, AL_INVALID_ENUM);
437  }
438  if(offset > ALBuf->OriginalSize || length > ALBuf->OriginalSize-offset ||
439  (offset%original_align) != 0 || (length%original_align) != 0)
440  {
441  WriteUnlock(&ALBuf->lock);
442  al_throwerr(Context, AL_INVALID_VALUE);
443  }
444 
445  Channels = ChannelsFromFmt(ALBuf->FmtChannels);
446  Bytes = BytesFromFmt(ALBuf->FmtType);
447  /* offset -> byte offset, length -> sample count */
448  if(SrcType == UserFmtIMA4)
449  {
450  offset = offset/36*65 * Bytes;
451  length = length/original_align * 65;
452  }
453  else
454  {
455  ALuint OldBytes = BytesFromUserFmt(SrcType);
456  offset = offset/OldBytes * Bytes;
457  length = length/OldBytes/Channels;
458  }
459  ConvertData(&((ALubyte*)ALBuf->data)[offset], ALBuf->FmtType,
460  data, SrcType, Channels, length);
461  WriteUnlock(&ALBuf->lock);
462  }
463  al_endtry;
464 
465  ALCcontext_DecRef(Context);
466 }
467 
468 
471  ALenum channels, ALenum type, const ALvoid *data)
472 {
473  ALCcontext *Context;
474  ALbuffer *ALBuf;
475  ALenum err;
476 
477  Context = GetContextRef();
478  if(!Context) return;
479 
480  al_try
481  {
482  ALCdevice *device = Context->Device;
483  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
484  al_throwerr(Context, AL_INVALID_NAME);
485  CHECK_VALUE(Context, samples >= 0 && samplerate != 0);
486  if(IsValidType(type) == AL_FALSE || IsValidChannels(channels) == AL_FALSE)
487  al_throwerr(Context, AL_INVALID_ENUM);
488 
489  err = LoadData(ALBuf, samplerate, internalformat, samples,
490  channels, type, data, AL_FALSE);
491  if(err != AL_NO_ERROR)
492  al_throwerr(Context, err);
493  }
494  al_endtry;
495 
496  ALCcontext_DecRef(Context);
497 }
498 
501  ALenum channels, ALenum type, const ALvoid *data)
502 {
503  ALCcontext *Context;
504  ALbuffer *ALBuf;
505 
506  Context = GetContextRef();
507  if(!Context) return;
508 
509  al_try
510  {
511  ALCdevice *device = Context->Device;
512  ALuint FrameSize;
513 
514  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
515  al_throwerr(Context, AL_INVALID_NAME);
516  CHECK_VALUE(Context, samples >= 0 && offset >= 0);
517  if(IsValidType(type) == AL_FALSE)
518  al_throwerr(Context, AL_INVALID_ENUM);
519 
520  WriteLock(&ALBuf->lock);
521  FrameSize = FrameSizeFromFmt(ALBuf->FmtChannels, ALBuf->FmtType);
522  if(channels != (ALenum)ALBuf->FmtChannels)
523  {
524  WriteUnlock(&ALBuf->lock);
525  al_throwerr(Context, AL_INVALID_ENUM);
526  }
527  else if(offset > ALBuf->SampleLen || samples > ALBuf->SampleLen-offset)
528  {
529  WriteUnlock(&ALBuf->lock);
530  al_throwerr(Context,AL_INVALID_VALUE);
531  }
532 
533  /* offset -> byte offset */
534  offset *= FrameSize;
535  ConvertData(&((ALubyte*)ALBuf->data)[offset], ALBuf->FmtType,
536  data, type, ChannelsFromFmt(ALBuf->FmtChannels), samples);
537  WriteUnlock(&ALBuf->lock);
538  }
539  al_endtry;
540 
541  ALCcontext_DecRef(Context);
542 }
543 
546  ALenum channels, ALenum type, ALvoid *data)
547 {
548  ALCcontext *Context;
549  ALbuffer *ALBuf;
550 
551  Context = GetContextRef();
552  if(!Context) return;
553 
554  al_try
555  {
556  ALCdevice *device = Context->Device;
557  ALuint FrameSize;
558 
559  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
560  al_throwerr(Context, AL_INVALID_NAME);
561  CHECK_VALUE(Context, samples >= 0 && offset >= 0);
562  if(IsValidType(type) == AL_FALSE)
563  al_throwerr(Context, AL_INVALID_ENUM);
564 
565  ReadLock(&ALBuf->lock);
566  FrameSize = FrameSizeFromFmt(ALBuf->FmtChannels, ALBuf->FmtType);
567  if(channels != (ALenum)ALBuf->FmtChannels)
568  {
569  ReadUnlock(&ALBuf->lock);
570  al_throwerr(Context, AL_INVALID_ENUM);
571  }
572  if(offset > ALBuf->SampleLen || samples > ALBuf->SampleLen-offset)
573  {
574  ReadUnlock(&ALBuf->lock);
575  al_throwerr(Context,AL_INVALID_VALUE);
576  }
577  if(type == UserFmtIMA4 && (samples%65) != 0)
578  {
579  ReadUnlock(&ALBuf->lock);
580  al_throwerr(Context, AL_INVALID_VALUE);
581  }
582 
583  /* offset -> byte offset */
584  offset *= FrameSize;
585  ConvertData(data, type, &((ALubyte*)ALBuf->data)[offset], ALBuf->FmtType,
586  ChannelsFromFmt(ALBuf->FmtChannels), samples);
587  ReadUnlock(&ALBuf->lock);
588  }
589  al_endtry;
590 
591  ALCcontext_DecRef(Context);
592 }
593 
595 {
596  enum FmtChannels DstChannels;
597  enum FmtType DstType;
598  ALCcontext *Context;
599  ALboolean ret;
600 
601  Context = GetContextRef();
602  if(!Context) return AL_FALSE;
603 
604  ret = DecomposeFormat(format, &DstChannels, &DstType);
605 
606  ALCcontext_DecRef(Context);
607 
608  return ret;
609 }
610 
611 
613 {
614  ALCcontext *Context;
615 
616  (void)value;
617 
618  Context = GetContextRef();
619  if(!Context) return;
620 
621  al_try
622  {
623  ALCdevice *device = Context->Device;
624  if(LookupBuffer(device, buffer) == NULL)
625  al_throwerr(Context, AL_INVALID_NAME);
626 
627  switch(param)
628  {
629  default:
630  al_throwerr(Context, AL_INVALID_ENUM);
631  }
632  }
633  al_endtry;
634 
635  ALCcontext_DecRef(Context);
636 }
637 
638 
640 {
641  ALCcontext *Context;
642 
643  (void)value1;
644  (void)value2;
645  (void)value3;
646 
647  Context = GetContextRef();
648  if(!Context) return;
649 
650  al_try
651  {
652  ALCdevice *device = Context->Device;
653  if(LookupBuffer(device, buffer) == NULL)
654  al_throwerr(Context, AL_INVALID_NAME);
655 
656  switch(param)
657  {
658  default:
659  al_throwerr(Context, AL_INVALID_ENUM);
660  }
661  }
662  al_endtry;
663 
664  ALCcontext_DecRef(Context);
665 }
666 
667 
669 {
670  ALCcontext *Context;
671 
672  Context = GetContextRef();
673  if(!Context) return;
674 
675  al_try
676  {
677  ALCdevice *device = Context->Device;
678  if(LookupBuffer(device, buffer) == NULL)
679  al_throwerr(Context, AL_INVALID_NAME);
680 
681  CHECK_VALUE(Context, values);
682  switch(param)
683  {
684  default:
685  al_throwerr(Context, AL_INVALID_ENUM);
686  }
687  }
688  al_endtry;
689 
690  ALCcontext_DecRef(Context);
691 }
692 
693 
695 {
696  ALCcontext *Context;
697 
698  (void)value;
699 
700  Context = GetContextRef();
701  if(!Context) return;
702 
703  al_try
704  {
705  ALCdevice *device = Context->Device;
706  if(LookupBuffer(device, buffer) == NULL)
707  al_throwerr(Context, AL_INVALID_NAME);
708 
709  switch(param)
710  {
711  default:
712  al_throwerr(Context, AL_INVALID_ENUM);
713  }
714  }
715  al_endtry;
716 
717  ALCcontext_DecRef(Context);
718 }
719 
720 
722 {
723  ALCcontext *Context;
724 
725  (void)value1;
726  (void)value2;
727  (void)value3;
728 
729  Context = GetContextRef();
730  if(!Context) return;
731 
732  al_try
733  {
734  ALCdevice *device = Context->Device;
735  if(LookupBuffer(device, buffer) == NULL)
736  al_throwerr(Context, AL_INVALID_NAME);
737 
738  switch(param)
739  {
740  default:
741  al_throwerr(Context, AL_INVALID_ENUM);
742  }
743  }
744  al_endtry;
745 
746  ALCcontext_DecRef(Context);
747 }
748 
749 
751 {
752  ALCcontext *Context;
753  ALbuffer *ALBuf;
754 
755  Context = GetContextRef();
756  if(!Context) return;
757 
758  al_try
759  {
760  ALCdevice *device = Context->Device;
761  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
762  al_throwerr(Context, AL_INVALID_NAME);
763 
764  CHECK_VALUE(Context, values);
765  switch(param)
766  {
767  case AL_LOOP_POINTS_SOFT:
768  WriteLock(&ALBuf->lock);
769  if(ALBuf->ref != 0)
770  {
771  WriteUnlock(&ALBuf->lock);
773  }
774  if(values[0] >= values[1] || values[0] < 0 ||
775  values[1] > ALBuf->SampleLen)
776  {
777  WriteUnlock(&ALBuf->lock);
778  al_throwerr(Context, AL_INVALID_VALUE);
779  }
780 
781  ALBuf->LoopStart = values[0];
782  ALBuf->LoopEnd = values[1];
783  WriteUnlock(&ALBuf->lock);
784  break;
785 
786  default:
787  al_throwerr(Context, AL_INVALID_ENUM);
788  }
789  }
790  al_endtry;
791 
792  ALCcontext_DecRef(Context);
793 }
794 
795 
797 {
798  ALCcontext *Context;
799  ALbuffer *Buffer;
800 
801  Context = GetContextRef();
802  if(!Context) return;
803 
804  al_try
805  {
806  ALCdevice *device = Context->Device;
807  if((Buffer=LookupBuffer(device, buffer)) == NULL)
808  al_throwerr(Context, AL_INVALID_NAME);
809 
810  CHECK_VALUE(Context, value);
811  switch(param)
812  {
813  case AL_SEC_LENGTH_SOFT:
814  ReadLock(&Buffer->lock);
815  if(Buffer->SampleLen != 0)
816  *value = Buffer->SampleLen / (ALfloat)Buffer->Frequency;
817  else
818  *value = 0.0f;
819  ReadUnlock(&Buffer->lock);
820  break;
821 
822  default:
823  al_throwerr(Context, AL_INVALID_ENUM);
824  }
825  }
826  al_endtry;
827 
828  ALCcontext_DecRef(Context);
829 }
830 
831 
833 {
834  ALCcontext *Context;
835 
836  Context = GetContextRef();
837  if(!Context) return;
838 
839  al_try
840  {
841  ALCdevice *device = Context->Device;
842  if(LookupBuffer(device, buffer) == NULL)
843  al_throwerr(Context, AL_INVALID_NAME);
844 
845  CHECK_VALUE(Context, value1 && value2 && value3);
846  switch(param)
847  {
848  default:
849  al_throwerr(Context, AL_INVALID_ENUM);
850  }
851  }
852  al_endtry;
853 
854  ALCcontext_DecRef(Context);
855 }
856 
857 
859 {
860  ALCcontext *Context;
861 
862  switch(param)
863  {
864  case AL_SEC_LENGTH_SOFT:
865  alGetBufferf(buffer, param, values);
866  return;
867  }
868 
869  Context = GetContextRef();
870  if(!Context) return;
871 
872  al_try
873  {
874  ALCdevice *device = Context->Device;
875  if(LookupBuffer(device, buffer) == NULL)
876  al_throwerr(Context, AL_INVALID_NAME);
877 
878  CHECK_VALUE(Context, values);
879  switch(param)
880  {
881  default:
882  al_throwerr(Context, AL_INVALID_ENUM);
883  }
884  }
885  al_endtry;
886 
887  ALCcontext_DecRef(Context);
888 }
889 
890 
892 {
893  ALCcontext *Context;
894  ALbuffer *Buffer;
895 
896  Context = GetContextRef();
897  if(!Context) return;
898 
899  al_try
900  {
901  ALCdevice *device = Context->Device;
902  if((Buffer=LookupBuffer(device, buffer)) == NULL)
903  al_throwerr(Context, AL_INVALID_NAME);
904 
905  CHECK_VALUE(Context, value);
906  switch(param)
907  {
908  case AL_FREQUENCY:
909  *value = Buffer->Frequency;
910  break;
911 
912  case AL_BITS:
913  *value = BytesFromFmt(Buffer->FmtType) * 8;
914  break;
915 
916  case AL_CHANNELS:
917  *value = ChannelsFromFmt(Buffer->FmtChannels);
918  break;
919 
920  case AL_SIZE:
921  ReadLock(&Buffer->lock);
922  *value = Buffer->SampleLen * FrameSizeFromFmt(Buffer->FmtChannels,
923  Buffer->FmtType);
924  ReadUnlock(&Buffer->lock);
925  break;
926 
928  *value = Buffer->Format;
929  break;
930 
931  case AL_BYTE_LENGTH_SOFT:
932  *value = Buffer->OriginalSize;
933  break;
934 
936  *value = Buffer->SampleLen;
937  break;
938 
939  default:
940  al_throwerr(Context, AL_INVALID_ENUM);
941  }
942  }
943  al_endtry;
944 
945  ALCcontext_DecRef(Context);
946 }
947 
948 
950 {
951  ALCcontext *Context;
952 
953  Context = GetContextRef();
954  if(!Context) return;
955 
956  al_try
957  {
958  ALCdevice *device = Context->Device;
959  if(LookupBuffer(device, buffer) == NULL)
960  al_throwerr(Context, AL_INVALID_NAME);
961 
962  CHECK_VALUE(Context, value1 && value2 && value3);
963  switch(param)
964  {
965  default:
966  al_throwerr(Context, AL_INVALID_ENUM);
967  }
968  }
969  al_endtry;
970 
971  ALCcontext_DecRef(Context);
972 }
973 
974 
976 {
977  ALCcontext *Context;
978  ALbuffer *ALBuf;
979 
980  switch(param)
981  {
982  case AL_FREQUENCY:
983  case AL_BITS:
984  case AL_CHANNELS:
985  case AL_SIZE:
987  case AL_BYTE_LENGTH_SOFT:
989  alGetBufferi(buffer, param, values);
990  return;
991  }
992 
993  Context = GetContextRef();
994  if(!Context) return;
995 
996  al_try
997  {
998  ALCdevice *device = Context->Device;
999  if((ALBuf=LookupBuffer(device, buffer)) == NULL)
1000  al_throwerr(Context, AL_INVALID_NAME);
1001 
1002  CHECK_VALUE(Context, values);
1003  switch(param)
1004  {
1005  case AL_LOOP_POINTS_SOFT:
1006  ReadLock(&ALBuf->lock);
1007  values[0] = ALBuf->LoopStart;
1008  values[1] = ALBuf->LoopEnd;
1009  ReadUnlock(&ALBuf->lock);
1010  break;
1011 
1012  default:
1013  al_throwerr(Context, AL_INVALID_ENUM);
1014  }
1015  }
1016  al_endtry;
1017 
1018  ALCcontext_DecRef(Context);
1019 }
1020 
1021 
1023 typedef ALubyte ALalaw;
1024 typedef ALubyte ALima4;
1025 typedef struct {
1026  ALbyte b[3];
1027 } ALbyte3;
1028 extern ALbyte ALbyte3_size_is_not_3[(sizeof(ALbyte3)==sizeof(ALbyte[3]))?1:-1];
1029 typedef struct {
1030  ALubyte b[3];
1031 } ALubyte3;
1032 extern ALbyte ALubyte3_size_is_not_3[(sizeof(ALubyte3)==sizeof(ALubyte[3]))?1:-1];
1033 
1034 static __inline ALshort DecodeMuLaw(ALmulaw val)
1035 { return muLawDecompressionTable[val]; }
1036 
1038 {
1039  ALint mant, exp, sign;
1040 
1041  sign = (val>>8) & 0x80;
1042  if(sign)
1043  {
1044  /* -32768 doesn't properly negate on a short; it results in itself.
1045  * So clamp to -32767 */
1046  val = maxi(val, -32767);
1047  val = -val;
1048  }
1049 
1050  val = mini(val, muLawClip);
1051  val += muLawBias;
1052 
1053  exp = muLawCompressTable[(val>>7) & 0xff];
1054  mant = (val >> (exp+3)) & 0x0f;
1055 
1056  return ~(sign | (exp<<4) | mant);
1057 }
1058 
1059 static __inline ALshort DecodeALaw(ALalaw val)
1060 { return aLawDecompressionTable[val]; }
1061 
1063 {
1064  ALint mant, exp, sign;
1065 
1066  sign = ((~val) >> 8) & 0x80;
1067  if(!sign)
1068  {
1069  val = maxi(val, -32767);
1070  val = -val;
1071  }
1072  val = mini(val, aLawClip);
1073 
1074  if(val >= 256)
1075  {
1076  exp = aLawCompressTable[(val>>8) & 0x7f];
1077  mant = (val >> (exp+3)) & 0x0f;
1078  }
1079  else
1080  {
1081  exp = 0;
1082  mant = val >> 4;
1083  }
1084 
1085  return ((exp<<4) | mant) ^ (sign^0x55);
1086 }
1087 
1088 static void DecodeIMA4Block(ALshort *dst, const ALima4 *src, ALint numchans)
1089 {
1090  ALint sample[MaxChannels], index[MaxChannels];
1092  ALsizei j,k,c;
1093 
1094  for(c = 0;c < numchans;c++)
1095  {
1096  sample[c] = *(src++);
1097  sample[c] |= *(src++) << 8;
1098  sample[c] = (sample[c]^0x8000) - 32768;
1099  index[c] = *(src++);
1100  index[c] |= *(src++) << 8;
1101  index[c] = (index[c]^0x8000) - 32768;
1102 
1103  index[c] = clampi(index[c], 0, 88);
1104 
1105  dst[c] = sample[c];
1106  }
1107 
1108  j = 1;
1109  while(j < 65)
1110  {
1111  for(c = 0;c < numchans;c++)
1112  {
1113  code[c] = *(src++);
1114  code[c] |= *(src++) << 8;
1115  code[c] |= *(src++) << 16;
1116  code[c] |= *(src++) << 24;
1117  }
1118 
1119  for(k = 0;k < 8;k++,j++)
1120  {
1121  for(c = 0;c < numchans;c++)
1122  {
1123  int nibble = code[c]&0xf;
1124  code[c] >>= 4;
1125 
1126  sample[c] += IMA4Codeword[nibble] * IMAStep_size[index[c]] / 8;
1127  sample[c] = clampi(sample[c], -32768, 32767);
1128 
1129  index[c] += IMA4Index_adjust[nibble];
1130  index[c] = clampi(index[c], 0, 88);
1131 
1132  dst[j*numchans + c] = sample[c];
1133  }
1134  }
1135  }
1136 }
1137 
1138 static void EncodeIMA4Block(ALima4 *dst, const ALshort *src, ALint *sample, ALint *index, ALint numchans)
1139 {
1140  ALsizei j,k,c;
1141 
1142  for(c = 0;c < numchans;c++)
1143  {
1144  int diff = src[c] - sample[c];
1145  int step = IMAStep_size[index[c]];
1146  int nibble;
1147 
1148  nibble = 0;
1149  if(diff < 0)
1150  {
1151  nibble = 0x8;
1152  diff = -diff;
1153  }
1154 
1155  diff = mini(step*2, diff);
1156  nibble |= (diff*8/step - 1) / 2;
1157 
1158  sample[c] += IMA4Codeword[nibble] * step / 8;
1159  sample[c] = clampi(sample[c], -32768, 32767);
1160 
1161  index[c] += IMA4Index_adjust[nibble];
1162  index[c] = clampi(index[c], 0, 88);
1163 
1164  *(dst++) = sample[c] & 0xff;
1165  *(dst++) = (sample[c]>>8) & 0xff;
1166  *(dst++) = index[c] & 0xff;
1167  *(dst++) = (index[c]>>8) & 0xff;
1168  }
1169 
1170  j = 1;
1171  while(j < 65)
1172  {
1173  for(c = 0;c < numchans;c++)
1174  {
1175  for(k = 0;k < 8;k++)
1176  {
1177  int diff = src[(j+k)*numchans + c] - sample[c];
1178  int step = IMAStep_size[index[c]];
1179  int nibble;
1180 
1181  nibble = 0;
1182  if(diff < 0)
1183  {
1184  nibble = 0x8;
1185  diff = -diff;
1186  }
1187 
1188  diff = mini(step*2, diff);
1189  nibble |= (diff*8/step - 1) / 2;
1190 
1191  sample[c] += IMA4Codeword[nibble] * step / 8;
1192  sample[c] = clampi(sample[c], -32768, 32767);
1193 
1194  index[c] += IMA4Index_adjust[nibble];
1195  index[c] = clampi(index[c], 0, 88);
1196 
1197  if(!(k&1)) *dst = nibble;
1198  else *(dst++) |= nibble<<4;
1199  }
1200  }
1201  j += 8;
1202  }
1203 }
1204 
1205 
1206 static __inline ALint DecodeByte3(ALbyte3 val)
1207 {
1208  if(IS_LITTLE_ENDIAN)
1209  return (val.b[2]<<16) | (((ALubyte)val.b[1])<<8) | ((ALubyte)val.b[0]);
1210  return (val.b[0]<<16) | (((ALubyte)val.b[1])<<8) | ((ALubyte)val.b[2]);
1211 }
1212 
1213 static __inline ALbyte3 EncodeByte3(ALint val)
1214 {
1215  if(IS_LITTLE_ENDIAN)
1216  {
1217  ALbyte3 ret = {{ val, val>>8, val>>16 }};
1218  return ret;
1219  }
1220  else
1221  {
1222  ALbyte3 ret = {{ val>>16, val>>8, val }};
1223  return ret;
1224  }
1225 }
1226 
1227 static __inline ALint DecodeUByte3(ALubyte3 val)
1228 {
1229  if(IS_LITTLE_ENDIAN)
1230  return (val.b[2]<<16) | (val.b[1]<<8) | (val.b[0]);
1231  return (val.b[0]<<16) | (val.b[1]<<8) | val.b[2];
1232 }
1233 
1234 static __inline ALubyte3 EncodeUByte3(ALint val)
1235 {
1236  if(IS_LITTLE_ENDIAN)
1237  {
1238  ALubyte3 ret = {{ val, val>>8, val>>16 }};
1239  return ret;
1240  }
1241  else
1242  {
1243  ALubyte3 ret = {{ val>>16, val>>8, val }};
1244  return ret;
1245  }
1246 }
1247 
1248 
1250 { return val; }
1252 { return val-128; }
1254 { return val>>8; }
1256 { return (val>>8)-128; }
1258 { return val>>24; }
1260 { return (val>>24)-128; }
1262 {
1263  if(val > 1.0f) return 127;
1264  if(val < -1.0f) return -128;
1265  return (ALint)(val * 127.0f);
1266 }
1268 {
1269  if(val > 1.0) return 127;
1270  if(val < -1.0) return -128;
1271  return (ALint)(val * 127.0);
1272 }
1274 { return Conv_ALbyte_ALshort(DecodeMuLaw(val)); }
1276 { return Conv_ALbyte_ALshort(DecodeALaw(val)); }
1277 static __inline ALbyte Conv_ALbyte_ALbyte3(ALbyte3 val)
1278 { return DecodeByte3(val)>>16; }
1279 static __inline ALbyte Conv_ALbyte_ALubyte3(ALubyte3 val)
1280 { return (DecodeUByte3(val)>>16)-128; }
1281 
1283 { return val+128; }
1285 { return val; }
1287 { return (val>>8)+128; }
1289 { return val>>8; }
1291 { return (val>>24)+128; }
1293 { return val>>24; }
1295 {
1296  if(val > 1.0f) return 255;
1297  if(val < -1.0f) return 0;
1298  return (ALint)(val * 127.0f) + 128;
1299 }
1301 {
1302  if(val > 1.0) return 255;
1303  if(val < -1.0) return 0;
1304  return (ALint)(val * 127.0) + 128;
1305 }
1307 { return Conv_ALubyte_ALshort(DecodeMuLaw(val)); }
1309 { return Conv_ALubyte_ALshort(DecodeALaw(val)); }
1310 static __inline ALubyte Conv_ALubyte_ALbyte3(ALbyte3 val)
1311 { return (DecodeByte3(val)>>16)+128; }
1312 static __inline ALubyte Conv_ALubyte_ALubyte3(ALubyte3 val)
1313 { return DecodeUByte3(val)>>16; }
1314 
1316 { return val<<8; }
1318 { return (val-128)<<8; }
1320 { return val; }
1322 { return val-32768; }
1324 { return val>>16; }
1326 { return (val>>16)-32768; }
1328 {
1329  if(val > 1.0f) return 32767;
1330  if(val < -1.0f) return -32768;
1331  return (ALint)(val * 32767.0f);
1332 }
1334 {
1335  if(val > 1.0) return 32767;
1336  if(val < -1.0) return -32768;
1337  return (ALint)(val * 32767.0);
1338 }
1340 { return Conv_ALshort_ALshort(DecodeMuLaw(val)); }
1342 { return Conv_ALshort_ALshort(DecodeALaw(val)); }
1343 static __inline ALshort Conv_ALshort_ALbyte3(ALbyte3 val)
1344 { return DecodeByte3(val)>>8; }
1345 static __inline ALshort Conv_ALshort_ALubyte3(ALubyte3 val)
1346 { return (DecodeUByte3(val)>>8)-32768; }
1347 
1349 { return (val+128)<<8; }
1351 { return val<<8; }
1353 { return val+32768; }
1355 { return val; }
1357 { return (val>>16)+32768; }
1359 { return val>>16; }
1361 {
1362  if(val > 1.0f) return 65535;
1363  if(val < -1.0f) return 0;
1364  return (ALint)(val * 32767.0f) + 32768;
1365 }
1367 {
1368  if(val > 1.0) return 65535;
1369  if(val < -1.0) return 0;
1370  return (ALint)(val * 32767.0) + 32768;
1371 }
1373 { return Conv_ALushort_ALshort(DecodeMuLaw(val)); }
1375 { return Conv_ALushort_ALshort(DecodeALaw(val)); }
1376 static __inline ALushort Conv_ALushort_ALbyte3(ALbyte3 val)
1377 { return (DecodeByte3(val)>>8)+32768; }
1378 static __inline ALushort Conv_ALushort_ALubyte3(ALubyte3 val)
1379 { return DecodeUByte3(val)>>8; }
1380 
1382 { return val<<24; }
1384 { return (val-128)<<24; }
1386 { return val<<16; }
1388 { return (val-32768)<<16; }
1390 { return val; }
1392 { return val-2147483648u; }
1394 {
1395  if(val > 1.0f) return 2147483647;
1396  if(val < -1.0f) return -2147483647-1;
1397  return (ALint)(val * 2147483647.0);
1398 }
1400 {
1401  if(val > 1.0) return 2147483647;
1402  if(val < -1.0) return -2147483647-1;
1403  return (ALint)(val * 2147483647.0);
1404 }
1406 { return Conv_ALint_ALshort(DecodeMuLaw(val)); }
1408 { return Conv_ALint_ALshort(DecodeALaw(val)); }
1409 static __inline ALint Conv_ALint_ALbyte3(ALbyte3 val)
1410 { return DecodeByte3(val)<<8; }
1411 static __inline ALint Conv_ALint_ALubyte3(ALubyte3 val)
1412 { return (DecodeUByte3(val)-8388608)<<8; }
1413 
1415 { return (val+128)<<24; }
1417 { return val<<24; }
1419 { return (val+32768)<<16; }
1421 { return val<<16; }
1423 { return val+2147483648u; }
1425 { return val; }
1427 {
1428  if(val > 1.0f) return 4294967295u;
1429  if(val < -1.0f) return 0;
1430  return (ALint)(val * 2147483647.0) + 2147483648u;
1431 }
1433 {
1434  if(val > 1.0) return 4294967295u;
1435  if(val < -1.0) return 0;
1436  return (ALint)(val * 2147483647.0) + 2147483648u;
1437 }
1439 { return Conv_ALuint_ALshort(DecodeMuLaw(val)); }
1441 { return Conv_ALuint_ALshort(DecodeALaw(val)); }
1442 static __inline ALuint Conv_ALuint_ALbyte3(ALbyte3 val)
1443 { return (DecodeByte3(val)+8388608)<<8; }
1444 static __inline ALuint Conv_ALuint_ALubyte3(ALubyte3 val)
1445 { return DecodeUByte3(val)<<8; }
1446 
1448 { return val * (1.0f/127.0f); }
1450 { return (val-128) * (1.0f/127.0f); }
1452 { return val * (1.0f/32767.0f); }
1454 { return (val-32768) * (1.0f/32767.0f); }
1456 { return (ALfloat)(val * (1.0/2147483647.0)); }
1458 { return (ALfloat)((ALint)(val-2147483648u) * (1.0/2147483647.0)); }
1460 { return (val==val) ? val : 0.0f; }
1462 { return (val==val) ? (ALfloat)val : 0.0f; }
1464 { return Conv_ALfloat_ALshort(DecodeMuLaw(val)); }
1466 { return Conv_ALfloat_ALshort(DecodeALaw(val)); }
1467 static __inline ALfloat Conv_ALfloat_ALbyte3(ALbyte3 val)
1468 { return (ALfloat)(DecodeByte3(val) * (1.0/8388607.0)); }
1469 static __inline ALfloat Conv_ALfloat_ALubyte3(ALubyte3 val)
1470 { return (ALfloat)((DecodeUByte3(val)-8388608) * (1.0/8388607.0)); }
1471 
1473 { return val * (1.0/127.0); }
1475 { return (val-128) * (1.0/127.0); }
1477 { return val * (1.0/32767.0); }
1479 { return (val-32768) * (1.0/32767.0); }
1481 { return val * (1.0/2147483647.0); }
1483 { return (ALint)(val-2147483648u) * (1.0/2147483647.0); }
1485 { return (val==val) ? val : 0.0f; }
1487 { return (val==val) ? val : 0.0; }
1489 { return Conv_ALdouble_ALshort(DecodeMuLaw(val)); }
1491 { return Conv_ALdouble_ALshort(DecodeALaw(val)); }
1492 static __inline ALdouble Conv_ALdouble_ALbyte3(ALbyte3 val)
1493 { return DecodeByte3(val) * (1.0/8388607.0); }
1494 static __inline ALdouble Conv_ALdouble_ALubyte3(ALubyte3 val)
1495 { return (DecodeUByte3(val)-8388608) * (1.0/8388607.0); }
1496 
1497 #define DECL_TEMPLATE(T) \
1498 static __inline ALmulaw Conv_ALmulaw_##T(T val) \
1499 { return EncodeMuLaw(Conv_ALshort_##T(val)); }
1500 
1510 { return val; }
1512 DECL_TEMPLATE(ALbyte3)
1513 DECL_TEMPLATE(ALubyte3)
1514 
1515 #undef DECL_TEMPLATE
1516 
1517 #define DECL_TEMPLATE(T) \
1518 static __inline ALalaw Conv_ALalaw_##T(T val) \
1519 { return EncodeALaw(Conv_ALshort_##T(val)); }
1520 
1531 { return val; }
1532 DECL_TEMPLATE(ALbyte3)
1533 DECL_TEMPLATE(ALubyte3)
1534 
1535 #undef DECL_TEMPLATE
1536 
1537 #define DECL_TEMPLATE(T) \
1538 static __inline ALbyte3 Conv_ALbyte3_##T(T val) \
1539 { return EncodeByte3(Conv_ALint_##T(val)>>8); }
1540 
1551 static __inline ALbyte3 Conv_ALbyte3_ALbyte3(ALbyte3 val)
1552 { return val; }
1553 DECL_TEMPLATE(ALubyte3)
1554 
1555 #undef DECL_TEMPLATE
1556 
1557 #define DECL_TEMPLATE(T) \
1558 static __inline ALubyte3 Conv_ALubyte3_##T(T val) \
1559 { return EncodeUByte3(Conv_ALuint_##T(val)>>8); }
1560 
1571 DECL_TEMPLATE(ALbyte3)
1572 static __inline ALubyte3 Conv_ALubyte3_ALubyte3(ALubyte3 val)
1573 { return val; }
1574 
1575 #undef DECL_TEMPLATE
1576 
1577 
1578 #define DECL_TEMPLATE(T1, T2) \
1579 static void Convert_##T1##_##T2(T1 *dst, const T2 *src, ALuint numchans, \
1580  ALuint len) \
1581 { \
1582  ALuint i, j; \
1583  for(i = 0;i < len;i++) \
1584  { \
1585  for(j = 0;j < numchans;j++) \
1586  *(dst++) = Conv_##T1##_##T2(*(src++)); \
1587  } \
1588 }
1589 
1592 DECL_TEMPLATE(ALbyte, ALshort)
1593 DECL_TEMPLATE(ALbyte, ALushort)
1594 DECL_TEMPLATE(ALbyte, ALint)
1595 DECL_TEMPLATE(ALbyte, ALuint)
1596 DECL_TEMPLATE(ALbyte, ALfloat)
1597 DECL_TEMPLATE(ALbyte, ALdouble)
1598 DECL_TEMPLATE(ALbyte, ALmulaw)
1599 DECL_TEMPLATE(ALbyte, ALalaw)
1600 DECL_TEMPLATE(ALbyte, ALbyte3)
1601 DECL_TEMPLATE(ALbyte, ALubyte3)
1602 
1603 DECL_TEMPLATE(ALubyte, ALbyte)
1604 DECL_TEMPLATE(ALubyte, ALubyte)
1605 DECL_TEMPLATE(ALubyte, ALshort)
1606 DECL_TEMPLATE(ALubyte, ALushort)
1607 DECL_TEMPLATE(ALubyte, ALint)
1608 DECL_TEMPLATE(ALubyte, ALuint)
1609 DECL_TEMPLATE(ALubyte, ALfloat)
1610 DECL_TEMPLATE(ALubyte, ALdouble)
1611 DECL_TEMPLATE(ALubyte, ALmulaw)
1612 DECL_TEMPLATE(ALubyte, ALalaw)
1613 DECL_TEMPLATE(ALubyte, ALbyte3)
1614 DECL_TEMPLATE(ALubyte, ALubyte3)
1615 
1616 DECL_TEMPLATE(ALshort, ALbyte)
1617 DECL_TEMPLATE(ALshort, ALubyte)
1618 DECL_TEMPLATE(ALshort, ALshort)
1619 DECL_TEMPLATE(ALshort, ALushort)
1620 DECL_TEMPLATE(ALshort, ALint)
1621 DECL_TEMPLATE(ALshort, ALuint)
1622 DECL_TEMPLATE(ALshort, ALfloat)
1623 DECL_TEMPLATE(ALshort, ALdouble)
1624 DECL_TEMPLATE(ALshort, ALmulaw)
1625 DECL_TEMPLATE(ALshort, ALalaw)
1626 DECL_TEMPLATE(ALshort, ALbyte3)
1627 DECL_TEMPLATE(ALshort, ALubyte3)
1628 
1629 DECL_TEMPLATE(ALushort, ALbyte)
1630 DECL_TEMPLATE(ALushort, ALubyte)
1631 DECL_TEMPLATE(ALushort, ALshort)
1632 DECL_TEMPLATE(ALushort, ALushort)
1633 DECL_TEMPLATE(ALushort, ALint)
1634 DECL_TEMPLATE(ALushort, ALuint)
1635 DECL_TEMPLATE(ALushort, ALfloat)
1636 DECL_TEMPLATE(ALushort, ALdouble)
1637 DECL_TEMPLATE(ALushort, ALmulaw)
1638 DECL_TEMPLATE(ALushort, ALalaw)
1639 DECL_TEMPLATE(ALushort, ALbyte3)
1640 DECL_TEMPLATE(ALushort, ALubyte3)
1641 
1642 DECL_TEMPLATE(ALint, ALbyte)
1643 DECL_TEMPLATE(ALint, ALubyte)
1644 DECL_TEMPLATE(ALint, ALshort)
1645 DECL_TEMPLATE(ALint, ALushort)
1646 DECL_TEMPLATE(ALint, ALint)
1647 DECL_TEMPLATE(ALint, ALuint)
1648 DECL_TEMPLATE(ALint, ALfloat)
1649 DECL_TEMPLATE(ALint, ALdouble)
1650 DECL_TEMPLATE(ALint, ALmulaw)
1651 DECL_TEMPLATE(ALint, ALalaw)
1652 DECL_TEMPLATE(ALint, ALbyte3)
1653 DECL_TEMPLATE(ALint, ALubyte3)
1654 
1655 DECL_TEMPLATE(ALuint, ALbyte)
1656 DECL_TEMPLATE(ALuint, ALubyte)
1657 DECL_TEMPLATE(ALuint, ALshort)
1658 DECL_TEMPLATE(ALuint, ALushort)
1659 DECL_TEMPLATE(ALuint, ALint)
1660 DECL_TEMPLATE(ALuint, ALuint)
1661 DECL_TEMPLATE(ALuint, ALfloat)
1662 DECL_TEMPLATE(ALuint, ALdouble)
1663 DECL_TEMPLATE(ALuint, ALmulaw)
1664 DECL_TEMPLATE(ALuint, ALalaw)
1665 DECL_TEMPLATE(ALuint, ALbyte3)
1666 DECL_TEMPLATE(ALuint, ALubyte3)
1667 
1668 DECL_TEMPLATE(ALfloat, ALbyte)
1669 DECL_TEMPLATE(ALfloat, ALubyte)
1670 DECL_TEMPLATE(ALfloat, ALshort)
1671 DECL_TEMPLATE(ALfloat, ALushort)
1672 DECL_TEMPLATE(ALfloat, ALint)
1673 DECL_TEMPLATE(ALfloat, ALuint)
1674 DECL_TEMPLATE(ALfloat, ALfloat)
1675 DECL_TEMPLATE(ALfloat, ALdouble)
1676 DECL_TEMPLATE(ALfloat, ALmulaw)
1677 DECL_TEMPLATE(ALfloat, ALalaw)
1678 DECL_TEMPLATE(ALfloat, ALbyte3)
1679 DECL_TEMPLATE(ALfloat, ALubyte3)
1680 
1681 DECL_TEMPLATE(ALdouble, ALbyte)
1682 DECL_TEMPLATE(ALdouble, ALubyte)
1683 DECL_TEMPLATE(ALdouble, ALshort)
1684 DECL_TEMPLATE(ALdouble, ALushort)
1685 DECL_TEMPLATE(ALdouble, ALint)
1686 DECL_TEMPLATE(ALdouble, ALuint)
1687 DECL_TEMPLATE(ALdouble, ALfloat)
1688 DECL_TEMPLATE(ALdouble, ALdouble)
1689 DECL_TEMPLATE(ALdouble, ALmulaw)
1690 DECL_TEMPLATE(ALdouble, ALalaw)
1691 DECL_TEMPLATE(ALdouble, ALbyte3)
1692 DECL_TEMPLATE(ALdouble, ALubyte3)
1693 
1694 DECL_TEMPLATE(ALmulaw, ALbyte)
1695 DECL_TEMPLATE(ALmulaw, ALubyte)
1696 DECL_TEMPLATE(ALmulaw, ALshort)
1697 DECL_TEMPLATE(ALmulaw, ALushort)
1698 DECL_TEMPLATE(ALmulaw, ALint)
1699 DECL_TEMPLATE(ALmulaw, ALuint)
1700 DECL_TEMPLATE(ALmulaw, ALfloat)
1701 DECL_TEMPLATE(ALmulaw, ALdouble)
1702 DECL_TEMPLATE(ALmulaw, ALmulaw)
1703 DECL_TEMPLATE(ALmulaw, ALalaw)
1704 DECL_TEMPLATE(ALmulaw, ALbyte3)
1705 DECL_TEMPLATE(ALmulaw, ALubyte3)
1706 
1707 DECL_TEMPLATE(ALalaw, ALbyte)
1708 DECL_TEMPLATE(ALalaw, ALubyte)
1709 DECL_TEMPLATE(ALalaw, ALshort)
1710 DECL_TEMPLATE(ALalaw, ALushort)
1711 DECL_TEMPLATE(ALalaw, ALint)
1712 DECL_TEMPLATE(ALalaw, ALuint)
1713 DECL_TEMPLATE(ALalaw, ALfloat)
1714 DECL_TEMPLATE(ALalaw, ALdouble)
1715 DECL_TEMPLATE(ALalaw, ALmulaw)
1716 DECL_TEMPLATE(ALalaw, ALalaw)
1717 DECL_TEMPLATE(ALalaw, ALbyte3)
1718 DECL_TEMPLATE(ALalaw, ALubyte3)
1719 
1720 DECL_TEMPLATE(ALbyte3, ALbyte)
1721 DECL_TEMPLATE(ALbyte3, ALubyte)
1722 DECL_TEMPLATE(ALbyte3, ALshort)
1723 DECL_TEMPLATE(ALbyte3, ALushort)
1724 DECL_TEMPLATE(ALbyte3, ALint)
1725 DECL_TEMPLATE(ALbyte3, ALuint)
1726 DECL_TEMPLATE(ALbyte3, ALfloat)
1727 DECL_TEMPLATE(ALbyte3, ALdouble)
1728 DECL_TEMPLATE(ALbyte3, ALmulaw)
1729 DECL_TEMPLATE(ALbyte3, ALalaw)
1730 DECL_TEMPLATE(ALbyte3, ALbyte3)
1731 DECL_TEMPLATE(ALbyte3, ALubyte3)
1732 
1733 DECL_TEMPLATE(ALubyte3, ALbyte)
1734 DECL_TEMPLATE(ALubyte3, ALubyte)
1735 DECL_TEMPLATE(ALubyte3, ALshort)
1736 DECL_TEMPLATE(ALubyte3, ALushort)
1737 DECL_TEMPLATE(ALubyte3, ALint)
1738 DECL_TEMPLATE(ALubyte3, ALuint)
1739 DECL_TEMPLATE(ALubyte3, ALfloat)
1740 DECL_TEMPLATE(ALubyte3, ALdouble)
1741 DECL_TEMPLATE(ALubyte3, ALmulaw)
1742 DECL_TEMPLATE(ALubyte3, ALalaw)
1743 DECL_TEMPLATE(ALubyte3, ALbyte3)
1744 DECL_TEMPLATE(ALubyte3, ALubyte3)
1745 
1746 #undef DECL_TEMPLATE
1747 
1748 #define DECL_TEMPLATE(T) \
1749 static void Convert_##T##_ALima4(T *dst, const ALima4 *src, ALuint numchans, \
1750  ALuint len) \
1751 { \
1752  ALshort tmp[65*MaxChannels]; /* Max samples an IMA4 frame can be */ \
1753  ALuint i, j, k; \
1754  \
1755  i = 0; \
1756  while(i < len) \
1757  { \
1758  DecodeIMA4Block(tmp, src, numchans); \
1759  src += 36*numchans; \
1760  \
1761  for(j = 0;j < 65 && i < len;j++,i++) \
1762  { \
1763  for(k = 0;k < numchans;k++) \
1764  *(dst++) = Conv_##T##_ALshort(tmp[j*numchans + k]); \
1765  } \
1766  } \
1767 }
1768 
1769 DECL_TEMPLATE(ALbyte)
1770 DECL_TEMPLATE(ALubyte)
1771 DECL_TEMPLATE(ALshort)
1772 DECL_TEMPLATE(ALushort)
1773 DECL_TEMPLATE(ALint)
1774 DECL_TEMPLATE(ALuint)
1775 DECL_TEMPLATE(ALfloat)
1776 DECL_TEMPLATE(ALdouble)
1777 DECL_TEMPLATE(ALmulaw)
1778 DECL_TEMPLATE(ALalaw)
1779 DECL_TEMPLATE(ALbyte3)
1780 DECL_TEMPLATE(ALubyte3)
1781 
1782 #undef DECL_TEMPLATE
1783 
1784 #define DECL_TEMPLATE(T) \
1785 static void Convert_ALima4_##T(ALima4 *dst, const T *src, ALuint numchans, \
1786  ALuint len) \
1787 { \
1788  ALshort tmp[65*MaxChannels]; /* Max samples an IMA4 frame can be */ \
1789  ALint sample[MaxChannels] = {0,0,0,0,0,0,0,0}; \
1790  ALint index[MaxChannels] = {0,0,0,0,0,0,0,0}; \
1791  ALuint i, j; \
1792  \
1793  for(i = 0;i < len;i += 65) \
1794  { \
1795  for(j = 0;j < 65*numchans;j++) \
1796  tmp[j] = Conv_ALshort_##T(*(src++)); \
1797  EncodeIMA4Block(dst, tmp, sample, index, numchans); \
1798  dst += 36*numchans; \
1799  } \
1800 }
1801 
1802 DECL_TEMPLATE(ALbyte)
1803 DECL_TEMPLATE(ALubyte)
1804 DECL_TEMPLATE(ALshort)
1805 DECL_TEMPLATE(ALushort)
1806 DECL_TEMPLATE(ALint)
1807 DECL_TEMPLATE(ALuint)
1808 DECL_TEMPLATE(ALfloat)
1809 DECL_TEMPLATE(ALdouble)
1810 DECL_TEMPLATE(ALmulaw)
1811 DECL_TEMPLATE(ALalaw)
1813  ALuint numchans, ALuint numblocks)
1814 { memcpy(dst, src, numblocks*36*numchans); }
1815 DECL_TEMPLATE(ALbyte3)
1816 DECL_TEMPLATE(ALubyte3)
1817 
1818 #undef DECL_TEMPLATE
1819 
1820 #define DECL_TEMPLATE(T) \
1821 static void Convert_##T(T *dst, const ALvoid *src, enum UserFmtType srcType, \
1822  ALsizei numchans, ALsizei len) \
1823 { \
1824  switch(srcType) \
1825  { \
1826  case UserFmtByte: \
1827  Convert_##T##_ALbyte(dst, src, numchans, len); \
1828  break; \
1829  case UserFmtUByte: \
1830  Convert_##T##_ALubyte(dst, src, numchans, len); \
1831  break; \
1832  case UserFmtShort: \
1833  Convert_##T##_ALshort(dst, src, numchans, len); \
1834  break; \
1835  case UserFmtUShort: \
1836  Convert_##T##_ALushort(dst, src, numchans, len); \
1837  break; \
1838  case UserFmtInt: \
1839  Convert_##T##_ALint(dst, src, numchans, len); \
1840  break; \
1841  case UserFmtUInt: \
1842  Convert_##T##_ALuint(dst, src, numchans, len); \
1843  break; \
1844  case UserFmtFloat: \
1845  Convert_##T##_ALfloat(dst, src, numchans, len); \
1846  break; \
1847  case UserFmtDouble: \
1848  Convert_##T##_ALdouble(dst, src, numchans, len); \
1849  break; \
1850  case UserFmtMulaw: \
1851  Convert_##T##_ALmulaw(dst, src, numchans, len); \
1852  break; \
1853  case UserFmtAlaw: \
1854  Convert_##T##_ALalaw(dst, src, numchans, len); \
1855  break; \
1856  case UserFmtIMA4: \
1857  Convert_##T##_ALima4(dst, src, numchans, len); \
1858  break; \
1859  case UserFmtByte3: \
1860  Convert_##T##_ALbyte3(dst, src, numchans, len); \
1861  break; \
1862  case UserFmtUByte3: \
1863  Convert_##T##_ALubyte3(dst, src, numchans, len); \
1864  break; \
1865  } \
1866 }
1867 
1868 DECL_TEMPLATE(ALbyte)
1869 DECL_TEMPLATE(ALubyte)
1870 DECL_TEMPLATE(ALshort)
1871 DECL_TEMPLATE(ALushort)
1872 DECL_TEMPLATE(ALint)
1873 DECL_TEMPLATE(ALuint)
1874 DECL_TEMPLATE(ALfloat)
1875 DECL_TEMPLATE(ALdouble)
1876 DECL_TEMPLATE(ALmulaw)
1877 DECL_TEMPLATE(ALalaw)
1879 DECL_TEMPLATE(ALbyte3)
1880 DECL_TEMPLATE(ALubyte3)
1881 
1882 #undef DECL_TEMPLATE
1883 
1884 
1885 static void ConvertData(ALvoid *dst, enum UserFmtType dstType, const ALvoid *src, enum UserFmtType srcType, ALsizei numchans, ALsizei len)
1886 {
1887  switch(dstType)
1888  {
1889  case UserFmtByte:
1890  Convert_ALbyte(dst, src, srcType, numchans, len);
1891  break;
1892  case UserFmtUByte:
1893  Convert_ALubyte(dst, src, srcType, numchans, len);
1894  break;
1895  case UserFmtShort:
1896  Convert_ALshort(dst, src, srcType, numchans, len);
1897  break;
1898  case UserFmtUShort:
1899  Convert_ALushort(dst, src, srcType, numchans, len);
1900  break;
1901  case UserFmtInt:
1902  Convert_ALint(dst, src, srcType, numchans, len);
1903  break;
1904  case UserFmtUInt:
1905  Convert_ALuint(dst, src, srcType, numchans, len);
1906  break;
1907  case UserFmtFloat:
1908  Convert_ALfloat(dst, src, srcType, numchans, len);
1909  break;
1910  case UserFmtDouble:
1911  Convert_ALdouble(dst, src, srcType, numchans, len);
1912  break;
1913  case UserFmtMulaw:
1914  Convert_ALmulaw(dst, src, srcType, numchans, len);
1915  break;
1916  case UserFmtAlaw:
1917  Convert_ALalaw(dst, src, srcType, numchans, len);
1918  break;
1919  case UserFmtIMA4:
1920  Convert_ALima4(dst, src, srcType, numchans, len);
1921  break;
1922  case UserFmtByte3:
1923  Convert_ALbyte3(dst, src, srcType, numchans, len);
1924  break;
1925  case UserFmtUByte3:
1926  Convert_ALubyte3(dst, src, srcType, numchans, len);
1927  break;
1928  }
1929 }
1930 
1931 
1932 /*
1933  * LoadData
1934  *
1935  * Loads the specified data into the buffer, using the specified formats.
1936  * Currently, the new format must have the same channel configuration as the
1937  * original format.
1938  */
1939 static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALboolean storesrc)
1940 {
1941  ALuint NewChannels, NewBytes;
1942  enum FmtChannels DstChannels;
1943  enum FmtType DstType;
1944  ALuint64 newsize;
1945  ALvoid *temp;
1946 
1947  if(DecomposeFormat(NewFormat, &DstChannels, &DstType) == AL_FALSE ||
1948  (long)SrcChannels != (long)DstChannels)
1949  return AL_INVALID_ENUM;
1950 
1951  NewChannels = ChannelsFromFmt(DstChannels);
1952  NewBytes = BytesFromFmt(DstType);
1953 
1954  newsize = frames;
1955  newsize *= NewBytes;
1956  newsize *= NewChannels;
1957  if(newsize > INT_MAX)
1958  return AL_OUT_OF_MEMORY;
1959 
1960  WriteLock(&ALBuf->lock);
1961  if(ALBuf->ref != 0)
1962  {
1963  WriteUnlock(&ALBuf->lock);
1964  return AL_INVALID_OPERATION;
1965  }
1966 
1967  temp = realloc(ALBuf->data, (size_t)newsize);
1968  if(!temp && newsize)
1969  {
1970  WriteUnlock(&ALBuf->lock);
1971  return AL_OUT_OF_MEMORY;
1972  }
1973  ALBuf->data = temp;
1974 
1975  if(data != NULL)
1976  ConvertData(ALBuf->data, DstType, data, SrcType, NewChannels, frames);
1977 
1978  if(storesrc)
1979  {
1980  ALBuf->OriginalChannels = SrcChannels;
1981  ALBuf->OriginalType = SrcType;
1982  if(SrcType == UserFmtIMA4)
1983  ALBuf->OriginalSize = frames / 65 * 36 * ChannelsFromUserFmt(SrcChannels);
1984  else
1985  ALBuf->OriginalSize = frames * FrameSizeFromUserFmt(SrcChannels, SrcType);
1986  }
1987  else
1988  {
1989  ALBuf->OriginalChannels = DstChannels;
1990  ALBuf->OriginalType = DstType;
1991  ALBuf->OriginalSize = frames * NewBytes * NewChannels;
1992  }
1993 
1994  ALBuf->Frequency = freq;
1995  ALBuf->FmtChannels = DstChannels;
1996  ALBuf->FmtType = DstType;
1997  ALBuf->Format = NewFormat;
1998 
1999  ALBuf->SampleLen = frames;
2000  ALBuf->LoopStart = 0;
2001  ALBuf->LoopEnd = ALBuf->SampleLen;
2002 
2003  WriteUnlock(&ALBuf->lock);
2004  return AL_NO_ERROR;
2005 }
2006 
2007 
2009 {
2010  switch(type)
2011  {
2012  case UserFmtByte: return sizeof(ALbyte);
2013  case UserFmtUByte: return sizeof(ALubyte);
2014  case UserFmtShort: return sizeof(ALshort);
2015  case UserFmtUShort: return sizeof(ALushort);
2016  case UserFmtInt: return sizeof(ALint);
2017  case UserFmtUInt: return sizeof(ALuint);
2018  case UserFmtFloat: return sizeof(ALfloat);
2019  case UserFmtDouble: return sizeof(ALdouble);
2020  case UserFmtByte3: return sizeof(ALbyte3);
2021  case UserFmtUByte3: return sizeof(ALubyte3);
2022  case UserFmtMulaw: return sizeof(ALubyte);
2023  case UserFmtAlaw: return sizeof(ALubyte);
2024  case UserFmtIMA4: break; /* not handled here */
2025  }
2026  return 0;
2027 }
2029 {
2030  switch(chans)
2031  {
2032  case UserFmtMono: return 1;
2033  case UserFmtStereo: return 2;
2034  case UserFmtRear: return 2;
2035  case UserFmtQuad: return 4;
2036  case UserFmtX51: return 6;
2037  case UserFmtX61: return 7;
2038  case UserFmtX71: return 8;
2039  }
2040  return 0;
2041 }
2043  enum UserFmtType *type)
2044 {
2045  static const struct {
2046  ALenum format;
2047  enum UserFmtChannels channels;
2048  enum UserFmtType type;
2049  } list[] = {
2057 
2065 
2070 
2073 
2078 
2083 
2088 
2093  };
2094  ALuint i;
2095 
2096  for(i = 0;i < COUNTOF(list);i++)
2097  {
2098  if(list[i].format == format)
2099  {
2100  *chans = list[i].channels;
2101  *type = list[i].type;
2102  return AL_TRUE;
2103  }
2104  }
2105 
2106  return AL_FALSE;
2107 }
2108 
2110 {
2111  switch(type)
2112  {
2113  case FmtByte: return sizeof(ALbyte);
2114  case FmtShort: return sizeof(ALshort);
2115  case FmtFloat: return sizeof(ALfloat);
2116  }
2117  return 0;
2118 }
2119 ALuint ChannelsFromFmt(enum FmtChannels chans)
2120 {
2121  switch(chans)
2122  {
2123  case FmtMono: return 1;
2124  case FmtStereo: return 2;
2125  case FmtRear: return 2;
2126  case FmtQuad: return 4;
2127  case FmtX51: return 6;
2128  case FmtX61: return 7;
2129  case FmtX71: return 8;
2130  }
2131  return 0;
2132 }
2134 {
2135  static const struct {
2136  ALenum format;
2137  enum FmtChannels channels;
2138  enum FmtType type;
2139  } list[] = {
2143 
2147 
2151 
2154 
2158 
2162 
2166 
2170  };
2171  ALuint i;
2172 
2173  for(i = 0;i < COUNTOF(list);i++)
2174  {
2175  if(list[i].format == format)
2176  {
2177  *chans = list[i].channels;
2178  *type = list[i].type;
2179  return AL_TRUE;
2180  }
2181  }
2182 
2183  return AL_FALSE;
2184 }
2185 
2186 
2188 {
2189  switch(type)
2190  {
2191  case AL_BYTE_SOFT:
2192  case AL_UNSIGNED_BYTE_SOFT:
2193  case AL_SHORT_SOFT:
2195  case AL_INT_SOFT:
2196  case AL_UNSIGNED_INT_SOFT:
2197  case AL_FLOAT_SOFT:
2198  case AL_DOUBLE_SOFT:
2199  case AL_BYTE3_SOFT:
2201  return AL_TRUE;
2202  }
2203  return AL_FALSE;
2204 }
2205 
2207 {
2208  switch(channels)
2209  {
2210  case AL_MONO_SOFT:
2211  case AL_STEREO_SOFT:
2212  case AL_REAR_SOFT:
2213  case AL_QUAD_SOFT:
2214  case AL_5POINT1_SOFT:
2215  case AL_6POINT1_SOFT:
2216  case AL_7POINT1_SOFT:
2217  return AL_TRUE;
2218  }
2219  return AL_FALSE;
2220 }
2221 
2222 
2223 /*
2224  * ReleaseALBuffers()
2225  *
2226  * INTERNAL: Called to destroy any buffers that still exist on the device
2227  */
2229 {
2230  ALsizei i;
2231  for(i = 0;i < device->BufferMap.size;i++)
2232  {
2233  ALbuffer *temp = device->BufferMap.array[i].value;
2234  device->BufferMap.array[i].value = NULL;
2235 
2236  free(temp->data);
2237 
2238  FreeThunkEntry(temp->id);
2239  memset(temp, 0, sizeof(ALbuffer));
2240  free(temp);
2241  }
2242 }
static __inline ALint Conv_ALint_ALbyte(ALbyte val)
Definition: alBuffer.c:1381
UIntMap BufferMap
Definition: alMain.h:589
#define AL_APIENTRY
Definition: al.h:21
AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum param, ALint *values)
Definition: alBuffer.c:975
static __inline ALuint Conv_ALuint_ALfloat(ALfloat val)
Definition: alBuffer.c:1426
ALvoid * data
Definition: alBuffer.h:71
#define AL_6POINT1_32F_SOFT
Definition: alext.h:247
static __inline ALdouble Conv_ALdouble_ALushort(ALushort val)
Definition: alBuffer.c:1478
static __inline ALuint Conv_ALuint_ALubyte(ALubyte val)
Definition: alBuffer.c:1416
unsigned char ALubyte
Definition: al.h:47
static __inline ALfloat Conv_ALfloat_ALalaw(ALalaw val)
Definition: alBuffer.c:1465
void FreeThunkEntry(ALuint index)
Definition: alThunk.c:83
static __inline ALubyte Conv_ALubyte_ALubyte(ALubyte val)
Definition: alBuffer.c:1284
LPALBUFFERSAMPLESSOFT alBufferSamplesSOFT
Definition: allatency.c:45
#define IS_LITTLE_ENDIAN
Definition: alMain.h:61
GLuint const GLfloat * val
Definition: glew.h:2715
#define AL_FORMAT_REAR_MULAW
Definition: alext.h:122
#define AL_5POINT1_8_SOFT
Definition: alext.h:242
ALbyte ALbyte3_size_is_not_3[(sizeof(ALbyte3)==sizeof(ALbyte[3]))?1:-1]
void ALvoid
Definition: al.h:74
static __inline ALubyte3 EncodeUByte3(ALint val)
Definition: alBuffer.c:1234
GLenum GLint param
Definition: gl2ext.h:1491
static __inline ALbyte Conv_ALbyte_ALuint(ALuint val)
Definition: alBuffer.c:1259
#define AL_STEREO_SOFT
Definition: alext.h:210
static __inline ALubyte Conv_ALubyte_ALushort(ALushort val)
Definition: alBuffer.c:1288
#define AL_FORMAT_51CHN32
Definition: alext.h:108
#define AL_6POINT1_16_SOFT
Definition: alext.h:246
static __inline ALmulaw Conv_ALmulaw_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1509
AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, ALvoid *data)
Definition: alBuffer.c:544
#define AL_6POINT1_SOFT
Definition: alext.h:214
#define AL_FORMAT_QUAD8
Definition: alext.h:100
static __inline ALdouble Conv_ALdouble_ALbyte(ALbyte val)
Definition: alBuffer.c:1472
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
#define AL_FORMAT_61CHN16
Definition: alext.h:110
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1824
#define CHECK_VALUE(ctx, cond)
Definition: alMain.h:875
#define AL_FORMAT_STEREO_IMA4
Definition: alext.h:131
static __inline ALubyte Conv_ALubyte_ALbyte(ALbyte val)
Definition: alBuffer.c:1282
AL_API void AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
Definition: alBuffer.c:289
enum FmtType FmtType
Definition: alBuffer.h:78
static void EncodeIMA4Block(ALima4 *dst, const ALshort *src, ALint *sample, ALint *index, ALint numchans)
Definition: alBuffer.c:1138
#define AL_6POINT1_8_SOFT
Definition: alext.h:245
#define AL_TRUE
Definition: al.h:86
enum FmtChannels FmtChannels
Definition: alBuffer.h:77
AL_API void AL_APIENTRY alBuffer3f(ALuint buffer, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3)
Definition: alBuffer.c:639
#define RemoveBuffer(m, k)
Definition: alMain.h:670
static __inline ALuint Conv_ALuint_ALshort(ALshort val)
Definition: alBuffer.c:1418
#define AL_FORMAT_61CHN8
Definition: alext.h:109
#define AL_FORMAT_STEREO_MULAW
Definition: alext.h:120
#define NULL
Definition: ftobjs.h:61
#define AL_QUAD32F_SOFT
Definition: alext.h:238
static __inline ALdouble Conv_ALdouble_ALfloat(ALfloat val)
Definition: alBuffer.c:1484
static __inline ALshort Conv_ALshort_ALdouble(ALdouble val)
Definition: alBuffer.c:1333
static void DecodeIMA4Block(ALshort *dst, const ALima4 *src, ALint numchans)
Definition: alBuffer.c:1088
GLclampf f
Definition: glew.h:3390
static __inline ALbyte Conv_ALbyte_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1273
#define AL_FORMAT_QUAD32
Definition: alext.h:102
struct UIntMap::@59 * array
#define AL_FORMAT_MONO_MULAW
Definition: alext.h:119
static __inline ALfloat Conv_ALfloat_ALshort(ALshort val)
Definition: alBuffer.c:1451
static __inline ALfloat Conv_ALfloat_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1469
#define AL_BYTE_LENGTH_SOFT
Definition: alext.h:254
static const ALshort muLawDecompressionTable[256]
Definition: alBuffer.c:74
static __inline ALuint Conv_ALuint_ALuint(ALuint val)
Definition: alBuffer.c:1424
#define AL_REAR_SOFT
Definition: alext.h:211
int32_t k
Definition: e_log.c:102
static __inline ALshort Conv_ALshort_ALshort(ALshort val)
Definition: alBuffer.c:1319
RWLock lock
Definition: alBuffer.h:90
#define al_throwerr(ctx, err)
Definition: alMain.h:866
GLclampd n
Definition: glew.h:7287
#define AL_INVALID_VALUE
Definition: al.h:373
static __inline ALfloat Conv_ALfloat_ALushort(ALushort val)
Definition: alBuffer.c:1453
ALuint BytesFromFmt(enum FmtType type)
Definition: alBuffer.c:2109
int ALsizei
Definition: al.h:62
void ReadLock(RWLock *lock)
Definition: helpers.c:515
static __inline ALubyte Conv_ALubyte_ALint(ALint val)
Definition: alBuffer.c:1290
SDL_EventEntry * free
Definition: SDL_events.c:80
#define AL_FORMAT_REAR8
Definition: alext.h:103
#define al_try
Definition: alMain.h:838
int ALint
Definition: al.h:56
#define AL_MONO8_SOFT
Definition: alext.h:230
int32_t j
Definition: e_log.c:102
static const char aLawCompressTable[128]
Definition: alBuffer.c:171
static __inline ALfloat Conv_ALfloat_ALuint(ALuint val)
Definition: alBuffer.c:1457
static __inline ALint maxi(ALint a, ALint b)
Definition: alu.h:70
#define memset
Definition: SDL_malloc.c:633
#define AL_FALSE
Definition: al.h:83
static const int muLawClip
Definition: alBuffer.c:111
enum UserFmtChannels OriginalChannels
Definition: alBuffer.h:80
static __inline ALshort Conv_ALshort_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1345
#define AL_LOOP_POINTS_SOFT
Definition: alext.h:179
#define AL_FORMAT_MONO_IMA4
Definition: alext.h:130
static __inline ALint Conv_ALint_ALshort(ALshort val)
Definition: alBuffer.c:1385
#define AL_STEREO32F_SOFT
Definition: alext.h:235
ALsizei Frequency
Definition: alBuffer.h:73
static const int muLawBias
Definition: alBuffer.c:110
short ALshort
Definition: al.h:50
static __inline ALdouble Conv_ALdouble_ALuint(ALuint val)
Definition: alBuffer.c:1482
static __inline ALfloat Conv_ALfloat_ALubyte(ALubyte val)
Definition: alBuffer.c:1449
static __inline ALushort Conv_ALushort_ALbyte(ALbyte val)
Definition: alBuffer.c:1348
static __inline ALdouble Conv_ALdouble_ALshort(ALshort val)
Definition: alBuffer.c:1476
#define al_endtry
Definition: alMain.h:853
ALubyte ALima4
Definition: alBuffer.c:1024
#define AL_UNSIGNED_INT_SOFT
Definition: alext.h:223
static __inline ALbyte Conv_ALbyte_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1277
static __inline ALint clampi(ALint val, ALint min, ALint max)
Definition: alu.h:72
static __inline ALint Conv_ALint_ALint(ALint val)
Definition: alBuffer.c:1389
GLenum GLsizei len
Definition: glew.h:7035
static __inline ALushort Conv_ALushort_ALfloat(ALfloat val)
Definition: alBuffer.c:1360
ALCcontext * GetContextRef(void)
Definition: ALc.c:1999
static __inline ALubyte Conv_ALubyte_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1310
static __inline ALbyte Conv_ALbyte_ALalaw(ALalaw val)
Definition: alBuffer.c:1275
static __inline ALubyte Conv_ALubyte_ALdouble(ALdouble val)
Definition: alBuffer.c:1300
float ALfloat
Definition: al.h:68
#define calloc
Definition: SDL_malloc.c:636
static __inline ALint Conv_ALint_ALalaw(ALalaw val)
Definition: alBuffer.c:1407
ALubyte ALmulaw
Definition: alBuffer.c:1022
static __inline ALbyte Conv_ALbyte_ALubyte(ALubyte val)
Definition: alBuffer.c:1251
static __inline ALint Conv_ALint_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1409
ALsizei SampleLen
Definition: alBuffer.h:75
#define AL_7POINT1_8_SOFT
Definition: alext.h:248
signed char ALbyte
Definition: al.h:44
static __inline ALuint Conv_ALuint_ALbyte(ALbyte val)
Definition: alBuffer.c:1414
ret
Definition: glew_str_glx.c:2
#define LookupBuffer(m, k)
Definition: alMain.h:667
#define AL_INT_SOFT
Definition: alext.h:222
AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer, ALsizei offset, ALsizei samples, ALenum channels, ALenum type, const ALvoid *data)
Definition: alBuffer.c:499
#define AL_DOUBLE_SOFT
Definition: alext.h:225
static __inline ALushort Conv_ALushort_ALuint(ALuint val)
Definition: alBuffer.c:1358
#define AL_FORMAT_51CHN16
Definition: alext.h:107
#define AL_FORMAT_QUAD16_LOKI
Definition: alext.h:64
static __inline ALint Conv_ALint_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1405
ALvoid * value
Definition: alMain.h:310
ALsizei LoopStart
Definition: alBuffer.h:84
AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei offset, ALsizei length)
Definition: alBuffer.c:404
static __inline ALbyte Conv_ALbyte_ALfloat(ALfloat val)
Definition: alBuffer.c:1261
static __inline ALint Conv_ALint_ALfloat(ALfloat val)
Definition: alBuffer.c:1393
const GLuint * buffers
Definition: glew.h:1669
static __inline ALalaw Conv_ALalaw_ALalaw(ALalaw val)
Definition: alBuffer.c:1530
static __inline ALfloat Conv_ALfloat_ALfloat(ALfloat val)
Definition: alBuffer.c:1459
static __inline ALdouble Conv_ALdouble_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1492
#define AL_SIZE
Definition: al.h:351
AL_API void AL_APIENTRY alGetBufferfv(ALuint buffer, ALenum param, ALfloat *values)
Definition: alBuffer.c:858
#define AL_CHANNELS
Definition: al.h:349
#define AL_FORMAT_STEREO_ALAW_EXT
Definition: alext.h:88
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
#define DECL_TEMPLATE(func)
Definition: alcModulator.c:85
static __inline ALushort Conv_ALushort_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1378
#define AL_5POINT1_SOFT
Definition: alext.h:213
#define AL_FORMAT_QUAD16
Definition: alext.h:101
static __inline ALuint Conv_ALuint_ALdouble(ALdouble val)
Definition: alBuffer.c:1432
double ALdouble
Definition: al.h:71
#define AL_SHORT_SOFT
Definition: alext.h:220
static void ConvertData(ALvoid *dst, enum UserFmtType dstType, const ALvoid *src, enum UserFmtType srcType, ALsizei numchans, ALsizei len)
Definition: alBuffer.c:1885
static __inline ALshort Conv_ALshort_ALint(ALint val)
Definition: alBuffer.c:1323
ALuint u
Definition: alMain.h:58
#define AL_UNSIGNED_BYTE_SOFT
Definition: alext.h:219
GLuint64EXT * result
Definition: glew.h:12708
int32_t sign
Definition: e_sqrt.c:107
static __inline ALshort Conv_ALshort_ALbyte(ALbyte val)
Definition: alBuffer.c:1315
static __inline ALdouble Conv_ALdouble_ALalaw(ALalaw val)
Definition: alBuffer.c:1490
#define AL_FLOAT_SOFT
Definition: alext.h:224
static __inline ALbyte3 EncodeByte3(ALint val)
Definition: alBuffer.c:1213
FmtType
Definition: alBuffer.h:46
static ALboolean IsValidChannels(ALenum channels)
Definition: alBuffer.c:2206
GLenum GLenum dst
Definition: glew.h:2396
enum UserFmtType OriginalType
Definition: alBuffer.h:81
#define AL_SAMPLE_LENGTH_SOFT
Definition: alext.h:255
#define AL_FORMAT_MONO_DOUBLE_EXT
Definition: alext.h:75
static __inline ALint DecodeByte3(ALbyte3 val)
Definition: alBuffer.c:1206
GLsizei GLsizei * length
Definition: gl2ext.h:792
static __inline ALint Conv_ALint_ALdouble(ALdouble val)
Definition: alBuffer.c:1399
#define AL_QUAD8_SOFT
Definition: alext.h:236
void WriteUnlock(RWLock *lock)
Definition: helpers.c:538
#define AL_FORMAT_STEREO_FLOAT32
Definition: alext.h:70
unsigned short ALushort
Definition: al.h:53
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
#define al_catchany()
Definition: alMain.h:851
#define AL_7POINT1_SOFT
Definition: alext.h:215
#define AL_INVALID_NAME
Definition: al.h:367
static ALmulaw EncodeMuLaw(ALshort val)
Definition: alBuffer.c:1037
static __inline ALint Conv_ALint_ALubyte(ALubyte val)
Definition: alBuffer.c:1383
#define AL_BYTE3_SOFT
Definition: alext.h:226
static __inline ALushort Conv_ALushort_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1376
static __inline ALbyte Conv_ALbyte_ALdouble(ALdouble val)
Definition: alBuffer.c:1267
void ReadUnlock(RWLock *lock)
Definition: helpers.c:525
static __inline ALushort Conv_ALushort_ALushort(ALushort val)
Definition: alBuffer.c:1354
static __inline ALuint FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type)
Definition: alBuffer.h:38
static const int IMA4Index_adjust[16]
Definition: alBuffer.c:67
static __inline ALubyte3 Conv_ALubyte3_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1572
static __inline ALushort Conv_ALushort_ALalaw(ALalaw val)
Definition: alBuffer.c:1374
RefCount ref
Definition: alBuffer.h:88
GLsizei samples
Definition: gl2ext.h:970
ALsizei size
Definition: alMain.h:312
static __inline ALdouble Conv_ALdouble_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1488
const GLfloat * c
Definition: glew.h:14913
static __inline ALbyte Conv_ALbyte_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1279
ALuint BytesFromUserFmt(enum UserFmtType type)
Definition: alBuffer.c:2008
static __inline ALubyte Conv_ALubyte_ALshort(ALshort val)
Definition: alBuffer.c:1286
static __inline ALshort Conv_ALshort_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1343
static __inline ALuint Conv_ALuint_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1438
static __inline ALshort Conv_ALshort_ALalaw(ALalaw val)
Definition: alBuffer.c:1341
static __inline ALshort Conv_ALshort_ALuint(ALuint val)
Definition: alBuffer.c:1325
static __inline ALint Conv_ALint_ALushort(ALushort val)
Definition: alBuffer.c:1387
#define realloc
Definition: SDL_malloc.c:637
int ALenum
Definition: al.h:65
static __inline ALbyte Conv_ALbyte_ALbyte(ALbyte val)
Definition: alBuffer.c:1249
#define AL_FORMAT_MONO16
Definition: al.h:340
static __inline ALbyte3 Conv_ALbyte3_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1551
static __inline ALubyte Conv_ALubyte_ALuint(ALuint val)
Definition: alBuffer.c:1292
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
#define AL_QUAD_SOFT
Definition: alext.h:212
static __inline ALushort Conv_ALushort_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1372
ALenum NewThunkEntry(ALuint *index)
Definition: alThunk.c:47
GLuint index
Definition: glew.h:1800
#define AL_5POINT1_16_SOFT
Definition: alext.h:243
static __inline ALuint Conv_ALuint_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1442
#define AL_FORMAT_MONO8
Definition: al.h:339
void RWLockInit(RWLock *lock)
Definition: helpers.c:506
unsigned int ALuint
Definition: al.h:59
AL_API void AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
Definition: alBuffer.c:183
static __inline ALushort Conv_ALushort_ALdouble(ALdouble val)
Definition: alBuffer.c:1366
static __inline ALshort DecodeALaw(ALalaw val)
Definition: alBuffer.c:1059
static __inline ALfloat Conv_ALfloat_ALbyte(ALbyte val)
Definition: alBuffer.c:1447
static __inline ALubyte Conv_ALubyte_ALfloat(ALfloat val)
Definition: alBuffer.c:1294
AL_API void AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value)
Definition: alBuffer.c:891
#define AL_QUAD16_SOFT
Definition: alext.h:237
static __inline ALubyte Conv_ALubyte_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1306
#define AL_API
Definition: al.h:14
static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels chans, enum UserFmtType type, const ALvoid *data, ALboolean storesrc)
Definition: alBuffer.c:1939
static __inline ALushort Conv_ALushort_ALint(ALint val)
Definition: alBuffer.c:1356
static __inline ALint Conv_ALint_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1411
static __inline ALuint FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type)
Definition: alBuffer.h:63
#define AL_REAR16_SOFT
Definition: alext.h:240
#define AL_FORMAT_61CHN32
Definition: alext.h:111
AL_API void AL_APIENTRY alBufferi(ALuint buffer, ALenum param, ALint value)
Definition: alBuffer.c:694
static __inline ALint DecodeUByte3(ALubyte3 val)
Definition: alBuffer.c:1227
#define AL_MONO32F_SOFT
Definition: alext.h:232
GLint GLenum internalformat
Definition: gl2ext.h:845
static __inline ALdouble Conv_ALdouble_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1494
#define AL_BYTE_SOFT
Definition: alext.h:218
static __inline ALfloat Conv_ALfloat_ALdouble(ALdouble val)
Definition: alBuffer.c:1461
static __inline ALuint Conv_ALuint_ALalaw(ALalaw val)
Definition: alBuffer.c:1440
static __inline ALfloat Conv_ALfloat_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1463
static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans, enum UserFmtType *type)
Definition: alBuffer.c:2042
static __inline ALushort Conv_ALushort_ALubyte(ALubyte val)
Definition: alBuffer.c:1350
ALubyte ALalaw
Definition: alBuffer.c:1023
Definition: inftrees.h:24
#define AL_FORMAT_61CHN_MULAW
Definition: alext.h:124
static const int aLawClip
Definition: alBuffer.c:170
AL_API void AL_APIENTRY alBufferfv(ALuint buffer, ALenum param, const ALfloat *values)
Definition: alBuffer.c:668
static __inline ALuint Conv_ALuint_ALint(ALint val)
Definition: alBuffer.c:1422
#define AL_FORMAT_71CHN_MULAW
Definition: alext.h:125
AL_API void AL_APIENTRY alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3)
Definition: alBuffer.c:832
static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum FmtType *type)
Definition: alBuffer.c:2133
static __inline ALshort DecodeMuLaw(ALmulaw val)
Definition: alBuffer.c:1034
void ALCcontext_DecRef(ALCcontext *context)
Definition: ALc.c:1949
AL_API void AL_APIENTRY alBufferf(ALuint buffer, ALenum param, ALfloat value)
Definition: alBuffer.c:612
EGLSurface EGLint void ** value
Definition: eglext.h:301
static unsigned char nibble(char c)
Definition: SDL_joystick.c:797
static __inline ALubyte Conv_ALubyte_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1312
#define const
Definition: zconf.h:91
#define AL_FORMAT_51CHN_MULAW
Definition: alext.h:123
GLintptr offset
Definition: glew.h:1668
#define AL_FORMAT_71CHN32
Definition: alext.h:114
FmtChannels
Definition: alBuffer.h:51
#define AL_REAR32F_SOFT
Definition: alext.h:241
ALvoid ReleaseALBuffers(ALCdevice *device)
Definition: alBuffer.c:2228
static const int IMA4Codeword[16]
Definition: alBuffer.c:61
UserFmtChannels
Definition: alBuffer.h:26
#define memcpy
Definition: SDL_malloc.c:634
static __inline ALbyte Conv_ALbyte_ALushort(ALushort val)
Definition: alBuffer.c:1255
#define AL_FORMAT_QUAD8_LOKI
Definition: alext.h:63
static __inline ALbyte Conv_ALbyte_ALshort(ALshort val)
Definition: alBuffer.c:1253
#define AL_STEREO16_SOFT
Definition: alext.h:234
static __inline ALshort Conv_ALshort_ALubyte(ALubyte val)
Definition: alBuffer.c:1317
ALenum Format
Definition: alBuffer.h:74
static const int IMAStep_size[89]
Definition: alBuffer.c:48
#define AL_FORMAT_71CHN16
Definition: alext.h:113
#define AL_FORMAT_STEREO16
Definition: al.h:342
static __inline ALbyte Conv_ALbyte_ALint(ALint val)
Definition: alBuffer.c:1257
static __inline ALuint Conv_ALuint_ALushort(ALushort val)
Definition: alBuffer.c:1420
#define AL_FORMAT_MONO_FLOAT32
Definition: alext.h:69
#define AL_OUT_OF_MEMORY
Definition: al.h:379
static __inline ALuint Conv_ALuint_ALubyte3(ALubyte3 val)
Definition: alBuffer.c:1444
#define AL_MONO16_SOFT
Definition: alext.h:231
#define AL_FORMAT_51CHN8
Definition: alext.h:106
static __inline ALdouble Conv_ALdouble_ALubyte(ALubyte val)
Definition: alBuffer.c:1474
char ALboolean
Definition: al.h:38
#define AL_UNSIGNED_SHORT_SOFT
Definition: alext.h:221
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
#define AL_FORMAT_MONO_ALAW_EXT
Definition: alext.h:87
AL_API void AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *value)
Definition: alBuffer.c:796
static ALalaw EncodeALaw(ALshort val)
Definition: alBuffer.c:1062
#define AL_STEREO8_SOFT
Definition: alext.h:233
#define AL_BITS
Definition: al.h:347
#define AL_REAR8_SOFT
Definition: alext.h:239
static __inline ALushort Conv_ALushort_ALshort(ALshort val)
Definition: alBuffer.c:1352
static __inline ALdouble Conv_ALdouble_ALint(ALint val)
Definition: alBuffer.c:1480
#define AL_FORMAT_STEREO_DOUBLE_EXT
Definition: alext.h:76
static void Convert_ALima4_ALima4(ALima4 *dst, const ALima4 *src, ALuint numchans, ALuint numblocks)
Definition: alBuffer.c:1812
ALuint id
Definition: alBuffer.h:93
static __inline ALint mini(ALint a, ALint b)
Definition: alu.h:68
#define AL_7POINT1_16_SOFT
Definition: alext.h:249
static __inline ALshort Conv_ALshort_ALushort(ALushort val)
Definition: alBuffer.c:1321
ALCdevice * Device
Definition: alMain.h:704
static __inline ALshort Conv_ALshort_ALfloat(ALfloat val)
Definition: alBuffer.c:1327
#define AL_FORMAT_STEREO8
Definition: al.h:341
static const char muLawCompressTable[256]
Definition: alBuffer.c:112
static __inline ALdouble Conv_ALdouble_ALdouble(ALdouble val)
Definition: alBuffer.c:1486
static __inline ALubyte Conv_ALubyte_ALalaw(ALalaw val)
Definition: alBuffer.c:1308
static __inline ALfloat Conv_ALfloat_ALbyte3(ALbyte3 val)
Definition: alBuffer.c:1467
#define AL_INTERNAL_FORMAT_SOFT
Definition: alext.h:253
static __inline ALint Conv_ALint_ALuint(ALuint val)
Definition: alBuffer.c:1391
GLenum src
Definition: glew.h:2396
AL_API void AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
Definition: alBuffer.c:229
#define AL_FORMAT_QUAD_MULAW
Definition: alext.h:121
int i
Definition: pngrutil.c:1377
UserFmtType
Definition: alBuffer.h:11
#define AL_SEC_LENGTH_SOFT
Definition: alext.h:256
#define AL_7POINT1_32F_SOFT
Definition: alext.h:250
AL_API void AL_APIENTRY alBuffer3i(ALuint buffer, ALenum param, ALint value1, ALint value2, ALint value3)
Definition: alBuffer.c:721
ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value)
Definition: helpers.c:565
static ALboolean IsValidType(ALenum type)
Definition: alBuffer.c:2187
#define AL_FORMAT_REAR32
Definition: alext.h:105
#define AL_INVALID_ENUM
Definition: al.h:370
ALuint ChannelsFromUserFmt(enum UserFmtChannels chans)
Definition: alBuffer.c:2028
#define AL_FORMAT_REAR16
Definition: alext.h:104
AL_API void AL_APIENTRY alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1, ALint *value2, ALint *value3)
Definition: alBuffer.c:949
#define AL_FREQUENCY
Definition: al.h:345
ALsizei LoopEnd
Definition: alBuffer.h:85
#define AL_UNSIGNED_BYTE3_SOFT
Definition: alext.h:227
#define AL_NO_ERROR
Definition: al.h:364
ALuint ChannelsFromFmt(enum FmtChannels chans)
Definition: alBuffer.c:2119
#define AL_FORMAT_71CHN8
Definition: alext.h:112
#define AL_INVALID_OPERATION
Definition: al.h:376
void WriteLock(RWLock *lock)
Definition: helpers.c:531
#define AL_5POINT1_32F_SOFT
Definition: alext.h:244
ALsizei OriginalSize
Definition: alBuffer.h:82
#define AL_MONO_SOFT
Definition: alext.h:209
GLint GLsizei const GLuint64 * values
Definition: glew.h:3473
AL_API void AL_APIENTRY alBufferiv(ALuint buffer, ALenum param, const ALint *values)
Definition: alBuffer.c:750
LPALISBUFFERFORMATSUPPORTEDSOFT alIsBufferFormatSupportedSOFT
Definition: allatency.c:46
static __inline ALfloat Conv_ALfloat_ALint(ALint val)
Definition: alBuffer.c:1455
ALbyte ALubyte3_size_is_not_3[(sizeof(ALubyte3)==sizeof(ALubyte[3]))?1:-1]
#define COUNTOF(x)
Definition: alMain.h:63
static const ALshort aLawDecompressionTable[256]
Definition: alBuffer.c:134
static __inline ALshort Conv_ALshort_ALmulaw(ALmulaw val)
Definition: alBuffer.c:1339
AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer)
Definition: alBuffer.c:272
GLsizei size
Definition: gl2ext.h:1467