File: ossmodule.html

package info (click to toggle)
python-oss 0.0.0.20010624-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 388 kB
  • ctags: 218
  • sloc: ansic: 1,351; python: 110; makefile: 98
file content (1893 lines) | stat: -rw-r--r-- 47,016 bytes parent folder | download | duplicates (5)
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
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.51
     from ossmodule.texi on 30 July 1997 -->

<TITLE>Python OSS Module</TITLE>
</HEAD>
<BODY>
<H1>Python OSS Module</H1>
<H2>A Python interface to the Open Sound System API</H2>
<H2>July 1997</H2>
<ADDRESS>Timothy Butler</ADDRESS>
<P>
<P><HR><P>
<H1>Table of Contents</H1>
<UL>
<LI><A NAME="TOC1" HREF="ossmodule.html#SEC1">Introduction</A>
<UL>
<LI><A NAME="TOC2" HREF="ossmodule.html#SEC2">Essential References</A>
<LI><A NAME="TOC3" HREF="ossmodule.html#SEC3">Obtaining the oss Module</A>
<LI><A NAME="TOC4" HREF="ossmodule.html#SEC4">Installation</A>
<UL>
<LI><A NAME="TOC5" HREF="ossmodule.html#SEC5">Linking into the Interpreter</A>
<LI><A NAME="TOC6" HREF="ossmodule.html#SEC6">Building a Shared Library</A>
</UL>
<LI><A NAME="TOC7" HREF="ossmodule.html#SEC7">Feedback</A>
<LI><A NAME="TOC8" HREF="ossmodule.html#SEC8">Design and Implementation</A>
<LI><A NAME="TOC9" HREF="ossmodule.html#SEC9">Future Development</A>
</UL>
<LI><A NAME="TOC10" HREF="ossmodule.html#SEC10">Mixer Programming</A>
<UL>
<LI><A NAME="TOC11" HREF="ossmodule.html#SEC11">Channel Identifiers</A>
<UL>
<LI><A NAME="TOC12" HREF="ossmodule.html#SEC12">Channel Numbers</A>
<LI><A NAME="TOC13" HREF="ossmodule.html#SEC13">Channel Labels</A>
</UL>
<LI><A NAME="TOC14" HREF="ossmodule.html#SEC14">mixer Objects</A>
<UL>
<LI><A NAME="TOC15" HREF="ossmodule.html#SEC15">mixer Instantiation</A>
<LI><A NAME="TOC16" HREF="ossmodule.html#SEC16">mixer Methods</A>
</UL>
</UL>
<LI><A NAME="TOC17" HREF="ossmodule.html#SEC17">Sequencer Programming</A>
<UL>
<LI><A NAME="TOC18" HREF="ossmodule.html#SEC18">sequencer Objects</A>
<UL>
<LI><A NAME="TOC19" HREF="ossmodule.html#SEC19">sequencer Instantiation</A>
<LI><A NAME="TOC20" HREF="ossmodule.html#SEC20">sequencer Methods</A>
</UL>
<LI><A NAME="TOC21" HREF="ossmodule.html#SEC21">synth_info Objects</A>
<UL>
<LI><A NAME="TOC22" HREF="ossmodule.html#SEC22">synth_info Instantiation</A>
<LI><A NAME="TOC23" HREF="ossmodule.html#SEC23">synth_info Members</A>
</UL>
<LI><A NAME="TOC24" HREF="ossmodule.html#SEC24">midi_info Objects</A>
<UL>
<LI><A NAME="TOC25" HREF="ossmodule.html#SEC25">midi_info Instantiation</A>
<LI><A NAME="TOC26" HREF="ossmodule.html#SEC26">midi_info Members</A>
</UL>
</UL>
<LI><A NAME="TOC27" HREF="ossmodule.html#SEC27">Audio Programming</A>
<UL>
<LI><A NAME="TOC28" HREF="ossmodule.html#SEC28">Audio Formats</A>
<LI><A NAME="TOC29" HREF="ossmodule.html#SEC29">audio Objects</A>
<UL>
<LI><A NAME="TOC30" HREF="ossmodule.html#SEC30">audio Instantiation</A>
<LI><A NAME="TOC31" HREF="ossmodule.html#SEC31">audio Methods</A>
</UL>
</UL>
<LI><A NAME="TOC32" HREF="ossmodule.html#SEC32">Miscellaneous</A>
<UL>
<LI><A NAME="TOC33" HREF="ossmodule.html#SEC33">Sound Card ID Numbers</A>
</UL>
<LI><A NAME="TOC34" HREF="ossmodule.html#SEC34">Variable Index</A>
<LI><A NAME="TOC35" HREF="ossmodule.html#SEC35">Function Index</A>
</UL>
<P><HR><P>


<H1><A NAME="SEC1" HREF="ossmodule.html#TOC1">Introduction</A></H1>

<P>
The <B>oss</B> module provides access to the Open Sound System from the
Python programming language.  The Open Sound System is a UNIX device
driver that allows you to record and play digitized audio, control input
and output volume levels, select recording sources, and generate
synthesizer commands and midi bytes controlled by a low-level sequencer.
It runs on FreeBSD, Linux, BSD/OS, Solaris, and other operating systems.

</P>
<P>
Python is an interpreted, interactive, object-oriented, extensible,
and way-cool programming language.  An interactive programming environment
extended with objects to control your sound card can be a powerful and
fun combination.

</P>



<H2><A NAME="SEC2" HREF="ossmodule.html#TOC2">Essential References</A></H2>

<P>
This manual does not cover all of the details you need to program 
the Open Sound System. You should consult the following resources 
to learn about the Open Sound System.

</P>
<DL COMPACT>

<DT>Open Sound System
<DD>
http://www.4front-tech.com/oss.html

<DT>Open Sound System (OSS) Free
<DD>
http://www.4front-tech.com/usslite/

<DT>OSS Programmer's Guide
<DD>
http://www.4front-tech.com/pguide/index.html

<DT>OSS documentation (contains link to valuable "Hackers Guide to VoxWare")
<DD>
http://www.4front-tech.com/usslite/docs.html

</DL>

<P>
You can find more information about Python at 

</P>
<DL COMPACT>

<DT>Python Home Page
<DD>
http://www.python.org
</DL>



<H2><A NAME="SEC3" HREF="ossmodule.html#TOC3">Obtaining the oss Module</A></H2>

<P>
You can download the oss Module from

<PRE>
    http://www.indra.com/~tim/ossmodule
</PRE>



<H2><A NAME="SEC4" HREF="ossmodule.html#TOC4">Installation</A></H2>

<P>
The <B>oss</B> module consists entirely of a single C language source file,
<TT>`ossmodule.c'</TT>.  You must either 

</P>

<OL>

<LI>

compile and link the module into the Python interpreter or

<LI>

create and install a shared library in a directory named by your
<CODE>PYTHONPATH</CODE>.

</OL>



<H3><A NAME="SEC5" HREF="ossmodule.html#TOC5">Linking into the Interpreter</A></H3>


<OL>

<LI>Copy <TT>`ossmodule.c'</TT> into Python's <TT>`Modules'</TT> directory.


<PRE>
    &#62; cp ossmodule.c Python-1.4/Modules
</PRE>

<LI>Edit <TT>`Modules/Setup'</TT> and add an entry for the <B>oss</B> module.


<PRE>
    oss ossmodule.c -I/usr/include/machine -I/usr/include/sys
</PRE>

