FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Modules/almodule.c at 2.7 · python-emscripten/cpython · GitHub
python-emscripten
cpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Modules
/
almodule.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
3232 lines (2904 loc) · 90 KB
Breadcrumbs
cpython
/
Modules
/
almodule.c
Copy path
File metadata and controls
3232 lines (2904 loc) · 90 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#define
OLD_INTERFACE
/* define for pre-Irix 6 interface */
#include
"Python.h"
#include
"stringobject.h"
#include
<audio.h>
#include
<stdarg.h>
#ifndef
AL_NO_ELEM
#ifndef
OLD_INTERFACE
#define
OLD_INTERFACE
#endif
/* OLD_INTERFACE */
#endif
/* AL_NO_ELEM */
static
PyObject
*
ErrorObject
;
/* ----------------------------------------------------- */
/* Declarations for objects of type port */
typedef
struct
{
PyObject_HEAD
/* XXXX Add your own stuff here */
ALport
port
;
}
alpobject
;
static
PyTypeObject
Alptype
;
/* ---------------------------------------------------------------- */
/* Declarations for objects of type config */
typedef
struct
{
PyObject_HEAD
/* XXXX Add your own stuff here */
ALconfig
config
;
}
alcobject
;
static
PyTypeObject
Alctype
;
static
void
ErrorHandler
(
long
code
,
const
char
*
fmt
, ...)
{
va_list
args
;
char
buf
[
128
];
va_start
(
args
,
fmt
);
vsprintf
(
buf
,
fmt
,
args
);
va_end
(
args
);
PyErr_SetString
(
ErrorObject
,
buf
);
}
#ifdef
AL_NO_ELEM
/* IRIX 6 */
static
PyObject
*
param2python
(
int
resource
,
int
param
,
ALvalue
value
,
ALparamInfo
*
pinfo
)
{
ALparamInfo
info
;
if
(
pinfo
==
NULL
) {
pinfo
=
&
info
;
if
(
alGetParamInfo
(
resource
,
param
,
&
info
)
<
0
)
return
NULL
;
}
switch
(
pinfo
->
elementType
) {
case
AL_PTR_ELEM
:
/* XXXX don't know how to handle this */
case
AL_NO_ELEM
:
Py_INCREF
(
Py_None
);
return
Py_None
;
case
AL_INT32_ELEM
:
case
AL_RESOURCE_ELEM
:
case
AL_ENUM_ELEM
:
return
PyInt_FromLong
((
long
)
value
.
i
);
case
AL_INT64_ELEM
:
return
PyLong_FromLongLong
(
value
.
ll
);
case
AL_FIXED_ELEM
:
return
PyFloat_FromDouble
(
alFixedToDouble
(
value
.
ll
));
case
AL_CHAR_ELEM
:
if
(
value
.
ptr
==
NULL
) {
Py_INCREF
(
Py_None
);
return
Py_None
;
}
return
PyString_FromString
((
char
*
)
value
.
ptr
);
default
:
PyErr_SetString
(
ErrorObject
,
"unknown element type"
);
return
NULL
;
}
}
static
int
python2elem
(
PyObject
*
item
,
void
*
ptr
,
int
elementType
)
{
switch
(
elementType
) {
case
AL_INT32_ELEM
:
case
AL_RESOURCE_ELEM
:
case
AL_ENUM_ELEM
:
if
(!
PyInt_Check
(
item
)) {
PyErr_BadArgument
();
return
-1
;
}
*
((
int
*
)
ptr
)
=
PyInt_AsLong
(
item
);
break
;
case
AL_INT64_ELEM
:
if
(
PyInt_Check
(
item
))
*
((
long long
*
)
ptr
)
=
PyInt_AsLong
(
item
);
else
if
(
PyLong_Check
(
item
))
*
((
long long
*
)
ptr
)
=
PyLong_AsLongLong
(
item
);
else
{
PyErr_BadArgument
();
return
-1
;
}
break
;
case
AL_FIXED_ELEM
:
if
(
PyInt_Check
(
item
))
*
((
long long
*
)
ptr
)
=
alDoubleToFixed
((
double
)
PyInt_AsLong
(
item
));
else
if
(
PyFloat_Check
(
item
))
*
((
long long
*
)
ptr
)
=
alDoubleToFixed
(
PyFloat_AsDouble
(
item
));
else
{
PyErr_BadArgument
();
return
-1
;
}
break
;
default
:
PyErr_SetString
(
ErrorObject
,
"unknown element type"
);
return
-1
;
}
return
0
;
}
static
int
python2param
(
int
resource
,
ALpv
*
param
,
PyObject
*
value
,
ALparamInfo
*
pinfo
)
{
ALparamInfo
info
;
int
i
,
stepsize
;
PyObject
*
item
;
if
(
pinfo
==
NULL
) {
pinfo
=
&
info
;
if
(
alGetParamInfo
(
resource
,
param
->
param
,
&
info
)
<
0
)
return
-1
;
}
switch
(
pinfo
->
valueType
) {
case
AL_STRING_VAL
:
if
(
pinfo
->
elementType
!=
AL_CHAR_ELEM
) {
PyErr_SetString
(
ErrorObject
,
"unknown element type"
);
return
-1
;
}
if
(!
PyString_Check
(
value
)) {
PyErr_BadArgument
();
return
-1
;
}
param
->
value
.
ptr
=
PyString_AS_STRING
(
value
);
param
->
sizeIn
=
PyString_GET_SIZE
(
value
)
+
1
;
/*account for NUL*/
break
;
case
AL_SET_VAL
:
case
AL_VECTOR_VAL
:
if
(!
PyList_Check
(
value
)
&&
!
PyTuple_Check
(
value
)) {
PyErr_BadArgument
();
return
-1
;
}
switch
(
pinfo
->
elementType
) {
case
AL_INT32_ELEM
:
case
AL_RESOURCE_ELEM
:
case
AL_ENUM_ELEM
:
param
->
sizeIn
=
PySequence_Size
(
value
);
param
->
value
.
ptr
=
PyMem_NEW
(
int
,
param
->
sizeIn
);
stepsize
=
sizeof
(
int
);
break
;
case
AL_INT64_ELEM
:
case
AL_FIXED_ELEM
:
param
->
sizeIn
=
PySequence_Size
(
value
);
param
->
value
.
ptr
=
PyMem_NEW
(
long
long
,
param
->
sizeIn
);
stepsize
=
sizeof
(
long long
);
break
;
}
for
(
i
=
0
;
i
<
param
->
sizeIn
;
i
++
) {
item
=
PySequence_GetItem
(
value
,
i
);
if
(
python2elem
(
item
, (
void
*
) ((
char
*
)
param
->
value
.
ptr
+
i
*
stepsize
),
pinfo
->
elementType
)
<
0
) {
PyMem_DEL
(
param
->
value
.
ptr
);
return
-1
;
}
}
break
;
case
AL_SCALAR_VAL
:
switch
(
pinfo
->
elementType
) {
case
AL_INT32_ELEM
:
case
AL_RESOURCE_ELEM
:
case
AL_ENUM_ELEM
:
return
python2elem
(
value
, (
void
*
)
&
param
->
value
.
i
,
pinfo
->
elementType
);
case
AL_INT64_ELEM
:
case
AL_FIXED_ELEM
:
return
python2elem
(
value
, (
void
*
)
&
param
->
value
.
ll
,
pinfo
->
elementType
);
default
:
PyErr_SetString
(
ErrorObject
,
"unknown element type"
);
return
-1
;
}
}
return
0
;
}
static
int
python2params
(
int
resource1
,
int
resource2
,
PyObject
*
list
,
ALpv
*
*
pvsp
,
ALparamInfo
*
*
pinfop
)
{
PyObject
*
item
;
ALpv
*
pvs
;
ALparamInfo
*
pinfo
;
int
npvs
,
i
;
npvs
=
PyList_Size
(
list
);
pvs
=
PyMem_NEW
(
ALpv
,
npvs
);
pinfo
=
PyMem_NEW
(
ALparamInfo
,
npvs
);
for
(
i
=
0
;
i
<
npvs
;
i
++
) {
item
=
PyList_GetItem
(
list
,
i
);
if
(!
PyArg_ParseTuple
(
item
,
"iO"
,
&
pvs
[
i
].
param
,
&
item
))
goto
error
;
if
(
alGetParamInfo
(
resource1
,
pvs
[
i
].
param
,
&
pinfo
[
i
])
<
0
&&
alGetParamInfo
(
resource2
,
pvs
[
i
].
param
,
&
pinfo
[
i
])
<
0
)
goto
error
;
if
(
python2param
(
resource1
,
&
pvs
[
i
],
item
,
&
pinfo
[
i
])
<
0
)
goto
error
;
}
*
pvsp
=
pvs
;
*
pinfop
=
pinfo
;
return
npvs
;
error
:
/* XXXX we should clean up everything */
if
(
pvs
)
PyMem_DEL
(
pvs
);
if
(
pinfo
)
PyMem_DEL
(
pinfo
);
return
-1
;
}
/* -------------------------------------------------------- */
static
PyObject
*
SetConfig
(
alcobject
*
self
,
PyObject
*
args
,
int
(
*
func
)(
ALconfig
,
int
))
{
int
par
;
if
(!
PyArg_ParseTuple
(
args
,
"i:SetConfig"
,
&
par
))
return
NULL
;
if
((
*
func
)(
self
->
config
,
par
)
==
-1
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
GetConfig
(
alcobject
*
self
,
PyObject
*
args
,
int
(
*
func
)(
ALconfig
))
{
int
par
;
if
(!
PyArg_ParseTuple
(
args
,
":GetConfig"
))
return
NULL
;
if
((
par
=
(
*
func
)(
self
->
config
))
==
-1
)
return
NULL
;
return
PyInt_FromLong
((
long
)
par
);
}
PyDoc_STRVAR
(
alc_SetWidth__doc__
,
"alSetWidth: set the wordsize for integer audio data."
);
static
PyObject
*
alc_SetWidth
(
alcobject
*
self
,
PyObject
*
args
)
{
return
SetConfig
(
self
,
args
,
alSetWidth
);
}
PyDoc_STRVAR
(
alc_GetWidth__doc__
,
"alGetWidth: get the wordsize for integer audio data."
);
static
PyObject
*
alc_GetWidth
(
alcobject
*
self
,
PyObject
*
args
)
{
return
GetConfig
(
self
,
args
,
alGetWidth
);
}
PyDoc_STRVAR
(
alc_SetSampFmt__doc__
,
"alSetSampFmt: set the sample format setting in an audio ALconfig "
"structure."
);
static
PyObject
*
alc_SetSampFmt
(
alcobject
*
self
,
PyObject
*
args
)
{
return
SetConfig
(
self
,
args
,
alSetSampFmt
);
}
PyDoc_STRVAR
(
alc_GetSampFmt__doc__
,
"alGetSampFmt: get the sample format setting in an audio ALconfig "
"structure."
);
static
PyObject
*
alc_GetSampFmt
(
alcobject
*
self
,
PyObject
*
args
)
{
return
GetConfig
(
self
,
args
,
alGetSampFmt
);
}
PyDoc_STRVAR
(
alc_SetChannels__doc__
,
"alSetChannels: set the channel settings in an audio ALconfig."
);
static
PyObject
*
alc_SetChannels
(
alcobject
*
self
,
PyObject
*
args
)
{
return
SetConfig
(
self
,
args
,
alSetChannels
);
}
PyDoc_STRVAR
(
alc_GetChannels__doc__
,
"alGetChannels: get the channel settings in an audio ALconfig."
);
static
PyObject
*
alc_GetChannels
(
alcobject
*
self
,
PyObject
*
args
)
{
return
GetConfig
(
self
,
args
,
alGetChannels
);
}
PyDoc_STRVAR
(
alc_SetFloatMax__doc__
,
"alSetFloatMax: set the maximum value of floating point sample data."
);
static
PyObject
*
alc_SetFloatMax
(
alcobject
*
self
,
PyObject
*
args
)
{
double
maximum_value
;
if
(!
PyArg_ParseTuple
(
args
,
"d:SetFloatMax"
,
&
maximum_value
))
return
NULL
;
if
(
alSetFloatMax
(
self
->
config
,
maximum_value
)
<
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyDoc_STRVAR
(
alc_GetFloatMax__doc__
,
"alGetFloatMax: get the maximum value of floating point sample data."
);
static
PyObject
*
alc_GetFloatMax
(
alcobject
*
self
,
PyObject
*
args
)
{
double
maximum_value
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFloatMax"
))
return
NULL
;
if
((
maximum_value
=
alGetFloatMax
(
self
->
config
))
==
0
)
return
NULL
;
return
PyFloat_FromDouble
(
maximum_value
);
}
PyDoc_STRVAR
(
alc_SetDevice__doc__
,
"alSetDevice: set the device setting in an audio ALconfig structure."
);
static
PyObject
*
alc_SetDevice
(
alcobject
*
self
,
PyObject
*
args
)
{
return
SetConfig
(
self
,
args
,
alSetDevice
);
}
PyDoc_STRVAR
(
alc_GetDevice__doc__
,
"alGetDevice: get the device setting in an audio ALconfig structure."
);
static
PyObject
*
alc_GetDevice
(
alcobject
*
self
,
PyObject
*
args
)
{
return
GetConfig
(
self
,
args
,
alGetDevice
);
}
PyDoc_STRVAR
(
alc_SetQueueSize__doc__
,
"alSetQueueSize: set audio port buffer size."
);
static
PyObject
*
alc_SetQueueSize
(
alcobject
*
self
,
PyObject
*
args
)
{
return
SetConfig
(
self
,
args
,
alSetQueueSize
);
}
PyDoc_STRVAR
(
alc_GetQueueSize__doc__
,
"alGetQueueSize: get audio port buffer size."
);
static
PyObject
*
alc_GetQueueSize
(
alcobject
*
self
,
PyObject
*
args
)
{
return
GetConfig
(
self
,
args
,
alGetQueueSize
);
}
#endif
/* AL_NO_ELEM */
static
PyObject
*
setconfig
(
alcobject
*
self
,
PyObject
*
args
,
int
(
*
func
)(
ALconfig
,
long
))
{
long
par
;
if
(!
PyArg_ParseTuple
(
args
,
"l:SetConfig"
,
&
par
))
return
NULL
;
if
((
*
func
)(
self
->
config
,
par
)
==
-1
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
getconfig
(
alcobject
*
self
,
PyObject
*
args
,
long
(
*
func
)(
ALconfig
))
{
long
par
;
if
(!
PyArg_ParseTuple
(
args
,
":GetConfig"
))
return
NULL
;
if
((
par
=
(
*
func
)(
self
->
config
))
==
-1
)
return
NULL
;
return
PyInt_FromLong
((
long
)
par
);
}
static
PyObject
*
alc_setqueuesize
(
alcobject
*
self
,
PyObject
*
args
)
{
return
setconfig
(
self
,
args
,
ALsetqueuesize
);
}
static
PyObject
*
alc_getqueuesize
(
alcobject
*
self
,
PyObject
*
args
)
{
return
getconfig
(
self
,
args
,
ALgetqueuesize
);
}
static
PyObject
*
alc_setwidth
(
alcobject
*
self
,
PyObject
*
args
)
{
return
setconfig
(
self
,
args
,
ALsetwidth
);
}
static
PyObject
*
alc_getwidth
(
alcobject
*
self
,
PyObject
*
args
)
{
return
getconfig
(
self
,
args
,
ALgetwidth
);
}
static
PyObject
*
alc_getchannels
(
alcobject
*
self
,
PyObject
*
args
)
{
return
getconfig
(
self
,
args
,
ALgetchannels
);
}
static
PyObject
*
alc_setchannels
(
alcobject
*
self
,
PyObject
*
args
)
{
return
setconfig
(
self
,
args
,
ALsetchannels
);
}
#ifdef
AL_405
static
PyObject
*
alc_getsampfmt
(
alcobject
*
self
,
PyObject
*
args
)
{
return
getconfig
(
self
,
args
,
ALgetsampfmt
);
}
static
PyObject
*
alc_setsampfmt
(
alcobject
*
self
,
PyObject
*
args
)
{
return
setconfig
(
self
,
args
,
ALsetsampfmt
);
}
static
PyObject
*
alc_getfloatmax
(
alcobject
*
self
,
PyObject
*
args
)
{
double
arg
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFloatMax"
))
return
0
;
if
((
arg
=
ALgetfloatmax
(
self
->
config
))
==
0
)
return
NULL
;
return
PyFloat_FromDouble
(
arg
);
}
static
PyObject
*
alc_setfloatmax
(
alcobject
*
self
,
PyObject
*
args
)
{
double
arg
;
if
(!
PyArg_ParseTuple
(
args
,
"d:SetFloatMax"
,
&
arg
))
return
0
;
if
(
ALsetfloatmax
(
self
->
config
,
arg
)
==
-1
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
#endif
/* AL_405 */
static
struct
PyMethodDef
alc_methods
[]
=
{
#ifdef
AL_NO_ELEM
/* IRIX 6 */
{
"SetWidth"
, (
PyCFunction
)
alc_SetWidth
,
METH_VARARGS
,
alc_SetWidth__doc__
},
{
"GetWidth"
, (
PyCFunction
)
alc_GetWidth
,
METH_VARARGS
,
alc_GetWidth__doc__
},
{
"SetSampFmt"
, (
PyCFunction
)
alc_SetSampFmt
,
METH_VARARGS
,
alc_SetSampFmt__doc__
},
{
"GetSampFmt"
, (
PyCFunction
)
alc_GetSampFmt
,
METH_VARARGS
,
alc_GetSampFmt__doc__
},
{
"SetChannels"
, (
PyCFunction
)
alc_SetChannels
,
METH_VARARGS
,
alc_SetChannels__doc__
},
{
"GetChannels"
, (
PyCFunction
)
alc_GetChannels
,
METH_VARARGS
,
alc_GetChannels__doc__
},
{
"SetFloatMax"
, (
PyCFunction
)
alc_SetFloatMax
,
METH_VARARGS
,
alc_SetFloatMax__doc__
},
{
"GetFloatMax"
, (
PyCFunction
)
alc_GetFloatMax
,
METH_VARARGS
,
alc_GetFloatMax__doc__
},
{
"SetDevice"
, (
PyCFunction
)
alc_SetDevice
,
METH_VARARGS
,
alc_SetDevice__doc__
},
{
"GetDevice"
, (
PyCFunction
)
alc_GetDevice
,
METH_VARARGS
,
alc_GetDevice__doc__
},
{
"SetQueueSize"
, (
PyCFunction
)
alc_SetQueueSize
,
METH_VARARGS
,
alc_SetQueueSize__doc__
},
{
"GetQueueSize"
, (
PyCFunction
)
alc_GetQueueSize
,
METH_VARARGS
,
alc_GetQueueSize__doc__
},
#endif
/* AL_NO_ELEM */
{
"getqueuesize"
, (
PyCFunction
)
alc_getqueuesize
,
METH_VARARGS
},
{
"setqueuesize"
, (
PyCFunction
)
alc_setqueuesize
,
METH_VARARGS
},
{
"getwidth"
, (
PyCFunction
)
alc_getwidth
,
METH_VARARGS
},
{
"setwidth"
, (
PyCFunction
)
alc_setwidth
,
METH_VARARGS
},
{
"getchannels"
, (
PyCFunction
)
alc_getchannels
,
METH_VARARGS
},
{
"setchannels"
, (
PyCFunction
)
alc_setchannels
,
METH_VARARGS
},
#ifdef
AL_405
{
"getsampfmt"
, (
PyCFunction
)
alc_getsampfmt
,
METH_VARARGS
},
{
"setsampfmt"
, (
PyCFunction
)
alc_setsampfmt
,
METH_VARARGS
},
{
"getfloatmax"
, (
PyCFunction
)
alc_getfloatmax
,
METH_VARARGS
},
{
"setfloatmax"
, (
PyCFunction
)
alc_setfloatmax
,
METH_VARARGS
},
#endif
/* AL_405 */
{
NULL
,
NULL
}
/* sentinel */
};
/* ---------- */
static
PyObject
*
newalcobject
(
ALconfig
config
)
{
alcobject
*
self
;
self
=
PyObject_New
(
alcobject
,
&
Alctype
);
if
(
self
==
NULL
)
return
NULL
;
/* XXXX Add your own initializers here */
self
->
config
=
config
;
return
(
PyObject
*
)
self
;
}
static
void
alc_dealloc
(
alcobject
*
self
)
{
/* XXXX Add your own cleanup code here */
#ifdef
AL_NO_ELEM
/* IRIX 6 */
(
void
)
alFreeConfig
(
self
->
config
);
/* ignore errors */
#else
(
void
)
ALfreeconfig
(
self
->
config
);
/* ignore errors */
#endif
PyObject_Del
(
self
);
}
static
PyObject
*
alc_getattr
(
alcobject
*
self
,
char
*
name
)
{
/* XXXX Add your own getattr code here */
return
Py_FindMethod
(
alc_methods
, (
PyObject
*
)
self
,
name
);
}
PyDoc_STRVAR
(
Alctype__doc__
,
""
);
static
PyTypeObject
Alctype
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
/*ob_size*/
"al.config"
,
/*tp_name*/
sizeof
(
alcobject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
alc_dealloc
,
/*tp_dealloc*/
(
printfunc
)
0
,
/*tp_print*/
(
getattrfunc
)
alc_getattr
,
/*tp_getattr*/
(
setattrfunc
)
0
,
/*tp_setattr*/
(
cmpfunc
)
0
,
/*tp_compare*/
(
reprfunc
)
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
(
hashfunc
)
0
,
/*tp_hash*/
(
ternaryfunc
)
0
,
/*tp_call*/
(
reprfunc
)
0
,
/*tp_str*/
/* Space for future expansion */
0L
,
0L
,
0L
,
0L
,
Alctype__doc__
/* Documentation string */
};
/* End of code for config objects */
/* ---------------------------------------------------------------- */
#ifdef
AL_NO_ELEM
/* IRIX 6 */
PyDoc_STRVAR
(
alp_SetConfig__doc__
,
"alSetConfig: set the ALconfig of an audio ALport."
);
static
PyObject
*
alp_SetConfig
(
alpobject
*
self
,
PyObject
*
args
)
{
alcobject
*
config
;
if
(!
PyArg_ParseTuple
(
args
,
"O!:SetConfig"
,
&
Alctype
,
&
config
))
return
NULL
;
if
(
alSetConfig
(
self
->
port
,
config
->
config
)
<
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyDoc_STRVAR
(
alp_GetConfig__doc__
,
"alGetConfig: get the ALconfig of an audio ALport."
);
static
PyObject
*
alp_GetConfig
(
alpobject
*
self
,
PyObject
*
args
)
{
ALconfig
config
;
if
(!
PyArg_ParseTuple
(
args
,
":GetConfig"
))
return
NULL
;
if
((
config
=
alGetConfig
(
self
->
port
))
==
NULL
)
return
NULL
;
return
newalcobject
(
config
);
}
PyDoc_STRVAR
(
alp_GetResource__doc__
,
"alGetResource: get the resource associated with an audio port."
);
static
PyObject
*
alp_GetResource
(
alpobject
*
self
,
PyObject
*
args
)
{
int
resource
;
if
(!
PyArg_ParseTuple
(
args
,
":GetResource"
))
return
NULL
;
if
((
resource
=
alGetResource
(
self
->
port
))
==
0
)
return
NULL
;
return
PyInt_FromLong
((
long
)
resource
);
}
PyDoc_STRVAR
(
alp_GetFD__doc__
,
"alGetFD: get the file descriptor for an audio port."
);
static
PyObject
*
alp_GetFD
(
alpobject
*
self
,
PyObject
*
args
)
{
int
fd
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFD"
))
return
NULL
;
if
((
fd
=
alGetFD
(
self
->
port
))
<
0
)
return
NULL
;
return
PyInt_FromLong
((
long
)
fd
);
}
PyDoc_STRVAR
(
alp_GetFilled__doc__
,
"alGetFilled: return the number of filled sample frames in "
"an audio port."
);
static
PyObject
*
alp_GetFilled
(
alpobject
*
self
,
PyObject
*
args
)
{
int
filled
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFilled"
))
return
NULL
;
if
((
filled
=
alGetFilled
(
self
->
port
))
<
0
)
return
NULL
;
return
PyInt_FromLong
((
long
)
filled
);
}
PyDoc_STRVAR
(
alp_GetFillable__doc__
,
"alGetFillable: report the number of unfilled sample frames "
"in an audio port."
);
static
PyObject
*
alp_GetFillable
(
alpobject
*
self
,
PyObject
*
args
)
{
int
fillable
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFillable"
))
return
NULL
;
if
((
fillable
=
alGetFillable
(
self
->
port
))
<
0
)
return
NULL
;
return
PyInt_FromLong
((
long
)
fillable
);
}
PyDoc_STRVAR
(
alp_ReadFrames__doc__
,
"alReadFrames: read sample frames from an audio port."
);
static
PyObject
*
alp_ReadFrames
(
alpobject
*
self
,
PyObject
*
args
)
{
int
framecount
;
PyObject
*
v
;
int
size
;
int
ch
;
ALconfig
c
;
if
(!
PyArg_ParseTuple
(
args
,
"i:ReadFrames"
,
&
framecount
))
return
NULL
;
if
(
framecount
<
0
) {
PyErr_SetString
(
ErrorObject
,
"negative framecount"
);
return
NULL
;
}
c
=
alGetConfig
(
self
->
port
);
switch
(
alGetSampFmt
(
c
)) {
case
AL_SAMPFMT_TWOSCOMP
:
switch
(
alGetWidth
(
c
)) {
case
AL_SAMPLE_8
:
size
=
1
;
break
;
case
AL_SAMPLE_16
:
size
=
2
;
break
;
case
AL_SAMPLE_24
:
size
=
4
;
break
;
default
:
PyErr_SetString
(
ErrorObject
,
"can't determine width"
);
alFreeConfig
(
c
);
return
NULL
;
}
break
;
case
AL_SAMPFMT_FLOAT
:
size
=
4
;
break
;
case
AL_SAMPFMT_DOUBLE
:
size
=
8
;
break
;
default
:
PyErr_SetString
(
ErrorObject
,
"can't determine format"
);
alFreeConfig
(
c
);
return
NULL
;
}
ch
=
alGetChannels
(
c
);
alFreeConfig
(
c
);
if
(
ch
<
0
) {
PyErr_SetString
(
ErrorObject
,
"can't determine # of channels"
);
return
NULL
;
}
size
*=
ch
;
v
=
PyString_FromStringAndSize
((
char
*
)
NULL
,
size
*
framecount
);
if
(
v
==
NULL
)
return
NULL
;
Py_BEGIN_ALLOW_THREADS
alReadFrames
(
self
->
port
, (
void
*
)
PyString_AS_STRING
(
v
),
framecount
);
Py_END_ALLOW_THREADS
return
v
;
}
PyDoc_STRVAR
(
alp_DiscardFrames__doc__
,
"alDiscardFrames: discard audio from an audio port."
);
static
PyObject
*
alp_DiscardFrames
(
alpobject
*
self
,
PyObject
*
args
)
{
int
framecount
;
if
(!
PyArg_ParseTuple
(
args
,
"i:DiscardFrames"
,
&
framecount
))
return
NULL
;
Py_BEGIN_ALLOW_THREADS
framecount
=
alDiscardFrames
(
self
->
port
,
framecount
);
Py_END_ALLOW_THREADS
if
(
framecount
<
0
)
return
NULL
;
return
PyInt_FromLong
((
long
)
framecount
);
}
PyDoc_STRVAR
(
alp_ZeroFrames__doc__
,
"alZeroFrames: write zero-valued sample frames to an audio port."
);
static
PyObject
*
alp_ZeroFrames
(
alpobject
*
self
,
PyObject
*
args
)
{
int
framecount
;
if
(!
PyArg_ParseTuple
(
args
,
"i:ZeroFrames"
,
&
framecount
))
return
NULL
;
if
(
framecount
<
0
) {
PyErr_SetString
(
ErrorObject
,
"negative framecount"
);
return
NULL
;
}
Py_BEGIN_ALLOW_THREADS
alZeroFrames
(
self
->
port
,
framecount
);
Py_END_ALLOW_THREADS
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyDoc_STRVAR
(
alp_SetFillPoint__doc__
,
"alSetFillPoint: set low- or high-water mark for an audio port."
);
static
PyObject
*
alp_SetFillPoint
(
alpobject
*
self
,
PyObject
*
args
)
{
int
fillpoint
;
if
(!
PyArg_ParseTuple
(
args
,
"i:SetFillPoint"
,
&
fillpoint
))
return
NULL
;
if
(
alSetFillPoint
(
self
->
port
,
fillpoint
)
<
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyDoc_STRVAR
(
alp_GetFillPoint__doc__
,
"alGetFillPoint: get low- or high-water mark for an audio port."
);
static
PyObject
*
alp_GetFillPoint
(
alpobject
*
self
,
PyObject
*
args
)
{
int
fillpoint
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFillPoint"
))
return
NULL
;
if
((
fillpoint
=
alGetFillPoint
(
self
->
port
))
<
0
)
return
NULL
;
return
PyInt_FromLong
((
long
)
fillpoint
);
}
PyDoc_STRVAR
(
alp_GetFrameNumber__doc__
,
"alGetFrameNumber: get the absolute sample frame number "
"associated with a port."
);
static
PyObject
*
alp_GetFrameNumber
(
alpobject
*
self
,
PyObject
*
args
)
{
stamp_t
fnum
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFrameNumber"
))
return
NULL
;
if
(
alGetFrameNumber
(
self
->
port
,
&
fnum
)
<
0
)
return
NULL
;
return
PyLong_FromLongLong
((
long long
)
fnum
);
}
PyDoc_STRVAR
(
alp_GetFrameTime__doc__
,
"alGetFrameTime: get the time at which a sample frame came "
"in or will go out."
);
static
PyObject
*
alp_GetFrameTime
(
alpobject
*
self
,
PyObject
*
args
)
{
stamp_t
fnum
,
time
;
PyObject
*
ret
,
*
v0
,
*
v1
;
if
(!
PyArg_ParseTuple
(
args
,
":GetFrameTime"
))
return
NULL
;
if
(
alGetFrameTime
(
self
->
port
,
&
fnum
,
&
time
)
<
0
)
return
NULL
;
v0
=
PyLong_FromLongLong
((
long long
)
fnum
);
v1
=
PyLong_FromLongLong
((
long long
)
time
);
if
(
PyErr_Occurred
()) {
Py_XDECREF
(
v0
);
Py_XDECREF
(
v1
);
return
NULL
;
}
ret
=
PyTuple_Pack
(
2
,
v0
,
v1
);
Py_DECREF
(
v0
);
Py_DECREF
(
v1
);
return
ret
;
}
PyDoc_STRVAR
(
alp_WriteFrames__doc__
,
"alWriteFrames: write sample frames to an audio port."
);
static
PyObject
*
alp_WriteFrames
(
alpobject
*
self
,
PyObject
*
args
)
{
char
*
samples
;
int
length
;
int
size
,
ch
;
ALconfig
c
;
if
(!
PyArg_ParseTuple
(
args
,
"s#:WriteFrames"
,
&
samples
,
&
length
))
return
NULL
;
c
=
alGetConfig
(
self
->
port
);
switch
(
alGetSampFmt
(
c
)) {
case
AL_SAMPFMT_TWOSCOMP
:
switch
(
alGetWidth
(
c
)) {
case
AL_SAMPLE_8
:
size
=
1
;
break
;
case
AL_SAMPLE_16
:
size
=
2
;
break
;
case
AL_SAMPLE_24
:
size
=
4
;
break
;
default
:
PyErr_SetString
(
ErrorObject
,
"can't determine width"
);
alFreeConfig
(
c
);
return
NULL
;
}
break
;
case
AL_SAMPFMT_FLOAT
:
size
=
4
;
break
;
case
AL_SAMPFMT_DOUBLE
:
size
=
8
;
break
;
default
:
PyErr_SetString
(
ErrorObject
,
"can't determine format"
);
alFreeConfig
(
c
);
return
NULL
;
}
ch
=
alGetChannels
(
c
);
alFreeConfig
(
c
);
if
(
ch
<
0
) {
PyErr_SetString
(
ErrorObject
,
"can't determine # of channels"
);
return
NULL
;
}
size
*=
ch
;
if
(
length
%
size
!=
0
) {
PyErr_SetString
(
ErrorObject
,
"buffer length not whole number of frames"
);
return
NULL
;
}
Py_BEGIN_ALLOW_THREADS
alWriteFrames
(
self
->
port
, (
void
*
)
samples
,
length
/
size
);
Py_END_ALLOW_THREADS
Py_INCREF
(
Py_None
);
return
Py_None
;
}
PyDoc_STRVAR
(
alp_ClosePort__doc__
,
"alClosePort: close an audio port."
);
static
PyObject
*
alp_ClosePort
(
alpobject
*
self
,
PyObject
*
args
)
{
if
(!
PyArg_ParseTuple
(
args
,
":ClosePort"
))
return
NULL
;
if
(
alClosePort
(
self
->
port
)
<
0
)
return
NULL
;
self
->
port
=
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
#endif
/* AL_NO_ELEM */
#ifdef
OLD_INTERFACE
static
PyObject
*
alp_closeport
(
alpobject
*
self
,
PyObject
*
args
)
{
if
(!
PyArg_ParseTuple
(
args
,
":ClosePort"
))
return
NULL
;
if
(
ALcloseport
(
self
->
port
)
<
0
)
return
NULL
;
self
->
port
=
NULL
;
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL