Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a45141

Browse files
aifc.py, sunau.py: Adapted comments; added access statements.
SUNAUDIODEV.py: Added some constants for Solaris.
1 parent 6ed9df2 commit 2a45141

4 files changed

Lines changed: 84 additions & 42 deletions

File tree

Lib/aifc.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
#
5656
# Reading AIFF files:
5757
# f = aifc.open(file, 'r')
58-
# or
59-
# f = aifc.openfp(filep, 'r')
60-
# where file is the name of a file and filep is an open file pointer.
58+
# where file is either the name of a file or an open file pointer.
6159
# The open file pointer must have methods read(), seek(), and close().
6260
# In some types of audio files, if the setpos() method is not used,
6361
# the seek() method is not necessary.
@@ -90,9 +88,7 @@
9088
#
9189
# Writing AIFF files:
9290
# f = aifc.open(file, 'w')
93-
# or
94-
# f = aifc.openfp(filep, 'w')
95-
# where file is the name of a file and filep is an open file pointer.
91+
# where file is either the name of a file or an open file pointer.
9692
# The open file pointer must have methods write(), tell(), seek(), and
9793
# close().
9894
#
@@ -361,6 +357,12 @@ class Aifc_read:
361357
# file for readframes()
362358
# _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
363359
# _framesize -- size of one frame in the file
360+
361+
access _file, _nchannels, _nframes, _sampwidth, _framerate, \
362+
_comptype, _compname, _markers, _soundpos, _version, \
363+
_decomp, _comm_chunk_read, __aifc, _ssnd_seek_needed, \
364+
_ssnd_chunk, _framesize: private
365+
364366
def initfp(self, file):
365367
self._file = file
366368
self._version = 0
@@ -524,6 +526,8 @@ def readframes(self, nframes):
524526
#
525527
# Internal methods.
526528
#
529+
access *: private
530+
527531
def _decomp_data(self, data):
528532
dummy = self._decomp.SetParam(CL.FRAME_BUFFER_SIZE,
529533
len(data) * 2)
@@ -635,13 +639,17 @@ class Aifc_write:
635639
# _datalength -- the size of the audio samples written to the header
636640
# _datawritten -- the size of the audio samples actually written
637641

642+
access _file, _comptype, _compname, _nchannels, _sampwidth, \
643+
_framerate, _nframes, _aifc, _version, _comp, \
644+
_nframeswritten, _datalength, _datawritten: private
645+
638646
def __init__(self, f):
639647
if type(f) == type(''):
640648
filename = f
641649
f = builtin.open(f, 'w')
642650
else:
651+
# else, assume it is an open file object already
643652
filename = '???'
644-
# else, assume it is an open file object already
645653
self.initfp(f)
646654
if filename[-5:] == '.aiff':
647655
self._aifc = 0
@@ -826,6 +834,8 @@ def close(self):
826834
#
827835
# Internal methods.
828836
#
837+
access *: private
838+
829839
def _comp_data(self, data):
830840
dum = self._comp.SetParam(CL.FRAME_BUFFER_SIZE, len(data))
831841
dum = self._comp.SetParam(CL.COMPRESSED_BUFFER_SIZE, len(data))
@@ -987,6 +997,6 @@ def open(f, mode):
987997
elif mode == 'w':
988998
return Aifc_write(f)
989999
else:
990-
raise Error, 'mode must be \'r\' or \'w\''
1000+
raise Error, "mode must be 'r' or 'w'"
9911001

9921002
openfp = open # B/W compatibility

Lib/plat-sunos4/SUNAUDIODEV.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22
# The names are the same as in audioio.h with the leading AUDIO_
33
# removed.
44

5+
# Not all values are supported on all releases of SunOS.
6+
57
# Encoding types, for fields i_encoding and o_encoding
68

7-
ENCODING_ULAW = 1
8-
ENCODING_ALAW = 2
9+
ENCODING_NONE = 0 # no encoding assigned
10+
ENCODING_ULAW = 1 # u-law encoding
11+
ENCODING_ALAW = 2 # A-law encoding
12+
ENCODING_LINEAR = 3 # Linear PCM encoding
913

1014
# Gain ranges for i_gain, o_gain and monitor_gain
1115

12-
MIN_GAIN = 0
13-
MAX_GAIN = 255
16+
MIN_GAIN = 0 # minimum gain value
17+
MAX_GAIN = 255 # maximum gain value
18+
19+
# Balance values for i_balance and o_balance
20+
21+
LEFT_BALANCE = 0 # left channel only
22+
MID_BALANCE = 32 # equal left/right channel
23+
RIGHT_BALANCE = 64 # right channel only
24+
BALANCE_SHIFT = 3
1425

1526
# Port names for i_port and o_port
1627

@@ -19,7 +30,9 @@
1930
PORT_C = 3
2031
PORT_D = 4
2132

22-
SPEAKER = PORT_A
23-
HEADPHONE = PORT_B
33+
SPEAKER = 0x01 # output to built-in speaker
34+
HEADPHONE = 0x02 # output to headphone jack
35+
LINE_OUT = 0x04 # output to line out
2436