You may need to add or change the C preprocessor's search directories so
it can find <TT>`soundcard.h'</TT> on your system.

You can also create a shared library this way if you place the module
line in the <CODE>*shared*</CODE> section of the <TT>`Setup'</TT> file.  Read the
comments in the <TT>`Setup'</TT> file for details.

<LI>Recompile, test, and install the Python interpreter


<PRE>
    &#62; cd Python-1.4
    &#62; make

    &#62; ./python
    &#62;&#62; import oss

    &#62;make bininstall
</PRE>

        
</OL>



<H3><A NAME="SEC6" HREF="ossmodule.html#TOC6">Building a Shared Library</A></H3>

<P>
You can use the <TT>`Makefile'</TT> provided with the <B>oss</B> module
distribution to compile a shared library.  You will have to edit the
<TT>`Makefile'</TT> to match your system.  Copy the resulting shared library
to a directory named by your <CODE>PYTHONPATH</CODE>.

</P>

<OL>

</OL>



<H2><A NAME="SEC7" HREF="ossmodule.html#TOC7">Feedback</A></H2>

<P>
Please email bug reports and comments concerning the <B>oss</B> module to
<CODE>tim@netbox.com</CODE>.

</P>
<P>
I am not qualified to answer questions about the OSS itself.  Part of
the reason I wrote the <B>oss</B> module was to create an environment where
I could experiment with and learn about the OSS.

</P>
<P>
If you can't get your sound card to work in the first place
I can't help;  but you might check out the resources listed above.
See section <A HREF="ossmodule.html#SEC2">Essential References</A>.

</P>


<H2><A NAME="SEC8" HREF="ossmodule.html#TOC8">Design and Implementation</A></H2>

<P>
The C language header file, <TT>`sys/soundcard.h'</TT>, defines the OSS API.
Most of the API consists of macros which define operations and arguments
for the <CODE>ioctl()</CODE> system call. 

</P>
<P>
The <B>oss</B> module implements only the bare minimum to use the API
including:

</P>
<DL COMPACT>

<DT><B>Sound device objects.</B>
<DD>
Represent devices such as a mixer, sequencer, and digital audio
devices. The sound device objects in the <B>oss</B>
module store a file descriptor and their methods typically involve
little more than a call to <CODE>ioctl()</CODE> with the proper arguments.

<DT><B>Functions that open and return sound device objects.</B>
<DD>
<DT><B>Module-level variables holding macro "constants".</B>
<DD>
Bitmasks or device numbers that are ultimately provided as arguments to
the <CODE>ioctl()</CODE> calls. Many module-level variables exist in the
<B>oss</B> module which correspond to the exact same names of macro
constants in <TT>`soundcard.h'</TT>.  For example the value of
<CODE>oss.SOUND_MIXER_NRDEVICES</CODE> is the same as
<CODE>SOUND_MIXER_NRDEVICES</CODE> in <TT>`soundcard.h'</TT>.

<DT><B>"Structure" objects.</B>
<DD>
Hold read-only information about system capabilities.

</DL>

<P>
The API operations, such as <CODE>SOUND_MIXER_READ_RECMASK</CODE>, typically
translate into methods of sound device objects, such as
<CODE>mixer.read_recmask()</CODE>.  The correspondence should be clear from the
documentation if not from the names.

</P>
<P>
None of the objects provided by the <B>oss</B> module can serve as base classes.

</P>
<P>
Not every name and data structure provided by <TT>`soundcard.h'</TT> is
available through the <B>oss</B> module. The <B>oss</B> module provides only
the interface that is described in the official OSS API documentation.
Many parts of <TT>`soundcard.h'</TT> are either unsupported, obsolete, not
portable, or undocumented.

</P>
<P>
The MIDI interface and the /dev/sndstat objects are not provided because
these interfaces are simply read and write operations.
 
The <B>oss</B> module was developed using the OSSFree implementation under
FreeBSD. Your mileage may vary.

</P>


<H2><A NAME="SEC9" HREF="ossmodule.html#TOC9">Future Development</A></H2>

<P>
I would like to stick as close as possible to the OSS API as opposed to
implementing old or undocumented features.  So far, I have provided
that part of the API provided implemented by OSSFree.  I may add
features of the commercial version as an option.

</P>
<P>
As a separate project I'd like to add a layer on top of the <B>oss</B>
module (called "possum") that provides graphical interfaces to the sound
devices.  MIDI protocol support would be handy also.

</P>



<H1><A NAME="SEC10" HREF="ossmodule.html#TOC10">Mixer Programming</A></H1>



<H2><A NAME="SEC11" HREF="ossmodule.html#TOC11">Channel Identifiers</A></H2>



<H3><A NAME="SEC12" HREF="ossmodule.html#TOC12">Channel Numbers</A></H3>

<P>
Mixer channels are identified by channel numbers stored in these
module-level variables. Each channel number variable has a corresponding
"MASK" variable has a single bit set shifted left by the channel number.

</P>
<DL COMPACT>

<DT><CODE>SOUND_MIXER_NRDEVICES</CODE>
<DD>
<A NAME="IDX1"></A>
number of channels known to OSS [0,30] 

<DT><CODE>SOUND_MIXER_VOLUME</CODE>
<DD>
<A NAME="IDX2"></A>
<DT><CODE>SOUND_MASK_VOLUME</CODE>
<DD>
<A NAME="IDX3"></A>
 master output level     
	
<DT><CODE>SOUND_MIXER_BASS</CODE>
<DD>
<A NAME="IDX4"></A>
<DT><CODE>SOUND_MASK_BASS</CODE>
<DD>
<A NAME="IDX5"></A>
bass level of all output channels  

<DT><CODE>SOUND_MIXER_TREBLE</CODE>
<DD>
<A NAME="IDX6"></A>
<DT><CODE>SOUND_MASK_TREBLE</CODE>
<DD>
<A NAME="IDX7"></A>
treble level of all output channels

<DT><CODE>SOUND_MIXER_SYNTH</CODE>
<DD>
<A NAME="IDX8"></A>
<DT><CODE>SOUND_MASK_SYNTH</CODE>
<DD>
<A NAME="IDX9"></A>
level of synthesizer (e.g. FM, wave-table)

<DT><CODE>SOUND_MIXER_PCM</CODE>
<DD>
<A NAME="IDX10"></A>
<DT><CODE>SOUND_MASK_PCM</CODE>
<DD>
<A NAME="IDX11"></A>
output level for audio device (/dev/dsp, /dev/audio) 

<DT><CODE>SOUND_MIXER_SPEAKER</CODE>
<DD>
<A NAME="IDX12"></A>
<DT><CODE>SOUND_MASK_SPEAKER</CODE>
<DD>
<A NAME="IDX13"></A>
volume of PC speaker signal routed through card 

<DT><CODE>SOUND_MIXER_LINE</CODE>
<DD>
<A NAME="IDX14"></A>
<DT><CODE>SOUND_MASK_LINE</CODE>
<DD>
<A NAME="IDX15"></A>
level for line-in jack

<DT><CODE>SOUND_MIXER_MIC</CODE>
<DD>
<A NAME="IDX16"></A>
<DT><CODE>SOUND_MASK_MIC</CODE>
<DD>
<A NAME="IDX17"></A>
input level from microphone jack

<DT><CODE>SOUND_MIXER_CD</CODE>
<DD>
<A NAME="IDX18"></A>
<DT><CODE>SOUND_MASK_CD</CODE>
<DD>
<A NAME="IDX19"></A>
input level from CD

