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
|
********************************************************************
Python OSS Module - A Python interface to the Open Sound System API
********************************************************************
Public Domain 1997 Timothy Butler
THIS DOCUMENT IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Introduction
************
The oss 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.
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.
Essential References
====================
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.
Open Sound System
http://www.4front-tech.com/oss.html
Open Sound System (OSS) Free
http://www.4front-tech.com/usslite/
OSS Programmer's Guide
http://www.4front-tech.com/pguide/index.html
OSS documentation (contains link to valuable "Hackers Guide to VoxWare")
http://www.4front-tech.com/usslite/docs.html
You can find more information about Python at
Python Home Page
http://www.python.org
Obtaining the oss Module
========================
You can download the oss Module from
http://www.indra.com/~tim/ossmodule
Installation
============
The oss module consists entirely of a single C language source file,
`ossmodule.c'. You must either
1. compile and link the module into the Python interpreter or
2. create and install a shared library in a directory named by your
`PYTHONPATH'.
Linking into the Interpreter
----------------------------
1. Copy `ossmodule.c' into Python's `Modules' directory.
> cp ossmodule.c Python-1.4/Modules
2. Edit `Modules/Setup' and add an entry for the oss module.
oss ossmodule.c -I/usr/include/machine -I/usr/include/sys
You may need to add or change the C preprocessor's search
directories so it can find `soundcard.h' on your system.
You can also create a shared library this way if you place the
module line in the `*shared*' section of the `Setup' file. Read
the comments in the `Setup' file for details.
3. Recompile, test, and install the Python interpreter
> cd Python-1.4
> make
> ./python
>> import oss
>make bininstall
Building a Shared Library
-------------------------
You can use the `Makefile' provided with the oss module distribution
to compile a shared library. You will have to edit the `Makefile' to
match your system. Copy the resulting shared library to a directory
named by your `PYTHONPATH'.
Feedback
========
Please email bug reports and comments concerning the oss module to
`tim@netbox.com'.
I am not qualified to answer questions about the OSS itself. Part of
the reason I wrote the oss module was to create an environment where I
could experiment with and learn about the OSS.
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. *Note
Essential References::.
Design and Implementation
=========================
The C language header file, `sys/soundcard.h', defines the OSS API.
Most of the API consists of macros which define operations and arguments
for the `ioctl()' system call.
The oss module implements only the bare minimum to use the API
including:
Sound device objects.
Represent devices such as a mixer, sequencer, and digital audio
devices. The sound device objects in the oss module store a file
descriptor and their methods typically involve little more than a
call to `ioctl()' with the proper arguments.
Functions that open and return sound device objects.
Module-level variables holding macro "constants".
Bitmasks or device numbers that are ultimately provided as
arguments to the `ioctl()' calls. Many module-level variables
exist in the oss module which correspond to the exact same names
of macro constants in `soundcard.h'. For example the value of
`oss.SOUND_MIXER_NRDEVICES' is the same as `SOUND_MIXER_NRDEVICES'
in `soundcard.h'.
"Structure" objects.
Hold read-only information about system capabilities.
The API operations, such as `SOUND_MIXER_READ_RECMASK', typically
translate into methods of sound device objects, such as
`mixer.read_recmask()'. The correspondence should be clear from the
documentation if not from the names.
None of the objects provided by the oss module can serve as base
classes.
Not every name and data structure provided by `soundcard.h' is
available through the oss module. The oss module provides only the
interface that is described in the official OSS API documentation.
Many parts of `soundcard.h' are either unsupported, obsolete, not
portable, or undocumented.
The MIDI interface and the /dev/sndstat objects are not provided
because these interfaces are simply read and write operations.
The oss module was developed using the OSSFree implementation under
FreeBSD. Your mileage may vary.
Future Development
==================
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.
As a separate project I'd like to add a layer on top of the oss
module (called "possum") that provides graphical interfaces to the sound
devices. MIDI protocol support would be handy also.
Mixer Programming
*****************
Channel Identifiers
===================
Channel Numbers
---------------
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.
`SOUND_MIXER_NRDEVICES'
number of channels known to OSS [0,30]
`SOUND_MIXER_VOLUME'
`SOUND_MASK_VOLUME'
master output level
`SOUND_MIXER_BASS'
`SOUND_MASK_BASS'
bass level of all output channels
`SOUND_MIXER_TREBLE'
`SOUND_MASK_TREBLE'
treble level of all output channels
`SOUND_MIXER_SYNTH'
`SOUND_MASK_SYNTH'
level of synthesizer (e.g. FM, wave-table)
`SOUND_MIXER_PCM'
`SOUND_MASK_PCM'
output level for audio device (/dev/dsp, /dev/audio)
`SOUND_MIXER_SPEAKER'
`SOUND_MASK_SPEAKER'
volume of PC speaker signal routed through card
`SOUND_MIXER_LINE'
`SOUND_MASK_LINE'
level for line-in jack
`SOUND_MIXER_MIC'
`SOUND_MASK_MIC'
input level from microphone jack
`SOUND_MIXER_CD'
`SOUND_MASK_CD'
input level from CD
`SOUND_MIXER_IMIX'
`SOUND_MASK_IMIX'
output (headphone jack) vol for rec monitor (rec only)
`SOUND_MIXER_ALTPCM'
`SOUND_MASK_ALTPCM'
volume of alternative CODEC device
`SOUND_MIXER_RECLEV'
`SOUND_MASK_RECLEV'
global recording level (rec only)
`SOUND_MIXER_IGAIN'
`SOUND_MASK_IGAIN'
??
`SOUND_MIXER_OGAIN'
`SOUND_MASK_OGAIN'
??
`SOUND_MIXER_LINE1'
`SOUND_MASK_LINE1'
vendor specific
`SOUND_MIXER_LINE2'
`SOUND_MASK_LINE2'
vendor specific
`SOUND_MIXER_LINE3'
`SOUND_MASK_LINE3'
vendor specific
Channel Labels
--------------
Two module-level lists, `SOUND_DEVICE_LABELS' and
`SOUND_DEVICE_NAMES', store strings that can be used to name channels.
These lists can be indexed by channel number (e.g.
`SOUND_DEVICE_LABELS[SOUND_MIXER_VOLUME]').
`SOUND_DEVICE_LABELS'
channel names that are suitable for user presentation.
`SOUND_DEVICE_NAMES'
lowercase fixed-size names without spaces.
mixer Objects
=============
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.
Read and write operations on a mixer's file descriptor are undefined
and there are no `read()' or `write()' methods on a mixer.
mixer Instantiation
-------------------
Create an mixer object using the module function `open_mixer()'.
The same mixer device may be opened more than once. An open mixer
object will be closed before it is deleted.
- Function: open_mixer (FILENAME, FLAGS)
Create, open, and return a new mixer object.
FILENAME
defaults to `"/dev/mixer"'.
FLAGS
defaults to `FCNTL.O_RDWR'.
mixer Methods
-------------
- Method on mixer: fileno ()
Return the file number associated with this mixer.
- Method on mixer: close ()
Free the resources associated with this mixer.
Called on deletion if not called explicitly. Do not call any
methods of a closed mixer.
- Method on mixer: devmask ()
Return a bitmask of available mixer channels.
- Method on mixer: recmask ()
Return a bitmask of channels that may be used as recording sources.
- Method on mixer: stereodevs ()
Return a bitmask of stereo channels.
- Method on mixer: caps ()
Return a bitmask describing the general capabilities of a mixer.
Currently, the module-level constant mask `SOUND_CAP_EXCL_INPUT' is
the only mixer capability defined.
`SOUND_CAP_EXCL_INPUT'
If this bit is set to 1, then only one mixer channel can be
selected at the same time.
- Method on mixer: read_recsrc ()
Return a bitmask of active recording sources.
- Method on mixer: write_recsrc (MASK)
Select recording source channels with a bitmask.
If MASK is zero, then the mic input will be used.
- Method on mixer: read_channel (CHANNEL_NUM)
Return the level (volume) of a channel.
The volume is returned as a tuple, ( LEFT, RIGHT ), representing
the level of both stereo channels. For mono devices, only LEFT is
valid, (the right channel value is set to the left).
Levels are between 0 (off) and 100 (maximum), inclusive.
- Method on mixer: write_channel (CHANNEL_NUM, LEVEL)
Set the level (volume) of a channel.
LEVEL may be either a single integer or a tuple (LEFT, RIGHT) with
values from 0 (off) to 100 (maximum), inclusive.
If LEVEL is a single integer, it is applied to just a mono channel
or both sides of a stereo channel.
If LEVEL 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.
`write_channel()' 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 *not* be exactly the same as what
was requested. See the OSS developer's guide for details.
Sequencer Programming
*********************
sequencer Objects
=================
The sequencer object controls the on-board synthesizer using
MIDI-like commands and allows I/O through MIDI ports.
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 `note_on()' and
`chn_pressure()' but these do not send bytes out the MIDI port.
Instead, they only mimic similar effects with the synthesizers.
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 `read()' or `write()' methods on a mixer.
Many methods of a sequencer generate an "event" (synthesizer command
or a MIDI byte) that is written immediately to a buffer in the oss
module. As the buffer fills, events will eventually be passed to the
driver's queue. The sequencer `dump_buf()' 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 `wait_time()' 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 `dump_buf()'.
sequencer Instantiation
-----------------------
Create an sequencer object using the module function
`open_sequencer()'. Only one sequencer may be open at a time; even
within the same application.
An open sequencer object will be closed before it is deleted.
- Function: open_sequencer (FILENAME, FLAGS):
Create, open, and return a new sequencer object.
FILENAME
defaults to `"/dev/sequencer"'.
FLAGS
defaults to `FCNTL.O_RDWR'.
Use `FCNTL.O_WRONLY' for an output-only program so unnecessary
functions like MIDI input aren't initialized. Likewise, use
`FCNTL.O_RDONLY' for input-only programs.
sequencer Methods
-----------------
- Method on sequencer: fileno ()
Return the file number associated with this sequencer.
- Method on sequencer: close ()
Free the resources associated with this sequencer.
Called on deletion if not called explicitly. Do not call any
methods of a closed sequencer.
`close()' shuts off all synthesizer sounds immediately, so you
might want to add an extra delay before closing this device.
- Method on sequencer: nrsynths ()
Return the number of internal synthesizer devices.
- Method on sequencer: synth_info (OBJ)
Describe a specific synthesizer.
OBJ may be either an integer device number or a synth_info object
with its `device' member initialized.
If OBJ is an integer then return a new synth_info object
describing the device. If OBJ is an existing synth_info then it
is filled in with the description and returned.
You must provide a device number that is less than the value
returned by the method `nrsynths()'.
*Note synth_info Objects::
- Method on sequencer: nrmidis ()
Return the number of MIDI ports available.
- Method on sequencer: midi_info (OBJ)
Describe a specific MIDI port.
OBJ may be either an integer port number or a midi_info object
with its `device' member initialized to the desired MIDI port.
If OBJ is an integer then return a new midi_info object describing
the port. If OBJ is an existing midi_info then it is filled in
with the description and returned.
You must provide a port number that is less than the value
returned by the `nrmidis()' method.
*Note midi_info Objects::.
- Method on sequencer: start_timer ()
EVENT Reset the sequencer's timer.
Note that this method generates an *event* that will be processed
only when it makes it to the head of the queue.
The timer may not be restarted immediately.
- Method on sequencer: wait_time (TIME)
EVENT Pause the sequencer until TIME.
TIME 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.
Use the `ctrlrate()' method to determine the actual timer
resolution.
- Method on sequencer: ctrlrate ()
Return the timer resolution in ticks per second.
- Method on sequencer: midiout (MIDI_DEV, BYTE)
EVENT Write a byte to a MIDI port.
MIDI_DEV
the MIDI port number.
BYTE
either an integer or a single character that is the byte to
output.
- Method on sequencer: set_patch (DEV, VOICE, PATCH)
EVENT Assign synthesizer instrument number (patch) to a voice.
- Method on sequencer: start_note (DEV, VOICE, NOTE, VEL=64)
EVENT Start a voice on a synthesizer device.
NOTE
VEL
valid MIDI note number and velocity values, [0,127].
Some synthesizers support adjusting the volume of a note (rather
than starting a new note) with a NOTE value of 255. A VEL of 255
may specify a volume stored in some synthesizers' internal tables.
The use of these values is not portable.
- Method on sequencer: stop_note (DEV, VOICE, NOTE, VEL=64)
EVENT Stop the synthesizer note being played.
NOTE
the MIDI note number
VEL
the speed of the key release.
For portability, use the same note number that started the voice.
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 `close()' method, so the last notes have time to decay before
being cut off.
- Method on sequencer: chn_pressure (DEV, VOICE, PRESSURE)
EVENT Change the channel pressure.
`chn_pressure()' mimics the pressure used on some MIDI keyboards.
The driver translates pressure into the amount of vibrato in OPL-3
voices. PRESSURE may be in the range [0,127].
- Method on sequencer: panning (DEV, VOICE, POS)
EVENT Pan the voice between the left and right voice channels.
POS 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 POS 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.
- Method on sequencer: control (VOICE, CONTROLLER, VALUE)
EVENT Mimic standard MIDI controllers with the synthesizer.
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:
`CTRL_EXPRESSION'
expression controller of MIDI with values in the range
[0,127].
`CTRL_MAIN_VOLUME'
main volume controller with values in the range [0,100].
Note that these values may have different ranges than their
standard MIDI counterparts.
- Method on sequencer: bender_range (VOICE, VALUE)
Define the magnitude of the lowest and highest pitch-bends.
VALUE is in units of cents (1/100 of a semitone). Although VALUE
may be set larger, the maximum bend is two octaves (1200 cents or
12 semitones).
See `pitch_bend()'.
- Method on sequencer: pitch_bend (VOICE, VALUE)
EVENT Alter the pitch of a sequencer voice.
VALUE is in the range [-8192, 8191] representing the pitches of
the most extreme low and high bends.
The magnitude of the pitch bend is determined by the method
`bender_range()'. If you want *value* to be in units of cents
(1/100 semitone) then call `bender_range()' with a value of 8192.
The value can be assigned before or after starting the note and
the effect lasts until the note stops.
See `bender_range()'.
- Method on sequencer: expression (VOICE, VALUE)
EVENT Apply an "expression" MIDI controller to a synthesizer voice.
???
- Method on sequencer: main_volume (VOICE, VALUE)
EVENT Apply a "main volume" MIDI controller to a synthesizer voice.
???
synth_info Objects
==================
A synth_info object is a description of a synthesizer device.
synth_info Instantiation
------------------------
Typically a sequencer's `synth_info()' 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 `synth_info()'.
- Function: synth_info ()
Return a new, uninitialized synth_info object.
synth_info Members
------------------
All of these members are read-only except for `device'.
When a synth_info object is printed, it decodes and displays all of
its members. This behavior may change in a future release.
`name'
a string containing the name of the device
`device'
the device number of the synthesizer This is used only when this
synth_info object is passed to a sequencer's `synth_info()' method.
`synth_type'
integer describing the type of synthesizer.
`SYNTH_TYPE_FM'
`SYNTH_TYPE_SAMPLE'
`SYNTH_TYPE_MIDI'
`synth_subtype'
integer which may be used to detect the hardware type.
`nr_voices'
maximum number of voices the device supports in its current mode.
If you change the mode, the value will change also.
midi_info Objects
=================
A midi_info object describes a MIDI port.
midi_info Instantiation
-----------------------
Typically a sequencer's `midi_info()' 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 `midi_info()'.
- Function: midi_info ()
Return a new, uninitialized midi_info object.
midi_info Members
-----------------
All of these members are read-only except for `device'.
When a midi_info object is printed, it decodes and displays all of
its members. This behavior may change in a future release.
`name'
a string containing the name of the device
`device'
the midi port number, less than sequencer.nrmidis(). This is used
only when this midi_info object is passed to a sequencer's
`midi_info()' method.
`dev_type'
integer describing the type of sound card where the MIDI port
resides.
*Note Sound Card ID Numbers::.
`capabilities'
bit mask describing some MIDI capabilities?? One mask is defined:
`MIDI_CAP_MPU401'
mask
Audio Programming
*****************
Audio Formats
=============
Audio formats are represented by the following module-level bit-flag
values.
`AFMT_MU_LAW'
logarithmic mu-Law (8-bit)
`AFMT_A_LAW'
logarithmic A-Law (8-bit)
`AFMT_IMA_ADPCM'
ADPCM as defined by the Interactive Multimedia Association (IMA).
This is *not* the Creative ADPCM format. Requires an average of 4
bits per sample.
`AFMT_U8'
unsigned 8-bit
`AFMT_S16_LE'
signed 16-bit little-endian (Intel)
`AFMT_S16_BE'
signed 16-bit big-endian (Motorola)
`AFMT_S8'
unsigned 8-bit
`AFMT_U16_LE'
unsigned 16-bit little-endian
`AFMT_U16_BE'
unsigned 16-bit big-endian
`AFMT_MPEG'
MPEG audio format
audio Objects
=============
An audio object allows you to play and record digitized audio.
You do so by writing and reading samples to the audio device.
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.
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
`array' and `audioop' modules.
Before an audio object can be read or written, you must perform at
least three operations on it:
1. Set its sample format with the `format()' method.
2. Set the number of channels (mono or stereo) with the `stereo()'
method.
3. Set the sample rate with the `speed()' method.
These operations must be performed in the order presented above.
Please consult the OSS Programmer's Guide for more information.
audio Instantiation
-------------------
Create an audio object using the module function `open_audio()'.
An open audio object will be closed before it is deleted.
- Function: open_audio (FILENAME, FLAGS):
Create, open, and return a new audio object.
FILENAME
defaults to `"/dev/audio"'.
FLAGS
defaults to `FCNTL.O_RDWR'.
Use `FCNTL.O_WRONLY' if you intend to only play audio.
Likewise, use `FCNTL.O_RDONLY' to only record audio.
audio Methods
-------------
- Method on audio: fileno ()
Return the file number associated with this audio object.
- Method on audio: close ()
Free the resources associated with this audio object.
Called on deletion if not called explicitly. Do not call any
methods of a closed audio object.
`close()' performs a `sync()' operation.
- Method on audio: reset ()
Stop the audio device.
Once an audio device is reset you may set new format, stereo, and
speed parameters.
- Method on audio: sync ()
Wait until the last byte has been played.
Once all of the bytes that were written have been played, `sync()'
performs a `reset()' on the audio device.
- Method on audio: post ()
Warn the audio device of a pause in the output.
- Method on audio: format (FORMAT_FLAG)
Select and return the audio format.
*Note Audio Formats:: for valid values of FORMAT_FLAG.
You should check the return value to ensure that the format you
requested is supported.
To check the current audio format, pass `AFMT_QUERY' as FORMAT or
use the `query_format()' method.
- Method on audio: get_formats ()
Return a mask of all the audio formats supported by this device.
*Note Audio Formats::.
- Method on audio: query_format ()
Return the current audio format.
This is a shortcut for `format(AFMT_QUERY)'. *Note Audio
Formats::.
- Method on audio: stereo (IS_STEREO)
Set the number of channels.
IS_STEREO: 0=mono, 1=stereo
- Method on audio: channels (NUM_CHANNELS)
Set the number of channels.
*This operation is documented in the OSS manuals, but not
implemented in my version. -twb*
NUM_CHANNELS: 1=mono, 2=stereo
- Method on audio: speed (SAMPLING_RATE)
Set the sampling rate.
Sets and returns the sampling rate that was as close as the device
could get to the requested SAMPLING_RATE.
- Method on audio: read (BYTES_REQUESTED)
Record bytes from the audio device.
Returns a string holding the bytes that were read. This may not
be the same length as the number of bytes requested.
Note that the request is in units of *bytes*, not samples. For
example, if the device is configured for 16-bit stereo, you should
request multiples of four bytes.
- Method on audio: write (SAMPLES)
Play a string of samples.
SAMPLES is a string holding the bytes that should be written to
the audio device.
Returns the actual number of bytes that were written. This could
be less than the length of SAMPLES.
SAMPLES should be a length that is a multiple of the the sample
size (#channels * format size).
Miscellaneous
*************
Sound Card ID Numbers
=====================
These module-level variables hold numbers that identify sound cards.
`SNDCARD_ADLIB'
`SNDCARD_SB'
`SNDCARD_PAS'
`SNDCARD_GUS'
`SNDCARD_MPU401'
`SNDCARD_SB16'
`SNDCARD_SB16MIDI'
`SNDCARD_UART6850'
`SNDCARD_GUS16'
`SNDCARD_MSS'
`SNDCARD_PSS'
`SNDCARD_SSCAPE'
`SNDCARD_PSS_MPU'
`SNDCARD_PSS_MSS'
`SNDCARD_SSCAPE_MSS'
`SNDCARD_TRXPRO'
`SNDCARD_TRXPRO_SB'
`SNDCARD_TRXPRO_MPU'
`SNDCARD_AWE32'
Variable Index
**************
* Menu:
* AFMT_A_LAW: Audio Formats.
* AFMT_IMA_ADPCM: Audio Formats.
* AFMT_MPEG: Audio Formats.
* AFMT_MU_LAW: Audio Formats.
* AFMT_S16_BE: Audio Formats.
* AFMT_S16_LE: Audio Formats.
* AFMT_S8: Audio Formats.
* AFMT_U16_BE: Audio Formats.
* AFMT_U16_LE: Audio Formats.
* AFMT_U8: Audio Formats.
* CTRL_EXPRESSION: sequencer Methods.
* CTRL_MAIN_VOLUME: sequencer Methods.
* MIDI_CAP_MPU401: midi_info Members.
* SNDCARD_ADLIB: Sound Card ID Numbers.
* SNDCARD_AWE32: Sound Card ID Numbers.
* SNDCARD_GUS: Sound Card ID Numbers.
* SNDCARD_GUS16: Sound Card ID Numbers.
* SNDCARD_MPU401: Sound Card ID Numbers.
* SNDCARD_MSS: Sound Card ID Numbers.
* SNDCARD_PAS: Sound Card ID Numbers.
* SNDCARD_PSS: Sound Card ID Numbers.
* SNDCARD_PSS_MPU: Sound Card ID Numbers.
* SNDCARD_PSS_MSS: Sound Card ID Numbers.
* SNDCARD_SB: Sound Card ID Numbers.
* SNDCARD_SB16: Sound Card ID Numbers.
* SNDCARD_SB16MIDI: Sound Card ID Numbers.
* SNDCARD_SSCAPE: Sound Card ID Numbers.
* SNDCARD_SSCAPE_MSS: Sound Card ID Numbers.
* SNDCARD_TRXPRO: Sound Card ID Numbers.
* SNDCARD_TRXPRO_MPU: Sound Card ID Numbers.
* SNDCARD_TRXPRO_SB: Sound Card ID Numbers.
* SNDCARD_UART6850: Sound Card ID Numbers.
* SOUND_CAP_EXCL_INPUT: mixer Methods.
* SOUND_DEVICE_LABELS: Channel Labels.
* SOUND_DEVICE_NAMES: Channel Labels.
* SOUND_MASK_ALTPCM: Channel Numbers.
* SOUND_MASK_BASS: Channel Numbers.
* SOUND_MASK_CD: Channel Numbers.
* SOUND_MASK_IGAIN: Channel Numbers.
* SOUND_MASK_IMIX: Channel Numbers.
* SOUND_MASK_LINE: Channel Numbers.
* SOUND_MASK_LINE1: Channel Numbers.
* SOUND_MASK_LINE2: Channel Numbers.
* SOUND_MASK_LINE3: Channel Numbers.
* SOUND_MASK_MIC: Channel Numbers.
* SOUND_MASK_OGAIN: Channel Numbers.
* SOUND_MASK_PCM: Channel Numbers.
* SOUND_MASK_RECLEV: Channel Numbers.
* SOUND_MASK_SPEAKER: Channel Numbers.
* SOUND_MASK_SYNTH: Channel Numbers.
* SOUND_MASK_TREBLE: Channel Numbers.
* SOUND_MASK_VOLUME: Channel Numbers.
* SOUND_MIXER_ALTPCM: Channel Numbers.
* SOUND_MIXER_BASS: Channel Numbers.
* SOUND_MIXER_CD: Channel Numbers.
* SOUND_MIXER_IGAIN: Channel Numbers.
* SOUND_MIXER_IMIX: Channel Numbers.
* SOUND_MIXER_LINE: Channel Numbers.
* SOUND_MIXER_LINE1: Channel Numbers.
* SOUND_MIXER_LINE2: Channel Numbers.
* SOUND_MIXER_LINE3: Channel Numbers.
* SOUND_MIXER_MIC: Channel Numbers.
* SOUND_MIXER_NRDEVICES: Channel Numbers.
* SOUND_MIXER_OGAIN: Channel Numbers.
* SOUND_MIXER_PCM: Channel Numbers.
* SOUND_MIXER_RECLEV: Channel Numbers.
* SOUND_MIXER_SPEAKER: Channel Numbers.
* SOUND_MIXER_SYNTH: Channel Numbers.
* SOUND_MIXER_TREBLE: Channel Numbers.
* SOUND_MIXER_VOLUME: Channel Numbers.
* SYNTH_TYPE_FM: synth_info Members.
* SYNTH_TYPE_MIDI: synth_info Members.
* SYNTH_TYPE_SAMPLE: synth_info Members.
Function Index
**************
* Menu:
* bender_range on sequencer: sequencer Methods.
* caps on mixer: mixer Methods.
* channels on audio: audio Methods.
* chn_pressure on sequencer: sequencer Methods.
* close on audio: audio Methods.
* close on mixer: mixer Methods.
* close on sequencer: sequencer Methods.
* control on sequencer: sequencer Methods.
* ctrlrate on sequencer: sequencer Methods.
* devmask on mixer: mixer Methods.
* expression on sequencer: sequencer Methods.
* fileno on audio: audio Methods.
* fileno on mixer: mixer Methods.
* fileno on sequencer: sequencer Methods.
* format on audio: audio Methods.
* get_formats on audio: audio Methods.
* main_volume on sequencer: sequencer Methods.
* midi_info: midi_info Instantiation.
* midi_info on sequencer: sequencer Methods.
* midiout on sequencer: sequencer Methods.
* nrmidis on sequencer: sequencer Methods.
* nrsynths on sequencer: sequencer Methods.
* open_audio: audio Instantiation.
* open_mixer: mixer Instantiation.
* open_sequencer: sequencer Instantiation.
* panning on sequencer: sequencer Methods.
* pitch_bend on sequencer: sequencer Methods.
* post on audio: audio Methods.
* query_format on audio: audio Methods.
* read on audio: audio Methods.
* read_channel on mixer: mixer Methods.
* read_recsrc on mixer: mixer Methods.
* recmask on mixer: mixer Methods.
* reset on audio: audio Methods.
* set_patch on sequencer: sequencer Methods.
* speed on audio: audio Methods.
* start_note on sequencer: sequencer Methods.
* start_timer on sequencer: sequencer Methods.
* stereo on audio: audio Methods.
* stereodevs on mixer: mixer Methods.
* stop_note on sequencer: sequencer Methods.
* sync on audio: audio Methods.
* synth_info: synth_info Instantiation.
* synth_info on sequencer: sequencer Methods.
* wait_time on sequencer: sequencer Methods.
* write on audio: audio Methods.
* write_channel on mixer: mixer Methods.
* write_recsrc on mixer: mixer Methods.
|