aifc.py, sunau.py: Adapted comments; added access statements.

SUNAUDIODEV.py: Added some constants for Solaris.
This commit is contained in:
Sjoerd Mullender 1993-12-20 09:36:01 +00:00
parent 6ed9df2641
commit 2a45141741
4 changed files with 84 additions and 42 deletions

View File

@ -55,9 +55,7 @@
#
# Reading AIFF files:
# f = aifc.open(file, 'r')
# or
# f = aifc.openfp(filep, 'r')
# where file is the name of a file and filep is an open file pointer.
# where file is either the name of a file or an open file pointer.
# The open file pointer must have methods read(), seek(), and close().
# In some types of audio files, if the setpos() method is not used,
# the seek() method is not necessary.
@ -90,9 +88,7 @@
#
# Writing AIFF files:
# f = aifc.open(file, 'w')
# or
# f = aifc.openfp(filep, 'w')
# where file is the name of a file and filep is an open file pointer.
# where file is either the name of a file or an open file pointer.
# The open file pointer must have methods write(), tell(), seek(), and
# close().
#
@ -361,6 +357,12 @@ class Aifc_read:
# file for readframes()
# _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
# _framesize -- size of one frame in the file
access _file, _nchannels, _nframes, _sampwidth, _framerate, \
_comptype, _compname, _markers, _soundpos, _version, \
_decomp, _comm_chunk_read, __aifc, _ssnd_seek_needed, \
_ssnd_chunk, _framesize: private
def initfp(self, file):
self._file = file
self._version = 0
@ -524,6 +526,8 @@ class Aifc_read:
#
# Internal methods.
#
access *: private
def _decomp_data(self, data):
dummy = self._decomp.SetParam(CL.FRAME_BUFFER_SIZE,
len(data) * 2)
@ -635,13 +639,17 @@ class Aifc_write:
# _datalength -- the size of the audio samples written to the header
# _datawritten -- the size of the audio samples actually written
access _file, _comptype, _compname, _nchannels, _sampwidth, \
_framerate, _nframes, _aifc, _version, _comp, \
_nframeswritten, _datalength, _datawritten: private
def __init__(self, f):
if type(f) == type(''):
filename = f
f = builtin.open(f, 'w')
else:
# else, assume it is an open file object already
filename = '???'
# else, assume it is an open file object already
self.initfp(f)
if filename[-5:] == '.aiff':
self._aifc = 0
@ -826,6 +834,8 @@ class Aifc_write:
#
# Internal methods.
#
access *: private
def _comp_data(self, data):
dum = self._comp.SetParam(CL.FRAME_BUFFER_SIZE, len(data))
dum = self._comp.SetParam(CL.COMPRESSED_BUFFER_SIZE, len(data))
@ -987,6 +997,6 @@ def open(f, mode):
elif mode == 'w':
return Aifc_write(f)
else:
raise Error, 'mode must be \'r\' or \'w\''
raise Error, "mode must be 'r' or 'w'"
openfp = open # B/W compatibility

View File

@ -2,15 +2,26 @@
# The names are the same as in audioio.h with the leading AUDIO_
# removed.
# Not all values are supported on all releases of SunOS.
# Encoding types, for fields i_encoding and o_encoding
ENCODING_ULAW = 1
ENCODING_ALAW = 2
ENCODING_NONE = 0 # no encoding assigned
ENCODING_ULAW = 1 # u-law encoding
ENCODING_ALAW = 2 # A-law encoding
ENCODING_LINEAR = 3 # Linear PCM encoding
# Gain ranges for i_gain, o_gain and monitor_gain
MIN_GAIN = 0
MAX_GAIN = 255
MIN_GAIN = 0 # minimum gain value
MAX_GAIN = 255 # maximum gain value
# Balance values for i_balance and o_balance
LEFT_BALANCE = 0 # left channel only
MID_BALANCE = 32 # equal left/right channel
RIGHT_BALANCE = 64 # right channel only
BALANCE_SHIFT = 3
# Port names for i_port and o_port
@ -19,7 +30,9 @@ PORT_B = 2
PORT_C = 3
PORT_D = 4
SPEAKER = PORT_A
HEADPHONE = PORT_B
SPEAKER = 0x01 # output to built-in speaker
HEADPHONE = 0x02 # output to headphone jack
LINE_OUT = 0x04 # output to line out
MICROPHONE = PORT_A
MICROPHONE = 0x01 # input from microphone
LINE_IN = 0x02 # input from line in