<DT><CODE>SOUND_MIXER_IMIX</CODE>
<DD>
<A NAME="IDX20"></A>
<DT><CODE>SOUND_MASK_IMIX</CODE>
<DD>
<A NAME="IDX21"></A>
output (headphone jack) vol for rec monitor (rec only)

<DT><CODE>SOUND_MIXER_ALTPCM</CODE>
<DD>
<A NAME="IDX22"></A>
<DT><CODE>SOUND_MASK_ALTPCM</CODE>
<DD>
<A NAME="IDX23"></A>
volume of alternative CODEC device

<DT><CODE>SOUND_MIXER_RECLEV</CODE>
<DD>
<A NAME="IDX24"></A>
<DT><CODE>SOUND_MASK_RECLEV</CODE>
<DD>
<A NAME="IDX25"></A>
global recording level (rec only)

<DT><CODE>SOUND_MIXER_IGAIN</CODE>
<DD>
<A NAME="IDX26"></A>
<DT><CODE>SOUND_MASK_IGAIN</CODE>
<DD>
<A NAME="IDX27"></A>
??

<DT><CODE>SOUND_MIXER_OGAIN</CODE>
<DD>
<A NAME="IDX28"></A>
<DT><CODE>SOUND_MASK_OGAIN</CODE>
<DD>
<A NAME="IDX29"></A>
??

<DT><CODE>SOUND_MIXER_LINE1</CODE>
<DD>
<A NAME="IDX30"></A>
<DT><CODE>SOUND_MASK_LINE1</CODE>
<DD>
<A NAME="IDX31"></A>
vendor specific

<DT><CODE>SOUND_MIXER_LINE2</CODE>
<DD>
<A NAME="IDX32"></A>
<DT><CODE>SOUND_MASK_LINE2</CODE>
<DD>
<A NAME="IDX33"></A>
vendor specific

<DT><CODE>SOUND_MIXER_LINE3</CODE>
<DD>
<A NAME="IDX34"></A>
<DT><CODE>SOUND_MASK_LINE3</CODE>
<DD>
<A NAME="IDX35"></A>
vendor specific

</DL>



<H3><A NAME="SEC13" HREF="ossmodule.html#TOC13">Channel Labels</A></H3>

<P>
Two module-level lists, <CODE>SOUND_DEVICE_LABELS</CODE> and
<CODE>SOUND_DEVICE_NAMES</CODE>, store strings that can be used to name
channels. These lists can be indexed by channel number
(e.g. <CODE>SOUND_DEVICE_LABELS[SOUND_MIXER_VOLUME]</CODE>).

</P>
<DL COMPACT>

<DT><CODE>SOUND_DEVICE_LABELS</CODE>
<DD>
<A NAME="IDX36"></A>
channel names that are suitable for user presentation.
<DT><CODE>SOUND_DEVICE_NAMES</CODE>
<DD>
<A NAME="IDX37"></A>
lowercase fixed-size names without spaces.

</DL>



<H2><A NAME="SEC14" HREF="ossmodule.html#TOC14">mixer Objects</A></H2>

<P>
A mixer object controls the volume levels of input and output channels.
A mixer object also selects input sources from the microphone, line, and
CD inputs.

</P>
<P>
Read and write operations on a mixer's file descriptor are undefined and
there are no <CODE>read()</CODE> or <CODE>write()</CODE> methods on a mixer.
    

</P>


<H3><A NAME="SEC15" HREF="ossmodule.html#TOC15">mixer Instantiation</A></H3>

<P>
Create an mixer object using the module function <CODE>open_mixer()</CODE>.
The same mixer device may be opened more than once.
An open mixer object will be closed before it is deleted.

</P>
<P>
<DL>
<DT><U>Function:</U> <B>open_mixer</B> <I>(filename, flags)</I>
<DD><A NAME="IDX38"></A>
        
Create, open, and return a new mixer object.
<DL COMPACT>

<DT><VAR>filename</VAR>
<DD>
 defaults to <CODE>"/dev/mixer"</CODE>.
<DT><VAR>flags</VAR>
<DD>
defaults to <CODE>FCNTL.O_RDWR</CODE>.
</DL>

</DL>



<H3><A NAME="SEC16" HREF="ossmodule.html#TOC16">mixer Methods</A></H3>

<P>
<DL>
<DT><U>Method:</U> mixer <B>fileno</B> <I>()</I>
<DD><A NAME="IDX39"></A>
Return the file number associated with this mixer.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> mixer <B>close</B> <I>()</I>
<DD><A NAME="IDX40"></A>
Free the resources associated with this mixer.

</P>
<P>
Called on deletion if not called explicitly.  Do not call any
methods of a closed mixer.
</DL>
    
<DL>
<DT><U>Method:</U> mixer <B>devmask</B> <I>()</I>
<DD><A NAME="IDX41"></A>
Return a bitmask of available mixer channels.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> mixer <B>recmask</B> <I>()</I>
<DD><A NAME="IDX42"></A>
Return a bitmask of channels that may be used as recording sources.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> mixer <B>stereodevs</B> <I>()</I>
<DD><A NAME="IDX43"></A>
Return a bitmask of stereo channels.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> mixer <B>caps</B> <I>()</I>
<DD><A NAME="IDX44"></A>
Return a bitmask describing the general capabilities of a mixer.

</P>
<P>
Currently, the module-level constant mask <CODE>SOUND_CAP_EXCL_INPUT</CODE> is
the only mixer capability defined. 

</P>
<DL COMPACT>

<DT><CODE>SOUND_CAP_EXCL_INPUT</CODE>
<DD>
<A NAME="IDX45"></A>
If this bit is set to 1, then only one mixer channel can be selected at
the same time.
</DL>

</DL>

<P>
<DL>
<DT><U>Method:</U> mixer <B>read_recsrc</B> <I>()</I>
<DD><A NAME="IDX46"></A>
Return a bitmask of active recording sources.
</DL>

</P>

<P>
<DL>
<DT><U>Method:</U> mixer <B>write_recsrc</B> <I>(mask)</I>
<DD><A NAME="IDX47"></A>
Select recording source channels with a bitmask.
	
If <VAR>mask</VAR> is zero, then the mic input will be used.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> mixer <B>read_channel</B> <I>(channel_num)</I>
<DD><A NAME="IDX48"></A>
Return the level (volume) of a channel.

</P>
<P>
The volume is returned as a tuple, ( <VAR>left</VAR>, <VAR>right</VAR> ),
representing the level of both stereo channels.  For mono devices, only
<VAR>left</VAR> is valid, (the right channel value is set to the left).
	
Levels are between 0 (off) and 100 (maximum), inclusive.

</P>
</DL>

<P>
<DL>
<DT><U>Method:</U> mixer <B>write_channel</B> <I>(channel_num, level)</I>
<DD><A NAME="IDX49"></A>
Set the level (volume) of a channel.

</P>
<P>
<VAR>level</VAR> may be either a single integer or a tuple
(<VAR>left</VAR>, <VAR>right</VAR>) with values from 0 (off) to 100
(maximum), inclusive.
	
If <VAR>level</VAR> is a single integer, it is applied to just a mono
channel or both sides of a stereo channel.
	
If <VAR>level</VAR> is a tuple, then each side of a stereo channel will
be assigned its own level. Mono-devices use the left value
of a tuple.
	
