1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
|
/**
* OpenAL cross platform audio library
* Copyright (C) 1999-2007 by authors.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <limits.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#include "alMain.h"
#include "alu.h"
#include "alError.h"
#include "alBuffer.h"
#include "alThunk.h"
#include "sample_cvt.h"
extern inline struct ALbuffer *LookupBuffer(ALCdevice *device, ALuint id);
extern inline struct ALbuffer *RemoveBuffer(ALCdevice *device, ALuint id);
extern inline ALuint FrameSizeFromUserFmt(enum UserFmtChannels chans, enum UserFmtType type);
extern inline ALuint FrameSizeFromFmt(enum FmtChannels chans, enum FmtType type);
static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels chans, enum UserFmtType type, const ALvoid *data, ALsizei align, ALboolean storesrc);
static ALboolean IsValidType(ALenum type);
static ALboolean IsValidChannels(ALenum channels);
static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans, enum UserFmtType *type);
static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum FmtType *type);
static ALboolean SanitizeAlignment(enum UserFmtType type, ALsizei *align);
AL_API ALvoid AL_APIENTRY alGenBuffers(ALsizei n, ALuint *buffers)
{
ALCdevice *device;
ALCcontext *context;
ALsizei cur = 0;
ALenum err;
context = GetContextRef();
if(!context) return;
if(!(n >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
device = context->Device;
for(cur = 0;cur < n;cur++)
{
ALbuffer *buffer = calloc(1, sizeof(ALbuffer));
if(!buffer)
{
alDeleteBuffers(cur, buffers);
SET_ERROR_AND_GOTO(context, AL_OUT_OF_MEMORY, done);
}
RWLockInit(&buffer->lock);
err = NewThunkEntry(&buffer->id);
if(err == AL_NO_ERROR)
err = InsertUIntMapEntry(&device->BufferMap, buffer->id, buffer);
if(err != AL_NO_ERROR)
{
FreeThunkEntry(buffer->id);
memset(buffer, 0, sizeof(ALbuffer));
free(buffer);
alDeleteBuffers(cur, buffers);
SET_ERROR_AND_GOTO(context, err, done);
}
buffers[cur] = buffer->id;
}
done:
ALCcontext_DecRef(context);
}
AL_API ALvoid AL_APIENTRY alDeleteBuffers(ALsizei n, const ALuint *buffers)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *ALBuf;
ALsizei i;
context = GetContextRef();
if(!context) return;
if(!(n >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
device = context->Device;
for(i = 0;i < n;i++)
{
if(!buffers[i])
continue;
/* Check for valid Buffer ID */
if((ALBuf=LookupBuffer(device, buffers[i])) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(ALBuf->ref != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
}
for(i = 0;i < n;i++)
{
if((ALBuf=RemoveBuffer(device, buffers[i])) == NULL)
continue;
FreeThunkEntry(ALBuf->id);
free(ALBuf->data);
memset(ALBuf, 0, sizeof(*ALBuf));
free(ALBuf);
}
done:
ALCcontext_DecRef(context);
}
AL_API ALboolean AL_APIENTRY alIsBuffer(ALuint buffer)
{
ALCcontext *context;
ALboolean ret;
context = GetContextRef();
if(!context) return AL_FALSE;
ret = ((!buffer || LookupBuffer(context->Device, buffer)) ?
AL_TRUE : AL_FALSE);
ALCcontext_DecRef(context);
return ret;
}
AL_API ALvoid AL_APIENTRY alBufferData(ALuint buffer, ALenum format, const ALvoid *data, ALsizei size, ALsizei freq)
{
enum UserFmtChannels srcchannels;
enum UserFmtType srctype;
ALCdevice *device;
ALCcontext *context;
ALuint framesize;
ALenum newformat;
ALbuffer *albuf;
ALsizei align;
ALenum err;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(size >= 0 && freq > 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
align = albuf->UnpackAlign;
if(SanitizeAlignment(srctype, &align) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(srctype)
{
case UserFmtByte:
case UserFmtUByte:
case UserFmtShort:
case UserFmtUShort:
case UserFmtFloat:
framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
if((size%framesize) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
err = LoadData(albuf, freq, format, size/framesize*align,
srcchannels, srctype, data, align, AL_TRUE);
if(err != AL_NO_ERROR)
SET_ERROR_AND_GOTO(context, err, done);
break;
case UserFmtInt:
case UserFmtUInt:
case UserFmtByte3:
case UserFmtUByte3:
case UserFmtDouble:
framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
if((size%framesize) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
newformat = AL_FORMAT_MONO_FLOAT32;
switch(srcchannels)
{
case UserFmtMono: newformat = AL_FORMAT_MONO_FLOAT32; break;
case UserFmtStereo: newformat = AL_FORMAT_STEREO_FLOAT32; break;
case UserFmtRear: newformat = AL_FORMAT_REAR32; break;
case UserFmtQuad: newformat = AL_FORMAT_QUAD32; break;
case UserFmtX51: newformat = AL_FORMAT_51CHN32; break;
case UserFmtX61: newformat = AL_FORMAT_61CHN32; break;
case UserFmtX71: newformat = AL_FORMAT_71CHN32; break;
}
err = LoadData(albuf, freq, newformat, size/framesize*align,
srcchannels, srctype, data, align, AL_TRUE);
if(err != AL_NO_ERROR)
SET_ERROR_AND_GOTO(context, err, done);
break;
case UserFmtMulaw:
case UserFmtAlaw:
framesize = FrameSizeFromUserFmt(srcchannels, srctype) * align;
if((size%framesize) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
newformat = AL_FORMAT_MONO16;
switch(srcchannels)
{
case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
}
err = LoadData(albuf, freq, newformat, size/framesize*align,
srcchannels, srctype, data, align, AL_TRUE);
if(err != AL_NO_ERROR)
SET_ERROR_AND_GOTO(context, err, done);
break;
case UserFmtIMA4:
framesize = (align-1)/2 + 4;
framesize *= ChannelsFromUserFmt(srcchannels);
if((size%framesize) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
newformat = AL_FORMAT_MONO16;
switch(srcchannels)
{
case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
}
err = LoadData(albuf, freq, newformat, size/framesize*align,
srcchannels, srctype, data, align, AL_TRUE);
if(err != AL_NO_ERROR)
SET_ERROR_AND_GOTO(context, err, done);
break;
case UserFmtMSADPCM:
framesize = (align-2)/2 + 7;
framesize *= ChannelsFromUserFmt(srcchannels);
if((size%framesize) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
newformat = AL_FORMAT_MONO16;
switch(srcchannels)
{
case UserFmtMono: newformat = AL_FORMAT_MONO16; break;
case UserFmtStereo: newformat = AL_FORMAT_STEREO16; break;
case UserFmtRear: newformat = AL_FORMAT_REAR16; break;
case UserFmtQuad: newformat = AL_FORMAT_QUAD16; break;
case UserFmtX51: newformat = AL_FORMAT_51CHN16; break;
case UserFmtX61: newformat = AL_FORMAT_61CHN16; break;
case UserFmtX71: newformat = AL_FORMAT_71CHN16; break;
}
err = LoadData(albuf, freq, newformat, size/framesize*align,
srcchannels, srctype, data, align, AL_TRUE);
if(err != AL_NO_ERROR)
SET_ERROR_AND_GOTO(context, err, done);
break;
}
done:
ALCcontext_DecRef(context);
}
AL_API ALvoid AL_APIENTRY alBufferSubDataSOFT(ALuint buffer, ALenum format, const ALvoid *data, ALsizei offset, ALsizei length)
{
enum UserFmtChannels srcchannels;
enum UserFmtType srctype;
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
ALuint byte_align;
ALuint channels;
ALuint bytes;
ALsizei align;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(length >= 0 && offset >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(DecomposeUserFormat(format, &srcchannels, &srctype) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
WriteLock(&albuf->lock);
align = albuf->UnpackAlign;
if(SanitizeAlignment(srctype, &align) == AL_FALSE)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
if(srcchannels != albuf->OriginalChannels || srctype != albuf->OriginalType)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
if(align != albuf->OriginalAlign)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
if(albuf->OriginalType == UserFmtIMA4)
{
byte_align = (albuf->OriginalAlign-1)/2 + 4;
byte_align *= ChannelsFromUserFmt(albuf->OriginalChannels);
}
else if(albuf->OriginalType == UserFmtMSADPCM)
{
byte_align = (albuf->OriginalAlign-2)/2 + 7;
byte_align *= ChannelsFromUserFmt(albuf->OriginalChannels);
}
else
{
byte_align = albuf->OriginalAlign;
byte_align *= FrameSizeFromUserFmt(albuf->OriginalChannels,
albuf->OriginalType);
}
if(offset > albuf->OriginalSize || length > albuf->OriginalSize-offset ||
(offset%byte_align) != 0 || (length%byte_align) != 0)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
channels = ChannelsFromFmt(albuf->FmtChannels);
bytes = BytesFromFmt(albuf->FmtType);
/* offset -> byte offset, length -> sample count */
offset = offset/byte_align * channels*bytes;
length = length/byte_align * albuf->OriginalAlign;
ConvertData((char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
data, srctype, channels, length, align);
WriteUnlock(&albuf->lock);
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBufferSamplesSOFT(ALuint buffer,
ALuint samplerate, ALenum internalformat, ALsizei samples,
ALenum channels, ALenum type, const ALvoid *data)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
ALsizei align;
ALenum err;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(samples >= 0 && samplerate != 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(IsValidType(type) == AL_FALSE || IsValidChannels(channels) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
align = albuf->UnpackAlign;
if(SanitizeAlignment(type, &align) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if((samples%align) != 0)
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
err = LoadData(albuf, samplerate, internalformat, samples,
channels, type, data, align, AL_FALSE);
if(err != AL_NO_ERROR)
SET_ERROR_AND_GOTO(context, err, done);
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBufferSubSamplesSOFT(ALuint buffer,
ALsizei offset, ALsizei samples,
ALenum channels, ALenum type, const ALvoid *data)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
ALsizei align;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(samples >= 0 && offset >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(IsValidType(type) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
WriteLock(&albuf->lock);
align = albuf->UnpackAlign;
if(SanitizeAlignment(type, &align) == AL_FALSE)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
if(channels != (ALenum)albuf->FmtChannels)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
if((samples%align) != 0)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
/* offset -> byte offset */
offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType);
ConvertData((char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
data, type, ChannelsFromFmt(albuf->FmtChannels), samples, align);
WriteUnlock(&albuf->lock);
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alGetBufferSamplesSOFT(ALuint buffer,
ALsizei offset, ALsizei samples,
ALenum channels, ALenum type, ALvoid *data)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
ALsizei align;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(samples >= 0 && offset >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
if(IsValidType(type) == AL_FALSE)
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
ReadLock(&albuf->lock);
align = albuf->PackAlign;
if(SanitizeAlignment(type, &align) == AL_FALSE)
{
ReadUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
if(channels != (ALenum)albuf->FmtChannels)
{
ReadUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
if(offset > albuf->SampleLen || samples > albuf->SampleLen-offset)
{
ReadUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
if((samples%align) != 0)
{
ReadUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
/* offset -> byte offset */
offset *= FrameSizeFromFmt(albuf->FmtChannels, albuf->FmtType);
ConvertData(data, type, (char*)albuf->data+offset, (enum UserFmtType)albuf->FmtType,
ChannelsFromFmt(albuf->FmtChannels), samples, align);
ReadUnlock(&albuf->lock);
done:
ALCcontext_DecRef(context);
}
AL_API ALboolean AL_APIENTRY alIsBufferFormatSupportedSOFT(ALenum format)
{
enum FmtChannels dstchannels;
enum FmtType dsttype;
ALCcontext *context;
ALboolean ret;
context = GetContextRef();
if(!context) return AL_FALSE;
ret = DecomposeFormat(format, &dstchannels, &dsttype);
ALCcontext_DecRef(context);
return ret;
}
AL_API void AL_APIENTRY alBufferf(ALuint buffer, ALenum param, ALfloat UNUSED(value))
{
ALCdevice *device;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBuffer3f(ALuint buffer, ALenum param, ALfloat UNUSED(value1), ALfloat UNUSED(value2), ALfloat UNUSED(value3))
{
ALCdevice *device;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBufferfv(ALuint buffer, ALenum param, const ALfloat *values)
{
ALCdevice *device;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(values))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBufferi(ALuint buffer, ALenum param, ALint value)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
switch(param)
{
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
if(!(value >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
ExchangeInt(&albuf->UnpackAlign, value);
break;
case AL_PACK_BLOCK_ALIGNMENT_SOFT:
if(!(value >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
ExchangeInt(&albuf->PackAlign, value);
break;
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBuffer3i(ALuint buffer, ALenum param, ALint UNUSED(value1), ALint UNUSED(value2), ALint UNUSED(value3))
{
ALCdevice *device;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alBufferiv(ALuint buffer, ALenum param, const ALint *values)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
if(values)
{
switch(param)
{
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
case AL_PACK_BLOCK_ALIGNMENT_SOFT:
alBufferi(buffer, param, values[0]);
return;
}
}
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(values))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
case AL_LOOP_POINTS_SOFT:
WriteLock(&albuf->lock);
if(albuf->ref != 0)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_OPERATION, done);
}
if(values[0] >= values[1] || values[0] < 0 ||
values[1] > albuf->SampleLen)
{
WriteUnlock(&albuf->lock);
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
}
albuf->LoopStart = values[0];
albuf->LoopEnd = values[1];
WriteUnlock(&albuf->lock);
break;
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API ALvoid AL_APIENTRY alGetBufferf(ALuint buffer, ALenum param, ALfloat *value)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(value))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
case AL_SEC_LENGTH_SOFT:
ReadLock(&albuf->lock);
if(albuf->SampleLen != 0)
*value = albuf->SampleLen / (ALfloat)albuf->Frequency;
else
*value = 0.0f;
ReadUnlock(&albuf->lock);
break;
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alGetBuffer3f(ALuint buffer, ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3)
{
ALCdevice *device;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(value1 && value2 && value3))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alGetBufferfv(ALuint buffer, ALenum param, ALfloat *values)
{
ALCdevice *device;
ALCcontext *context;
switch(param)
{
case AL_SEC_LENGTH_SOFT:
alGetBufferf(buffer, param, values);
return;
}
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(values))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API ALvoid AL_APIENTRY alGetBufferi(ALuint buffer, ALenum param, ALint *value)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(value))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
case AL_FREQUENCY:
*value = albuf->Frequency;
break;
case AL_BITS:
*value = BytesFromFmt(albuf->FmtType) * 8;
break;
case AL_CHANNELS:
*value = ChannelsFromFmt(albuf->FmtChannels);
break;
case AL_SIZE:
ReadLock(&albuf->lock);
*value = albuf->SampleLen * FrameSizeFromFmt(albuf->FmtChannels,
albuf->FmtType);
ReadUnlock(&albuf->lock);
break;
case AL_INTERNAL_FORMAT_SOFT:
*value = albuf->Format;
break;
case AL_BYTE_LENGTH_SOFT:
*value = albuf->OriginalSize;
break;
case AL_SAMPLE_LENGTH_SOFT:
*value = albuf->SampleLen;
break;
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
*value = albuf->UnpackAlign;
break;
case AL_PACK_BLOCK_ALIGNMENT_SOFT:
*value = albuf->PackAlign;
break;
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alGetBuffer3i(ALuint buffer, ALenum param, ALint *value1, ALint *value2, ALint *value3)
{
ALCdevice *device;
ALCcontext *context;
context = GetContextRef();
if(!context) return;
device = context->Device;
if(LookupBuffer(device, buffer) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(value1 && value2 && value3))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
AL_API void AL_APIENTRY alGetBufferiv(ALuint buffer, ALenum param, ALint *values)
{
ALCdevice *device;
ALCcontext *context;
ALbuffer *albuf;
switch(param)
{
case AL_FREQUENCY:
case AL_BITS:
case AL_CHANNELS:
case AL_SIZE:
case AL_INTERNAL_FORMAT_SOFT:
case AL_BYTE_LENGTH_SOFT:
case AL_SAMPLE_LENGTH_SOFT:
case AL_UNPACK_BLOCK_ALIGNMENT_SOFT:
case AL_PACK_BLOCK_ALIGNMENT_SOFT:
alGetBufferi(buffer, param, values);
return;
}
context = GetContextRef();
if(!context) return;
device = context->Device;
if((albuf=LookupBuffer(device, buffer)) == NULL)
SET_ERROR_AND_GOTO(context, AL_INVALID_NAME, done);
if(!(values))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
switch(param)
{
case AL_LOOP_POINTS_SOFT:
ReadLock(&albuf->lock);
values[0] = albuf->LoopStart;
values[1] = albuf->LoopEnd;
ReadUnlock(&albuf->lock);
break;
default:
SET_ERROR_AND_GOTO(context, AL_INVALID_ENUM, done);
}
done:
ALCcontext_DecRef(context);
}
/*
* LoadData
*
* Loads the specified data into the buffer, using the specified formats.
* Currently, the new format must have the same channel configuration as the
* original format.
*/
static ALenum LoadData(ALbuffer *ALBuf, ALuint freq, ALenum NewFormat, ALsizei frames, enum UserFmtChannels SrcChannels, enum UserFmtType SrcType, const ALvoid *data, ALsizei align, ALboolean storesrc)
{
ALuint NewChannels, NewBytes;
enum FmtChannels DstChannels;
enum FmtType DstType;
ALuint64 newsize;
ALvoid *temp;
if(DecomposeFormat(NewFormat, &DstChannels, &DstType) == AL_FALSE ||
(long)SrcChannels != (long)DstChannels)
return AL_INVALID_ENUM;
NewChannels = ChannelsFromFmt(DstChannels);
NewBytes = BytesFromFmt(DstType);
newsize = frames;
newsize *= NewBytes;
newsize *= NewChannels;
if(newsize > INT_MAX)
return AL_OUT_OF_MEMORY;
WriteLock(&ALBuf->lock);
if(ALBuf->ref != 0)
{
WriteUnlock(&ALBuf->lock);
return AL_INVALID_OPERATION;
}
temp = realloc(ALBuf->data, (size_t)newsize);
if(!temp && newsize)
{
WriteUnlock(&ALBuf->lock);
return AL_OUT_OF_MEMORY;
}
ALBuf->data = temp;
if(data != NULL)
ConvertData(ALBuf->data, (enum UserFmtType)DstType, data, SrcType, NewChannels, frames, align);
if(storesrc)
{
ALBuf->OriginalChannels = SrcChannels;
ALBuf->OriginalType = SrcType;
if(SrcType == UserFmtIMA4)
{
ALsizei byte_align = ((align-1)/2 + 4) * ChannelsFromUserFmt(SrcChannels);
ALBuf->OriginalSize = frames / align * byte_align;
ALBuf->OriginalAlign = align;
}
else if(SrcType == UserFmtMSADPCM)
{
ALsizei byte_align = ((align-2)/2 + 7) * ChannelsFromUserFmt(SrcChannels);
ALBuf->OriginalSize = frames / align * byte_align;
ALBuf->OriginalAlign = align;
}
else
{
ALBuf->OriginalSize = frames * FrameSizeFromUserFmt(SrcChannels, SrcType);
ALBuf->OriginalAlign = 1;
}
}
else
{
ALBuf->OriginalChannels = (enum UserFmtChannels)DstChannels;
ALBuf->OriginalType = (enum UserFmtType)DstType;
ALBuf->OriginalSize = frames * NewBytes * NewChannels;
ALBuf->OriginalAlign = 1;
}
ALBuf->Frequency = freq;
ALBuf->FmtChannels = DstChannels;
ALBuf->FmtType = DstType;
ALBuf->Format = NewFormat;
ALBuf->SampleLen = frames;
ALBuf->LoopStart = 0;
ALBuf->LoopEnd = ALBuf->SampleLen;
WriteUnlock(&ALBuf->lock);
return AL_NO_ERROR;
}
ALuint BytesFromUserFmt(enum UserFmtType type)
{
switch(type)
{
case UserFmtByte: return sizeof(ALbyte);
case UserFmtUByte: return sizeof(ALubyte);
case UserFmtShort: return sizeof(ALshort);
case UserFmtUShort: return sizeof(ALushort);
case UserFmtInt: return sizeof(ALint);
case UserFmtUInt: return sizeof(ALuint);
case UserFmtFloat: return sizeof(ALfloat);
case UserFmtDouble: return sizeof(ALdouble);
case UserFmtByte3: return sizeof(ALbyte[3]);
case UserFmtUByte3: return sizeof(ALubyte[3]);
case UserFmtMulaw: return sizeof(ALubyte);
case UserFmtAlaw: return sizeof(ALubyte);
case UserFmtIMA4: break; /* not handled here */
case UserFmtMSADPCM: break; /* not handled here */
}
return 0;
}
ALuint ChannelsFromUserFmt(enum UserFmtChannels chans)
{
switch(chans)
{
case UserFmtMono: return 1;
case UserFmtStereo: return 2;
case UserFmtRear: return 2;
case UserFmtQuad: return 4;
case UserFmtX51: return 6;
case UserFmtX61: return 7;
case UserFmtX71: return 8;
}
return 0;
}
static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans,
enum UserFmtType *type)
{
static const struct {
ALenum format;
enum UserFmtChannels channels;
enum UserFmtType type;
} list[] = {
{ AL_FORMAT_MONO8, UserFmtMono, UserFmtUByte },
{ AL_FORMAT_MONO16, UserFmtMono, UserFmtShort },
{ AL_FORMAT_MONO_FLOAT32, UserFmtMono, UserFmtFloat },
{ AL_FORMAT_MONO_DOUBLE_EXT, UserFmtMono, UserFmtDouble },
{ AL_FORMAT_MONO_IMA4, UserFmtMono, UserFmtIMA4 },
{ AL_FORMAT_MONO_MSADPCM_SOFT, UserFmtMono, UserFmtMSADPCM },
{ AL_FORMAT_MONO_MULAW, UserFmtMono, UserFmtMulaw },
{ AL_FORMAT_MONO_ALAW_EXT, UserFmtMono, UserFmtAlaw },
{ AL_FORMAT_STEREO8, UserFmtStereo, UserFmtUByte },
{ AL_FORMAT_STEREO16, UserFmtStereo, UserFmtShort },
{ AL_FORMAT_STEREO_FLOAT32, UserFmtStereo, UserFmtFloat },
{ AL_FORMAT_STEREO_DOUBLE_EXT, UserFmtStereo, UserFmtDouble },
{ AL_FORMAT_STEREO_IMA4, UserFmtStereo, UserFmtIMA4 },
{ AL_FORMAT_STEREO_MSADPCM_SOFT, UserFmtStereo, UserFmtMSADPCM },
{ AL_FORMAT_STEREO_MULAW, UserFmtStereo, UserFmtMulaw },
{ AL_FORMAT_STEREO_ALAW_EXT, UserFmtStereo, UserFmtAlaw },
{ AL_FORMAT_REAR8, UserFmtRear, UserFmtUByte },
{ AL_FORMAT_REAR16, UserFmtRear, UserFmtShort },
{ AL_FORMAT_REAR32, UserFmtRear, UserFmtFloat },
{ AL_FORMAT_REAR_MULAW, UserFmtRear, UserFmtMulaw },
{ AL_FORMAT_QUAD8_LOKI, UserFmtQuad, UserFmtUByte },
{ AL_FORMAT_QUAD16_LOKI, UserFmtQuad, UserFmtShort },
{ AL_FORMAT_QUAD8, UserFmtQuad, UserFmtUByte },
{ AL_FORMAT_QUAD16, UserFmtQuad, UserFmtShort },
{ AL_FORMAT_QUAD32, UserFmtQuad, UserFmtFloat },
{ AL_FORMAT_QUAD_MULAW, UserFmtQuad, UserFmtMulaw },
{ AL_FORMAT_51CHN8, UserFmtX51, UserFmtUByte },
{ AL_FORMAT_51CHN16, UserFmtX51, UserFmtShort },
{ AL_FORMAT_51CHN32, UserFmtX51, UserFmtFloat },
{ AL_FORMAT_51CHN_MULAW, UserFmtX51, UserFmtMulaw },
{ AL_FORMAT_61CHN8, UserFmtX61, UserFmtUByte },
{ AL_FORMAT_61CHN16, UserFmtX61, UserFmtShort },
{ AL_FORMAT_61CHN32, UserFmtX61, UserFmtFloat },
{ AL_FORMAT_61CHN_MULAW, UserFmtX61, UserFmtMulaw },
{ AL_FORMAT_71CHN8, UserFmtX71, UserFmtUByte },
{ AL_FORMAT_71CHN16, UserFmtX71, UserFmtShort },
{ AL_FORMAT_71CHN32, UserFmtX71, UserFmtFloat },
{ AL_FORMAT_71CHN_MULAW, UserFmtX71, UserFmtMulaw },
};
ALuint i;
for(i = 0;i < COUNTOF(list);i++)
{
if(list[i].format == format)
{
*chans = list[i].channels;
*type = list[i].type;
return AL_TRUE;
}
}
return AL_FALSE;
}
ALuint BytesFromFmt(enum FmtType type)
{
switch(type)
{
case FmtByte: return sizeof(ALbyte);
case FmtShort: return sizeof(ALshort);
case FmtFloat: return sizeof(ALfloat);
}
return 0;
}
ALuint ChannelsFromFmt(enum FmtChannels chans)
{
switch(chans)
{
case FmtMono: return 1;
case FmtStereo: return 2;
case FmtRear: return 2;
case FmtQuad: return 4;
case FmtX51: return 6;
case FmtX61: return 7;
case FmtX71: return 8;
}
return 0;
}
static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum FmtType *type)
{
static const struct {
ALenum format;
enum FmtChannels channels;
enum FmtType type;
} list[] = {
{ AL_MONO8_SOFT, FmtMono, FmtByte },
{ AL_MONO16_SOFT, FmtMono, FmtShort },
{ AL_MONO32F_SOFT, FmtMono, FmtFloat },
{ AL_STEREO8_SOFT, FmtStereo, FmtByte },
{ AL_STEREO16_SOFT, FmtStereo, FmtShort },
{ AL_STEREO32F_SOFT, FmtStereo, FmtFloat },
{ AL_REAR8_SOFT, FmtRear, FmtByte },
{ AL_REAR16_SOFT, FmtRear, FmtShort },
{ AL_REAR32F_SOFT, FmtRear, FmtFloat },
{ AL_FORMAT_QUAD8_LOKI, FmtQuad, FmtByte },
{ AL_FORMAT_QUAD16_LOKI, FmtQuad, FmtShort },
{ AL_QUAD8_SOFT, FmtQuad, FmtByte },
{ AL_QUAD16_SOFT, FmtQuad, FmtShort },
{ AL_QUAD32F_SOFT, FmtQuad, FmtFloat },
{ AL_5POINT1_8_SOFT, FmtX51, FmtByte },
{ AL_5POINT1_16_SOFT, FmtX51, FmtShort },
{ AL_5POINT1_32F_SOFT, FmtX51, FmtFloat },
{ AL_6POINT1_8_SOFT, FmtX61, FmtByte },
{ AL_6POINT1_16_SOFT, FmtX61, FmtShort },
{ AL_6POINT1_32F_SOFT, FmtX61, FmtFloat },
{ AL_7POINT1_8_SOFT, FmtX71, FmtByte },
{ AL_7POINT1_16_SOFT, FmtX71, FmtShort },
{ AL_7POINT1_32F_SOFT, FmtX71, FmtFloat },
};
ALuint i;
for(i = 0;i < COUNTOF(list);i++)
{
if(list[i].format == format)
{
*chans = list[i].channels;
*type = list[i].type;
return AL_TRUE;
}
}
return AL_FALSE;
}
static ALboolean SanitizeAlignment(enum UserFmtType type, ALsizei *align)
{
if(*align < 0)
return AL_FALSE;
if(*align == 0)
{
if(type == UserFmtIMA4)
{
/* Here is where things vary:
* nVidia and Apple use 64+1 sample frames per block -> block_size=36 bytes per channel
* Most PC sound software uses 2040+1 sample frames per block -> block_size=1024 bytes per channel
*/
*align = 65;
}
else if(type == UserFmtMSADPCM)
*align = 64;
else
*align = 1;
return AL_TRUE;
}
if(type == UserFmtIMA4)
{
/* IMA4 block alignment must be a multiple of 8, plus 1. */
return ((*align)&7) == 1;
}
if(type == UserFmtMSADPCM)
{
/* MSADPCM block alignment must be a multiple of 2. */
/* FIXME: Too strict? Might only require align*channels to be a
* multiple of 2. */
return ((*align)&1) == 0;
}
return AL_TRUE;
}
static ALboolean IsValidType(ALenum type)
{
switch(type)
{
case AL_BYTE_SOFT:
case AL_UNSIGNED_BYTE_SOFT:
case AL_SHORT_SOFT:
case AL_UNSIGNED_SHORT_SOFT:
case AL_INT_SOFT:
case AL_UNSIGNED_INT_SOFT:
case AL_FLOAT_SOFT:
case AL_DOUBLE_SOFT:
case AL_BYTE3_SOFT:
case AL_UNSIGNED_BYTE3_SOFT:
return AL_TRUE;
}
return AL_FALSE;
}
static ALboolean IsValidChannels(ALenum channels)
{
switch(channels)
{
case AL_MONO_SOFT:
case AL_STEREO_SOFT:
case AL_REAR_SOFT:
case AL_QUAD_SOFT:
case AL_5POINT1_SOFT:
case AL_6POINT1_SOFT:
case AL_7POINT1_SOFT:
return AL_TRUE;
}
return AL_FALSE;
}
/*
* ReleaseALBuffers()
*
* INTERNAL: Called to destroy any buffers that still exist on the device
*/
ALvoid ReleaseALBuffers(ALCdevice *device)
{
ALsizei i;
for(i = 0;i < device->BufferMap.size;i++)
{
ALbuffer *temp = device->BufferMap.array[i].value;
device->BufferMap.array[i].value = NULL;
free(temp->data);
FreeThunkEntry(temp->id);
memset(temp, 0, sizeof(ALbuffer));
free(temp);
}
}
|