View File

@ -37,9 +37,7 @@
#
# Reading audio files:
# f = au.open(file, 'r')
# or
# f = au.openfp(filep, 'r')
# where file is the name of a file and filep is an open file pointer.
# where file is either the name of a file or an open file pointer.
# The open file pointer must have methods read(), seek(), and close().
# When the setpos() and rewind() methods are not used, the seek()
# method is not necessary.
@ -72,9 +70,7 @@
#
# Writing audio files:
# f = au.open(file, 'w')
# or
# f = au.openfp(filep, 'w')
# where file is the name of a file and filep is an open file pointer.
# where file is either the name of a file or an open file pointer.
# The open file pointer must have methods write(), tell(), seek(), and
# close().
#
@ -151,6 +147,20 @@ def _write_u32(file, x):
file.write(chr(int(data[i])))
class Au_read:
access _file, _soundpos, _hdr_size, _data_size, _encoding, \
_sampwidth, _framesize, _framerate, _nchannels, \
_framesize, _info: private
def __init__(self, f):
if type(f) == type(''):
import builtin
f = builtin.open(f, 'r')
self.initfp(f)
def __del__(self):
if self._file:
self.close()
def initfp(self, file):
self._file = file
self._soundpos = 0
@ -193,16 +203,6 @@ class Au_read:
else:
self._info = ''
def __init__(self, f):
if type(f) == type(''):
import builtin
f = builtin.open(f, 'r')
self.initfp(f)
def __del__(self):
if self._file:
self.close()
def getfp(self):
return self._file
@ -278,12 +278,20 @@ class Au_read:
self._file = None
class Au_write:
access _file, _framerate, _nchannels, _sampwidth, _framesize, \
_nframes, _nframeswritten, _datawritten, _info, \
_comptype: private
def __init__(self, f):
if type(f) == type(''):
import builtin
f = builtin.open(f, 'w')
self.initfp(f)
def __del__(self):
if self._file:
self.close()
def initfp(self, file):
self._file = file
self._framerate = 0
@ -297,10 +305,6 @@ class Au_write:
self._info = ''
self._comptype = 'ULAW' # default is U-law
def __del__(self):
if self._file:
self.close()
def setnchannels(self, nchannels):
if self._nframeswritten:
raise Error, 'cannot change parameters after starting to write'
@ -404,6 +408,8 @@ class Au_write:
#
# private methods
#
access *: private
def _ensure_header_written(self):
if not self._nframeswritten:
if not self._nchannels:

View File

@ -2,15 +2,26 @@
# The names are the same as in audioio.h with the leading AUDIO_
# removed.
# Not all values are supported on all releases of SunOS.
# Encoding types, for fields i_encoding and o_encoding
ENCODING_ULAW = 1
ENCODING_ALAW = 2
ENCODING_NONE = 0 # no encoding assigned
ENCODING_ULAW = 1 # u-law encoding
ENCODING_ALAW = 2 # A-law encoding
ENCODING_LINEAR = 3 # Linear PCM encoding
# Gain ranges for i_gain, o_gain and monitor_gain
MIN_GAIN = 0
MAX_GAIN = 255
MIN_GAIN = 0 # minimum gain value
MAX_GAIN = 255 # maximum gain value
# Balance values for i_balance and o_balance
LEFT_BALANCE = 0 # left channel only
MID_BALANCE = 32 # equal left/right channel
RIGHT_BALANCE = 64 # right channel only
BALANCE_SHIFT = 3
# Port names for i_port and o_port
@ -19,7 +30,9 @@ PORT_B = 2
PORT_C = 3
PORT_D = 4
SPEAKER = PORT_A
HEADPHONE = PORT_B
SPEAKER = 0x01 # output to built-in speaker
HEADPHONE = 0x02 # output to headphone jack
LINE_OUT = 0x04 # output to line out
MICROPHONE = PORT_A
MICROPHONE = 0x01 # input from microphone
LINE_IN = 0x02 # input from line in