<CODE>write_channel()</CODE> returns a tuple that represents the new
level(s) of a channel.  Because some mixers will quantize
levels with only 3 to 8 bits, the new levels may <EM>not</EM> be
exactly the same as what was requested. See the OSS
developer's guide for details.
</DL>

</P>


<H1><A NAME="SEC17" HREF="ossmodule.html#TOC17">Sequencer Programming</A></H1>



<H2><A NAME="SEC18" HREF="ossmodule.html#TOC18">sequencer Objects</A></H2>

<P>
The sequencer object controls the on-board synthesizer using MIDI-like
commands and allows I/O through MIDI ports.

</P>

<P>
Synthesizers accept commands that resemble MIDI commands but otherwise
have nothing to do with the MIDI capabilities of a soundcard. For
example, some synthesizer methods are called <CODE>note_on()</CODE> and
<CODE>chn_pressure()</CODE> but these do not send bytes out the MIDI
port. Instead, they only mimic similar effects with the synthesizers.

</P>
<P>
MIDI I/O support consists entirely of simple commands to read and
write individual bytes through specific MIDI ports. MIDI input is not
implemented in this version.
    
Read and write operations on a mixer's file descriptor are undefined and
there are no <CODE>read()</CODE> or <CODE>write()</CODE> methods on a mixer.

</P>
<P>
Many methods of a sequencer generate an <STRONG>event</STRONG> (synthesizer command
or a MIDI byte) that is written immediately to a buffer in the <B>oss</B>
module.  As the buffer fills, events will eventually be passed to the
driver's queue. The sequencer <CODE>dump_buf()</CODE> method flushes the
module's buffer to the driver's event queue.
 
The sequencer driver processes most events in its queue immediately.
The sequencer method <CODE>wait_time()</CODE> intersperses timing events
between other events. When the driver processes a timing event in the
queue, it waits until that absolute time before continuing. Note that in
order for the sequencer to see the timing event it must be flushed to
the event queue using <CODE>dump_buf()</CODE>.
    

</P>


<H3><A NAME="SEC19" HREF="ossmodule.html#TOC19">sequencer Instantiation</A></H3>

<P>
Create an sequencer object using the module function <CODE>open_sequencer()</CODE>.
Only one sequencer may be open at a time; even within the same 
application.

</P>
<P>
An open sequencer object will be closed before it is deleted.
    
<DL>
<DT><U>Function:</U> <B>open_sequencer</B> <I>(filename, flags):</I>
<DD><A NAME="IDX50"></A>
Create, open, and return a new sequencer object.

</P>
<DL COMPACT>

<DT><VAR>filename</VAR>
<DD>
 defaults to <CODE>"/dev/sequencer"</CODE>.
<DT><VAR>flags</VAR>
<DD>
defaults to <CODE>FCNTL.O_RDWR</CODE>.

Use <CODE>FCNTL.O_WRONLY</CODE> for an output-only program so unnecessary
functions like MIDI input aren't initialized.  Likewise, use
<CODE>FCNTL.O_RDONLY</CODE> for input-only programs.
</DL>

</DL>



<H3><A NAME="SEC20" HREF="ossmodule.html#TOC20">sequencer Methods</A></H3>

<P>
<DL>
<DT><U>Method:</U> sequencer <B>fileno</B> <I>()</I>
<DD><A NAME="IDX51"></A>
Return the file number associated with this sequencer.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>close</B> <I>()</I>
<DD><A NAME="IDX52"></A>
Free the resources associated with this sequencer.

</P>
<P>
Called on deletion if not called explicitly.  Do not call any
methods of a closed sequencer.
	
<CODE>close()</CODE> shuts off all synthesizer sounds immediately, so you might
want to add an extra delay before closing this device.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>nrsynths</B> <I>()</I>
<DD><A NAME="IDX53"></A>
Return the number of internal synthesizer devices.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>synth_info</B> <I>(obj)</I>
<DD><A NAME="IDX54"></A>
Describe a specific synthesizer.

</P>
<P>
<VAR>obj</VAR> may be either an integer device number or a 
synth_info object with its <CODE>device</CODE> member initialized.

</P>
<P>
If <VAR>obj</VAR> is an integer then return a new synth_info object
describing the device.  If <VAR>obj</VAR> is an existing synth_info then it
is filled in with the description and returned.

</P>
<P>
You must provide a device number that is less than the value
returned by the method <CODE>nrsynths()</CODE>.

</P>
<P>
See section <A HREF="ossmodule.html#SEC21">synth_info Objects</A>
</DL>
	
<DL>
<DT><U>Method:</U> sequencer <B>nrmidis</B> <I>()</I>
<DD><A NAME="IDX55"></A>
Return the number of MIDI ports available.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>midi_info</B> <I>(obj)</I>
<DD><A NAME="IDX56"></A>
Describe a specific MIDI port.

</P>
<P>
<VAR>obj</VAR> may be either an integer port number or a midi_info object
with its <CODE>device</CODE> member initialized to the desired MIDI port.

</P>
<P>
If <VAR>obj</VAR> is an integer then return a new midi_info object describing
the port.  If <VAR>obj</VAR> is an existing midi_info then it is filled in
with the description and returned.

</P>
<P>
You must provide a port number that is less than the value
returned by the <CODE>nrmidis()</CODE> method.

</P>
<P>
See section <A HREF="ossmodule.html#SEC24">midi_info Objects</A>.

</P>
</DL>

<P>
<DL>
<DT><U>Method:</U> sequencer <B>start_timer</B> <I>()</I>
<DD><A NAME="IDX57"></A>
EVENT Reset the sequencer's timer.

</P>
<P>
Note that this method generates an <EM>event</EM> that will 
be processed only when it makes it to the head of the queue.

</P>
<P>
The timer may not be restarted immediately.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>wait_time</B> <I>(time)</I>
<DD><A NAME="IDX58"></A>
EVENT Pause the sequencer until <VAR>time</VAR>.

</P>
<P>
<VAR>time</VAR> is the absolute time when the driver should continue reading
the event queue.  Absolute time is measured in units of the kernel timer
(typically 100 Hz, 10 ms/tick) from the time the device was opened.

</P>
<P>
Use the <CODE>ctrlrate()</CODE> method to determine the actual timer
resolution.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>ctrlrate</B> <I>()</I>
<DD><A NAME="IDX59"></A>
Return the timer resolution in ticks per second.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>midiout</B> <I>(midi_dev, byte)</I>
<DD><A NAME="IDX60"></A>
EVENT Write a byte to a MIDI port.

</P>
<DL COMPACT>

<DT><VAR>midi_dev</VAR>
<DD>
the MIDI port number.
<DT><VAR>byte</VAR>
<DD>
either an integer or a single character that is the byte to output.
</DL>
</DL>

<P>
<DL>
<DT><U>Method:</U> sequencer <B>set_patch</B> <I>(dev, voice, patch)</I>
<DD><A NAME="IDX61"></A>
EVENT Assign synthesizer instrument number (patch) to a voice.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>start_note</B> <I>(dev, voice, note, vel=64)</I>
<DD><A NAME="IDX62"></A>
EVENT Start a voice on a synthesizer device.

</P>
<DL COMPACT>

<DT><VAR>note</VAR>
<DD>
<DT><VAR>vel</VAR>
<DD>
valid MIDI note number and velocity values, [0,127].
</DL>

<P>
Some synthesizers support adjusting the volume of a note (rather than
starting a new note) with a <VAR>note</VAR> value of 255.  A <VAR>vel</VAR> of 255
may specify a volume stored in some synthesizers' internal tables. The
use of these values is not portable.