25-
MICROPHONE = PORT_A
37+
MICROPHONE = 0x01 # input from microphone
38+
LINE_IN = 0x02 # input from line in

Lib/sunau.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
#
3838
# Reading audio files:
3939
# f = au.open(file, 'r')
40-
# or
41-
# f = au.openfp(filep, 'r')
42-
# where file is the name of a file and filep is an open file pointer.
40+
# where file is either the name of a file or an open file pointer.
4341
# The open file pointer must have methods read(), seek(), and close().
4442
# When the setpos() and rewind() methods are not used, the seek()
4543
# method is not necessary.
@@ -72,9 +70,7 @@
7270
#
7371
# Writing audio files:
7472
# f = au.open(file, 'w')
75-
# or
76-
# f = au.openfp(filep, 'w')
77-
# where file is the name of a file and filep is an open file pointer.
73+
# where file is either the name of a file or an open file pointer.
7874
# The open file pointer must have methods write(), tell(), seek(), and
7975
# close().
8076
#
@@ -151,6 +147,20 @@ def _write_u32(file, x):
151147
file.write(chr(int(data[i])))
152148

153149
class Au_read:
150+
access _file, _soundpos, _hdr_size, _data_size, _encoding, \
151+
_sampwidth, _framesize, _framerate, _nchannels, \
152+
_framesize, _info: private
153+
154+
def __init__(self, f):
155+
if type(f) == type(''):
156+
import builtin
157+
f = builtin.open(f, 'r')
158+
self.initfp(f)
159+
160+
def __del__(self):
161+
if self._file:
162+
self.close()
163+
154164
def initfp(self, file):
155165
self._file = file
156166
self._soundpos = 0
@@ -193,16 +203,6 @@ def initfp(self, file):
193203
else:
194204
self._info = ''
195205

196-
def __init__(self, f):
197-
if type(f) == type(''):
198-
import builtin
199-
f = builtin.open(f, 'r')
200-
self.initfp(f)
201-
202-
def __del__(self):
203-
if self._file:
204-
self.close()
205-
206206
def getfp(self):
207207
return self._file
208208

@@ -278,12 +278,20 @@ def close(self):
278278
self._file = None
279279

280280
class Au_write:
281+
access _file, _framerate, _nchannels, _sampwidth, _framesize, \
282+
_nframes, _nframeswritten, _datawritten, _info, \
283+
_comptype: private
284+
281285
def __init__(self, f):
282286
if type(f) == type(''):
283287
import builtin
284288
f = builtin.open(f, 'w')
285289
self.initfp(f)
286290

291+
def __del__(self):
292+
if self._file:
293+
self.close()
294+
287295
def initfp(self, file):
288296
self._file = file
289297
self._framerate = 0
@@ -297,10 +305,6 @@ def initfp(self, file):
297305
self._info = ''
298306
self._comptype = 'ULAW' # default is U-law
299307

300-
def __del__(self):
301-
if self._file:
302-
self.close()
303-
304308
def setnchannels(self, nchannels):
305309
if self._nframeswritten:
306310
raise Error, 'cannot change parameters after starting to write'
@@ -404,6 +408,8 @@ def close(self):
404408
#
405409
# private methods
406410
#
411+
access *: private
412+
407413
def _ensure_header_written(self):
408414
if not self._nframeswritten:
409415
if not self._nchannels:

Lib/sunos4/SUNAUDIODEV.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22
# The names are the same as in audioio.h with the leading AUDIO_
33
# removed.
44

5+
# Not all values are supported on all releases of SunOS.
6+
57
# Encoding types, for fields i_encoding and o_encoding
68

7-
ENCODING_ULAW = 1
8-
ENCODING_ALAW = 2
9+
ENCODING_NONE = 0 # no encoding assigned
10+
ENCODING_ULAW = 1 # u-law encoding
11+
ENCODING_ALAW = 2 # A-law encoding
12+
ENCODING_LINEAR = 3 # Linear PCM encoding
913

1014
# Gain ranges for i_gain, o_gain and monitor_gain
1115

12-
MIN_GAIN = 0
13-
MAX_GAIN = 255
16+
MIN_GAIN = 0 # minimum gain value
17+
MAX_GAIN = 255 # maximum gain value
18+
19+
# Balance values for i_balance and o_balance
20+
21+
LEFT_BALANCE = 0 # left channel only
22+
MID_BALANCE = 32 # equal left/right channel
23+
RIGHT_BALANCE = 64 # right channel only
24+
BALANCE_SHIFT = 3
1425

1526
# Port names for i_port and o_port
1627

@@ -19,7 +30,9 @@
1930
PORT_C = 3
2031
PORT_D = 4
2132

22-
SPEAKER = PORT_A
23-
HEADPHONE = PORT_B
33+
SPEAKER = 0x01 # output to built-in speaker
34+
HEADPHONE = 0x02 # output to headphone jack
35+
LINE_OUT = 0x04 # output to line out
2436

25-
MICROPHONE = PORT_A
37+
MICROPHONE = 0x01 # input from microphone
38+
LINE_IN = 0x02 # input from line in

0 commit comments

Comments
 (0)