</P>
</DL>

<P>
<DL>
<DT><U>Method:</U> sequencer <B>stop_note</B> <I>(dev, voice, note, vel=64)</I>
<DD><A NAME="IDX63"></A>
EVENT Stop the synthesizer note being played.

</P>
<DL COMPACT>

<DT><VAR>note</VAR>
<DD>
the MIDI note number
<DT><VAR>vel</VAR>
<DD>
the speed of the key release.
</DL>

<P>
For portability, use the same note number that started the voice.

</P>
<P>
The voice may have already stopped or decayed.  The release time is an
instrument-specific parameter so the sound may not stop immediately.
Consider adding a delay between the final note and the <CODE>close()</CODE>
method, so the last notes have time to decay before being cut off.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>chn_pressure</B> <I>(dev, voice, pressure)</I>
<DD><A NAME="IDX64"></A>
EVENT Change the channel pressure.
	
<CODE>chn_pressure()</CODE> mimics the pressure used on some MIDI keyboards.
The driver translates pressure into the amount of vibrato in 
OPL-3 voices.  <VAR>pressure</VAR> may be in the range [0,127].
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>panning</B> <I>(dev, voice, pos)</I>
<DD><A NAME="IDX65"></A>
EVENT  Pan the voice between the left and right voice channels.

</P>
<P>
<VAR>pos</VAR> is an integer [-128, 127] where -128 is far left, 0 is
center, and 127 is far right.
	
The pan position is determined by adding <VAR>pos</VAR> to the pan
value stored in the instrument parameters and lasts until
until the note is stopped. The OPL-3 pan value is
simply its volume level.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>control</B> <I>(voice, controller, value)</I>
<DD><A NAME="IDX66"></A>
EVENT Mimic standard MIDI controllers with the synthesizer.

</P>
<P>
The change may be made before starting a note and lasts until the note
is stopped. Once a note is stopped the controller value reverts to its
default.
	
Midi controllers that may be supported are:
<DL COMPACT>

<DT><CODE>CTRL_EXPRESSION</CODE>
<DD>
<A NAME="IDX67"></A>
expression controller of MIDI with values in the range [0,127].

<DT><CODE>CTRL_MAIN_VOLUME</CODE>
<DD>
<A NAME="IDX68"></A>
main volume controller with values in the range [0,100].
</DL>

<P>
Note that these values may have different ranges than their
standard MIDI counterparts.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>bender_range</B> <I>(voice, value)</I>
<DD><A NAME="IDX69"></A>
Define the magnitude of the lowest and highest pitch-bends.
	
<VAR>value</VAR> is in units of cents (1/100 of a semitone).  Although
<VAR>value</VAR> may be set larger, the maximum bend is two octaves (1200
cents or 12 semitones).

</P>
<P>
See <CODE>pitch_bend()</CODE>.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>pitch_bend</B> <I>(voice, value)</I>
<DD><A NAME="IDX70"></A>
EVENT Alter the pitch of a sequencer voice.

</P>
<P>
<VAR>value</VAR> is in the range [-8192, 8191] representing the pitches of
the most extreme low and high bends.

</P>
<P>
The magnitude of the pitch bend is determined by the method
<CODE>bender_range()</CODE>.  If you want *value* to be in units of cents
(1/100 semitone) then call <CODE>bender_range()</CODE> with a value of 8192.

</P>
<P>
The value can be assigned before or after starting the note
and the effect lasts until the note stops.

</P>
<P>
See <CODE>bender_range()</CODE>.

</P>
</DL>

<P>
<DL>
<DT><U>Method:</U> sequencer <B>expression</B> <I>(voice, value)</I>
<DD><A NAME="IDX71"></A>
EVENT Apply an "expression" MIDI controller to a synthesizer voice.
	
???
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> sequencer <B>main_volume</B> <I>(voice, value)</I>
<DD><A NAME="IDX72"></A>
EVENT Apply a "main volume" MIDI controller to a synthesizer voice.

</P>
<P>
???
</DL>

</P>



<H2><A NAME="SEC21" HREF="ossmodule.html#TOC21">synth_info Objects</A></H2>

<P>
A synth_info object is a description of a synthesizer device.

</P>



<H3><A NAME="SEC22" HREF="ossmodule.html#TOC22">synth_info Instantiation</A></H3>

<P>
Typically a sequencer's <CODE>synth_info()</CODE> method creates and returns a
synth_info object.  You can also create a synth_info (for a sequencer to 
fill in) with the module-level function <CODE>synth_info()</CODE>.

</P>
<P>
<DL>
<DT><U>Function:</U> <B>synth_info</B> <I>()</I>
<DD><A NAME="IDX73"></A>
Return a new, uninitialized synth_info object. 
</DL>

</P>


<H3><A NAME="SEC23" HREF="ossmodule.html#TOC23">synth_info Members</A></H3>

<P>
All of these members are read-only except for <CODE>device</CODE>.

</P>
<P>
When a synth_info object is printed, it decodes and displays all of its
members.  This behavior may change in a future release.

</P>
<DL COMPACT>

<DT><CODE>name</CODE>
<DD>
a string containing the name of the device

<DT><CODE>device</CODE>
<DD>
the device number of the synthesizer 
This is used only when this synth_info object is 
passed to a sequencer's <CODE>synth_info()</CODE> method. 

<DT><CODE>synth_type</CODE>
<DD>
integer describing the type of synthesizer.

<DL COMPACT>

<DT><CODE>SYNTH_TYPE_FM</CODE>
<DD>
<A NAME="IDX74"></A>
<DT><CODE>SYNTH_TYPE_SAMPLE</CODE>
<DD>
<A NAME="IDX75"></A>
<DT><CODE>SYNTH_TYPE_MIDI</CODE>
<DD>
<A NAME="IDX76"></A>
</DL>

<DT><CODE>synth_subtype</CODE>
<DD>
integer which may be used to detect the hardware type.

<DT><CODE>nr_voices</CODE>
<DD>
maximum number of voices the device supports in its current mode. If you
change the mode, the value will change also.

</DL>



<H2><A NAME="SEC24" HREF="ossmodule.html#TOC24">midi_info Objects</A></H2>

<P>
A midi_info object describes a MIDI port.

</P>



<H3><A NAME="SEC25" HREF="ossmodule.html#TOC25">midi_info Instantiation</A></H3>

<P>
Typically a sequencer's <CODE>midi_info()</CODE> method creates and returns a
midi_info object.  You can also create a midi_info (for a sequencer to 
fill in) with the module-level function <CODE>midi_info()</CODE>.

</P>
<P>
<DL>
<DT><U>Function:</U> <B>midi_info</B> <I>()</I>
<DD><A NAME="IDX77"></A>
Return a new, uninitialized midi_info object. 
</DL>

</P>


<H3><A NAME="SEC26" HREF="ossmodule.html#TOC26">midi_info Members</A></H3>

<P>
All of these members are read-only except for <CODE>device</CODE>.

</P>
<P>
When a midi_info object is printed, it decodes and displays all of its
members.  This behavior may change in a future release.

</P>
<DL COMPACT>

<DT><CODE>name</CODE>
<DD>
a string containing the name of the device

<DT><CODE>device</CODE>
<DD>
the midi port number, less than sequencer.nrmidis().
This is used only when this midi_info object is 
passed to a sequencer's <CODE>midi_info()</CODE> method. 

<DT><CODE>dev_type</CODE>
<DD>
integer describing the type of sound card where
the MIDI port resides.

See section <A HREF="ossmodule.html#SEC33">Sound Card ID Numbers</A>.

<DT><CODE>capabilities</CODE>
<DD>
bit mask describing some MIDI capabilities?? One mask is defined:

<DL COMPACT>

<DT><CODE>MIDI_CAP_MPU401</CODE>
<DD>
<A NAME="IDX78"></A>
mask
</DL>

</DL>



<H1><A NAME="SEC27" HREF="ossmodule.html#TOC27">Audio Programming</A></H1>



<H2><A NAME="SEC28" HREF="ossmodule.html#TOC28">Audio Formats</A></H2>

<P>
Audio formats are represented by the following module-level bit-flag
values.

</P>
<DL COMPACT>

<DT><CODE>AFMT_MU_LAW</CODE>
<DD>
<A NAME="IDX79"></A>
logarithmic mu-Law (8-bit)
<DT><CODE>AFMT_A_LAW</CODE>
<DD>
<A NAME="IDX80"></A>
logarithmic A-Law  (8-bit)
<DT><CODE>AFMT_IMA_ADPCM</CODE>
<DD>
<A NAME="IDX81"></A>
ADPCM as defined by the Interactive Multimedia Association (IMA).  This
is <EM>not</EM> the Creative ADPCM format. Requires an average of 4 bits
per sample.
<DT><CODE>AFMT_U8</CODE>
<DD>
<A NAME="IDX82"></A>
unsigned 8-bit 
<DT><CODE>AFMT_S16_LE</CODE>
<DD>
<A NAME="IDX83"></A>
signed 16-bit little-endian (Intel)
<DT><CODE>AFMT_S16_BE</CODE>
<DD>
<A NAME="IDX84"></A>
signed 16-bit big-endian (Motorola)
<DT><CODE>AFMT_S8</CODE>
<DD>
<A NAME="IDX85"></A>
unsigned 8-bit
<DT><CODE>AFMT_U16_LE</CODE>
<DD>
<A NAME="IDX86"></A>
unsigned 16-bit little-endian
<DT><CODE>AFMT_U16_BE</CODE>
<DD>
<A NAME="IDX87"></A>
unsigned 16-bit big-endian
<DT><CODE>AFMT_MPEG</CODE>
<DD>
<A NAME="IDX88"></A>
MPEG audio format
</DL>



<H2><A NAME="SEC29" HREF="ossmodule.html#TOC29">audio Objects</A></H2>

<P>
An audio object allows you to play and record digitized audio.

</P>
<P>
You do so by writing and reading samples to the audio device.

</P>
<P>
Please be aware that because Python is not as fast as languages that
are compiled to machine code, you may have difficulty producing
some sounds without output buffer underruns and input overflows.
These may manifest themselves as pauses, clicking, humming, or other
distortions in the sound. 

</P>
<P>
You may have some luck, however, if you use some of the built-in modules
and modules compiled from C. Consider using operations in the
<CODE>array</CODE> and <CODE>audioop</CODE> modules.

</P>
<P>
Before an audio object can be read or written, you must perform 
at least three operations on it:

<OL>
<LI>

Set its sample format with the <CODE>format()</CODE> method.
<LI>

Set the number of channels (mono or stereo) with the <CODE>stereo()</CODE> method.
<LI>

Set the sample rate with the <CODE>speed()</CODE> method.
</OL>

<P>
These operations must be performed in the order presented above.  Please
consult the OSS Programmer's Guide for more information.
 

</P>


<H3><A NAME="SEC30" HREF="ossmodule.html#TOC30">audio Instantiation</A></H3>

<P>
Create an audio object using the module function <CODE>open_audio()</CODE>.

</P>
<P>
An open audio object will be closed before it is deleted.
    
<DL>
<DT><U>Function:</U> <B>open_audio</B> <I>(filename, flags):</I>
<DD><A NAME="IDX89"></A>
Create, open, and return a new audio object.

</P>
<DL COMPACT>

<DT><VAR>filename</VAR>
<DD>
 defaults to <CODE>"/dev/audio"</CODE>.
<DT><VAR>flags</VAR>
<DD>
defaults to <CODE>FCNTL.O_RDWR</CODE>.

Use <CODE>FCNTL.O_WRONLY</CODE> if you intend to only play audio.
Likewise, use <CODE>FCNTL.O_RDONLY</CODE> to only record audio.
</DL>

</DL>



<H3><A NAME="SEC31" HREF="ossmodule.html#TOC31">audio Methods</A></H3>

<P>
<DL>
<DT><U>Method:</U> audio <B>fileno</B> <I>()</I>
<DD><A NAME="IDX90"></A>
Return the file number associated with this audio object.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>close</B> <I>()</I>
<DD><A NAME="IDX91"></A>
Free the resources associated with this audio object.

</P>
<P>
Called on deletion if not called explicitly.  Do not call any
methods of a closed audio object.
	
<CODE>close()</CODE> performs a <CODE>sync()</CODE> operation.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>reset</B> <I>()</I>
<DD><A NAME="IDX92"></A>
Stop the audio device.

</P>
<P>
Once an audio device is reset you may set new format, stereo, and speed
parameters.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>sync</B> <I>()</I>
<DD><A NAME="IDX93"></A>
Wait until the last byte has been played.

</P>
<P>
Once all of the bytes that were written have been played, <CODE>sync()</CODE>
performs a <CODE>reset()</CODE> on the audio device.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>post</B> <I>()</I>
<DD><A NAME="IDX94"></A>
Warn the audio device of a pause in the output.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>format</B> <I>(format_flag)</I>
<DD><A NAME="IDX95"></A>
Select and return the audio format.

</P>
<P>
See section <A HREF="ossmodule.html#SEC28">Audio Formats</A> for valid values of <VAR>format_flag</VAR>.

</P>
<P>
You should check the return value to ensure that the format you
requested is supported.  

</P>
<P>
To check the current audio format, pass <CODE>AFMT_QUERY</CODE> as
<VAR>format</VAR> or use the <CODE>query_format()</CODE> method.

</P>
</DL>

<P>
<DL>
<DT><U>Method:</U> audio <B>get_formats</B> <I>()</I>
<DD><A NAME="IDX96"></A>
Return a mask of all the audio formats supported by this device.

</P>
<P>
See section <A HREF="ossmodule.html#SEC28">Audio Formats</A>.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>query_format</B> <I>()</I>
<DD><A NAME="IDX97"></A>
Return the current audio format.

</P>
<P>
This is a shortcut for <CODE>format(AFMT_QUERY)</CODE>.
See section <A HREF="ossmodule.html#SEC28">Audio Formats</A>.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>stereo</B> <I>(is_stereo)</I>
<DD><A NAME="IDX98"></A>
Set the number of channels. 

</P>
<P>
<VAR>is_stereo</VAR>: 0=mono, 1=stereo
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>channels</B> <I>(num_channels)</I>
<DD><A NAME="IDX99"></A>
Set the number of channels. 

</P>
<P>
<EM>This operation is documented in the OSS manuals, but not implemented
in my version. -twb</EM>

</P>
<P>
<VAR>num_channels</VAR>: 1=mono, 2=stereo
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>speed</B> <I>(sampling_rate)</I>
<DD><A NAME="IDX100"></A>
Set the sampling rate. 

</P>
<P>
Sets and returns the sampling rate that was as close as the device could
get to the requested <VAR>sampling_rate</VAR>.
</DL>

</P>
<P>
<DL>
<DT><U>Method:</U> audio <B>read</B> <I>(bytes_requested)</I>
<DD><A NAME="IDX101"></A>
Record bytes from the audio device. 

</P>
<P>
Returns a string holding the bytes that were read.  This may 
not be the same length as the number of bytes requested.

</P>
<P>
Note that the request is in units of <EM>bytes</EM>, not samples.
For example, if the device is configured for 16-bit stereo, you
should request multiples of four bytes.

</P>
</DL>

<P>
<DL>
<DT><U>Method:</U> audio <B>write</B> <I>(samples)</I>
<DD><A NAME="IDX102"></A>
Play a string of samples.

</P>
<P>
<VAR>samples</VAR> is a string holding the bytes that should be written
to the audio device.

</P>
<P>
Returns the actual number of bytes that were written. This could
be less than the length of <VAR>samples</VAR>.

</P>
<P>
<VAR>samples</VAR> should be a length that is a multiple of the the sample
size (#channels * format size).

</P>
</DL>



<H1><A NAME="SEC32" HREF="ossmodule.html#TOC32">Miscellaneous</A></H1>



<H2><A NAME="SEC33" HREF="ossmodule.html#TOC33">Sound Card ID Numbers</A></H2>

<P>
These module-level variables hold numbers that identify sound cards. 

</P>
<DL COMPACT>

<DT><CODE>SNDCARD_ADLIB</CODE>
<DD>
<A NAME="IDX103"></A>
<DT><CODE>SNDCARD_SB</CODE>
<DD>
<A NAME="IDX104"></A>
<DT><CODE>SNDCARD_PAS</CODE>
<DD>
<A NAME="IDX105"></A>
<DT><CODE>SNDCARD_GUS</CODE>
<DD>
<A NAME="IDX106"></A>
<DT><CODE>SNDCARD_MPU401</CODE>
<DD>
<A NAME="IDX107"></A>
<DT><CODE>SNDCARD_SB16</CODE>
<DD>
<A NAME="IDX108"></A>
<DT><CODE>SNDCARD_SB16MIDI</CODE>
<DD>
<A NAME="IDX109"></A>
<DT><CODE>SNDCARD_UART6850</CODE>
<DD>
<A NAME="IDX110"></A>
<DT><CODE>SNDCARD_GUS16</CODE>
<DD>
<A NAME="IDX111"></A>
<DT><CODE>SNDCARD_MSS</CODE>
<DD>
<A NAME="IDX112"></A>
<DT><CODE>SNDCARD_PSS</CODE>
<DD>
<A NAME="IDX113"></A>
<DT><CODE>SNDCARD_SSCAPE</CODE>
<DD>
<A NAME="IDX114"></A>
<DT><CODE>SNDCARD_PSS_MPU</CODE>
<DD>
<A NAME="IDX115"></A>
<DT><CODE>SNDCARD_PSS_MSS</CODE>
<DD>
<A NAME="IDX116"></A>
<DT><CODE>SNDCARD_SSCAPE_MSS</CODE>
<DD>
<A NAME="IDX117"></A>
<DT><CODE>SNDCARD_TRXPRO</CODE>
<DD>
<A NAME="IDX118"></A>
<DT><CODE>SNDCARD_TRXPRO_SB</CODE>
<DD>
<A NAME="IDX119"></A>
<DT><CODE>SNDCARD_TRXPRO_MPU</CODE>
<DD>
<A NAME="IDX120"></A>
<DT><CODE>SNDCARD_AWE32</CODE>
<DD>
<A NAME="IDX121"></A>
</DL>



<H1><A NAME="SEC34" HREF="ossmodule.html#TOC34">Variable Index</A></H1>
<P>
<H2>a</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX80">AFMT_A_LAW</A>
<LI><A HREF="ossmodule.html#IDX81">AFMT_IMA_ADPCM</A>
<LI><A HREF="ossmodule.html#IDX88">AFMT_MPEG</A>
<LI><A HREF="ossmodule.html#IDX79">AFMT_MU_LAW</A>
<LI><A HREF="ossmodule.html#IDX84">AFMT_S16_BE</A>
<LI><A HREF="ossmodule.html#IDX83">AFMT_S16_LE</A>
<LI><A HREF="ossmodule.html#IDX85">AFMT_S8</A>
<LI><A HREF="ossmodule.html#IDX87">AFMT_U16_BE</A>
<LI><A HREF="ossmodule.html#IDX86">AFMT_U16_LE</A>
<LI><A HREF="ossmodule.html#IDX82">AFMT_U8</A>
</DIR>
<H2>c</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX67">CTRL_EXPRESSION</A>
<LI><A HREF="ossmodule.html#IDX68">CTRL_MAIN_VOLUME</A>
</DIR>
<H2>m</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX78">MIDI_CAP_MPU401</A>
</DIR>
<H2>s</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX103">SNDCARD_ADLIB</A>
<LI><A HREF="ossmodule.html#IDX121">SNDCARD_AWE32</A>
<LI><A HREF="ossmodule.html#IDX106">SNDCARD_GUS</A>
<LI><A HREF="ossmodule.html#IDX111">SNDCARD_GUS16</A>
<LI><A HREF="ossmodule.html#IDX107">SNDCARD_MPU401</A>
<LI><A HREF="ossmodule.html#IDX112">SNDCARD_MSS</A>
<LI><A HREF="ossmodule.html#IDX105">SNDCARD_PAS</A>
<LI><A HREF="ossmodule.html#IDX113">SNDCARD_PSS</A>
<LI><A HREF="ossmodule.html#IDX115">SNDCARD_PSS_MPU</A>
<LI><A HREF="ossmodule.html#IDX116">SNDCARD_PSS_MSS</A>
<LI><A HREF="ossmodule.html#IDX104">SNDCARD_SB</A>
<LI><A HREF="ossmodule.html#IDX108">SNDCARD_SB16</A>
<LI><A HREF="ossmodule.html#IDX109">SNDCARD_SB16MIDI</A>
<LI><A HREF="ossmodule.html#IDX114">SNDCARD_SSCAPE</A>
<LI><A HREF="ossmodule.html#IDX117">SNDCARD_SSCAPE_MSS</A>
<LI><A HREF="ossmodule.html#IDX118">SNDCARD_TRXPRO</A>
<LI><A HREF="ossmodule.html#IDX120">SNDCARD_TRXPRO_MPU</A>
<LI><A HREF="ossmodule.html#IDX119">SNDCARD_TRXPRO_SB</A>
<LI><A HREF="ossmodule.html#IDX110">SNDCARD_UART6850</A>
<LI><A HREF="ossmodule.html#IDX45">SOUND_CAP_EXCL_INPUT</A>
<LI><A HREF="ossmodule.html#IDX36">SOUND_DEVICE_LABELS</A>
<LI><A HREF="ossmodule.html#IDX37">SOUND_DEVICE_NAMES</A>
<LI><A HREF="ossmodule.html#IDX23">SOUND_MASK_ALTPCM</A>
<LI><A HREF="ossmodule.html#IDX5">SOUND_MASK_BASS</A>
<LI><A HREF="ossmodule.html#IDX19">SOUND_MASK_CD</A>
<LI><A HREF="ossmodule.html#IDX27">SOUND_MASK_IGAIN</A>
<LI><A HREF="ossmodule.html#IDX21">SOUND_MASK_IMIX</A>
<LI><A HREF="ossmodule.html#IDX15">SOUND_MASK_LINE</A>
<LI><A HREF="ossmodule.html#IDX31">SOUND_MASK_LINE1</A>
<LI><A HREF="ossmodule.html#IDX33">SOUND_MASK_LINE2</A>
<LI><A HREF="ossmodule.html#IDX35">SOUND_MASK_LINE3</A>
<LI><A HREF="ossmodule.html#IDX17">SOUND_MASK_MIC</A>
<LI><A HREF="ossmodule.html#IDX29">SOUND_MASK_OGAIN</A>
<LI><A HREF="ossmodule.html#IDX11">SOUND_MASK_PCM</A>
<LI><A HREF="ossmodule.html#IDX25">SOUND_MASK_RECLEV</A>
<LI><A HREF="ossmodule.html#IDX13">SOUND_MASK_SPEAKER</A>
<LI><A HREF="ossmodule.html#IDX9">SOUND_MASK_SYNTH</A>
<LI><A HREF="ossmodule.html#IDX7">SOUND_MASK_TREBLE</A>
<LI><A HREF="ossmodule.html#IDX3">SOUND_MASK_VOLUME</A>
<LI><A HREF="ossmodule.html#IDX22">SOUND_MIXER_ALTPCM</A>
<LI><A HREF="ossmodule.html#IDX4">SOUND_MIXER_BASS</A>
<LI><A HREF="ossmodule.html#IDX18">SOUND_MIXER_CD</A>
<LI><A HREF="ossmodule.html#IDX26">SOUND_MIXER_IGAIN</A>
<LI><A HREF="ossmodule.html#IDX20">SOUND_MIXER_IMIX</A>
<LI><A HREF="ossmodule.html#IDX14">SOUND_MIXER_LINE</A>
<LI><A HREF="ossmodule.html#IDX30">SOUND_MIXER_LINE1</A>
<LI><A HREF="ossmodule.html#IDX32">SOUND_MIXER_LINE2</A>
<LI><A HREF="ossmodule.html#IDX34">SOUND_MIXER_LINE3</A>
<LI><A HREF="ossmodule.html#IDX16">SOUND_MIXER_MIC</A>
<LI><A HREF="ossmodule.html#IDX1">SOUND_MIXER_NRDEVICES</A>
<LI><A HREF="ossmodule.html#IDX28">SOUND_MIXER_OGAIN</A>
<LI><A HREF="ossmodule.html#IDX10">SOUND_MIXER_PCM</A>
<LI><A HREF="ossmodule.html#IDX24">SOUND_MIXER_RECLEV</A>
<LI><A HREF="ossmodule.html#IDX12">SOUND_MIXER_SPEAKER</A>
<LI><A HREF="ossmodule.html#IDX8">SOUND_MIXER_SYNTH</A>
<LI><A HREF="ossmodule.html#IDX6">SOUND_MIXER_TREBLE</A>
<LI><A HREF="ossmodule.html#IDX2">SOUND_MIXER_VOLUME</A>
<LI><A HREF="ossmodule.html#IDX74">SYNTH_TYPE_FM</A>
<LI><A HREF="ossmodule.html#IDX76">SYNTH_TYPE_MIDI</A>
<LI><A HREF="ossmodule.html#IDX75">SYNTH_TYPE_SAMPLE</A>
</DIR>

</P>


<H1><A NAME="SEC35" HREF="ossmodule.html#TOC35">Function Index</A></H1>

<P>
<H2>b</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX69">bender_range on sequencer</A>
</DIR>
<H2>c</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX44">caps on mixer</A>
<LI><A HREF="ossmodule.html#IDX99">channels on audio</A>
<LI><A HREF="ossmodule.html#IDX64">chn_pressure on sequencer</A>
<LI><A HREF="ossmodule.html#IDX91">close on audio</A>
<LI><A HREF="ossmodule.html#IDX40">close on mixer</A>
<LI><A HREF="ossmodule.html#IDX52">close on sequencer</A>
<LI><A HREF="ossmodule.html#IDX66">control on sequencer</A>
<LI><A HREF="ossmodule.html#IDX59">ctrlrate on sequencer</A>
</DIR>
<H2>d</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX41">devmask on mixer</A>
</DIR>
<H2>e</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX71">expression on sequencer</A>
</DIR>
<H2>f</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX90">fileno on audio</A>
<LI><A HREF="ossmodule.html#IDX39">fileno on mixer</A>
<LI><A HREF="ossmodule.html#IDX51">fileno on sequencer</A>
<LI><A HREF="ossmodule.html#IDX95">format on audio</A>
</DIR>
<H2>g</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX96">get_formats on audio</A>
</DIR>
<H2>m</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX72">main_volume on sequencer</A>
<LI><A HREF="ossmodule.html#IDX77">midi_info</A>
<LI><A HREF="ossmodule.html#IDX56">midi_info on sequencer</A>
<LI><A HREF="ossmodule.html#IDX60">midiout on sequencer</A>
</DIR>
<H2>n</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX55">nrmidis on sequencer</A>
<LI><A HREF="ossmodule.html#IDX53">nrsynths on sequencer</A>
</DIR>
<H2>o</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX89">open_audio</A>
<LI><A HREF="ossmodule.html#IDX38">open_mixer</A>
<LI><A HREF="ossmodule.html#IDX50">open_sequencer</A>
</DIR>
<H2>p</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX65">panning on sequencer</A>
<LI><A HREF="ossmodule.html#IDX70">pitch_bend on sequencer</A>
<LI><A HREF="ossmodule.html#IDX94">post on audio</A>
</DIR>
<H2>q</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX97">query_format on audio</A>
</DIR>
<H2>r</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX101">read on audio</A>
<LI><A HREF="ossmodule.html#IDX48">read_channel on mixer</A>
<LI><A HREF="ossmodule.html#IDX46">read_recsrc on mixer</A>
<LI><A HREF="ossmodule.html#IDX42">recmask on mixer</A>
<LI><A HREF="ossmodule.html#IDX92">reset on audio</A>
</DIR>
<H2>s</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX61">set_patch on sequencer</A>
<LI><A HREF="ossmodule.html#IDX100">speed on audio</A>
<LI><A HREF="ossmodule.html#IDX62">start_note on sequencer</A>
<LI><A HREF="ossmodule.html#IDX57">start_timer on sequencer</A>
<LI><A HREF="ossmodule.html#IDX98">stereo on audio</A>
<LI><A HREF="ossmodule.html#IDX43">stereodevs on mixer</A>
<LI><A HREF="ossmodule.html#IDX63">stop_note on sequencer</A>
<LI><A HREF="ossmodule.html#IDX93">sync on audio</A>
<LI><A HREF="ossmodule.html#IDX73">synth_info</A>
<LI><A HREF="ossmodule.html#IDX54">synth_info on sequencer</A>
</DIR>
<H2>w</H2>
<DIR>
<LI><A HREF="ossmodule.html#IDX58">wait_time on sequencer</A>
<LI><A HREF="ossmodule.html#IDX102">write on audio</A>
<LI><A HREF="ossmodule.html#IDX49">write_channel on mixer</A>
<LI><A HREF="ossmodule.html#IDX47">write_recsrc on mixer</A>
</DIR>

</P>
<P><HR><P>
This document was generated on 30 July 1997 using the
<A HREF="http://wwwcn.cern.ch/dci/texi2html/">texi2html</A>
translator version 1.51.</P>
</BODY>
</HTML>