Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: aifc.py
"""Stuff to parse AIFF-C and AIFF files.
[0] Fix | Delete
[1] Fix | Delete
Unless explicitly stated otherwise, the description below is true
[2] Fix | Delete
both for AIFF-C files and AIFF files.
[3] Fix | Delete
[4] Fix | Delete
An AIFF-C file has the following structure.
[5] Fix | Delete
[6] Fix | Delete
+-----------------+
[7] Fix | Delete
| FORM |
[8] Fix | Delete
+-----------------+
[9] Fix | Delete
| <size> |
[10] Fix | Delete
+----+------------+
[11] Fix | Delete
| | AIFC |
[12] Fix | Delete
| +------------+
[13] Fix | Delete
| | <chunks> |
[14] Fix | Delete
| | . |
[15] Fix | Delete
| | . |
[16] Fix | Delete
| | . |
[17] Fix | Delete
+----+------------+
[18] Fix | Delete
[19] Fix | Delete
An AIFF file has the string "AIFF" instead of "AIFC".
[20] Fix | Delete
[21] Fix | Delete
A chunk consists of an identifier (4 bytes) followed by a size (4 bytes,
[22] Fix | Delete
big endian order), followed by the data. The size field does not include
[23] Fix | Delete
the size of the 8 byte header.
[24] Fix | Delete
[25] Fix | Delete
The following chunk types are recognized.
[26] Fix | Delete
[27] Fix | Delete
FVER
[28] Fix | Delete
<version number of AIFF-C defining document> (AIFF-C only).
[29] Fix | Delete
MARK
[30] Fix | Delete
<# of markers> (2 bytes)
[31] Fix | Delete
list of markers:
[32] Fix | Delete
<marker ID> (2 bytes, must be > 0)
[33] Fix | Delete
<position> (4 bytes)
[34] Fix | Delete
<marker name> ("pstring")
[35] Fix | Delete
COMM
[36] Fix | Delete
<# of channels> (2 bytes)
[37] Fix | Delete
<# of sound frames> (4 bytes)
[38] Fix | Delete
<size of the samples> (2 bytes)
[39] Fix | Delete
<sampling frequency> (10 bytes, IEEE 80-bit extended
[40] Fix | Delete
floating point)
[41] Fix | Delete
in AIFF-C files only:
[42] Fix | Delete
<compression type> (4 bytes)
[43] Fix | Delete
<human-readable version of compression type> ("pstring")
[44] Fix | Delete
SSND
[45] Fix | Delete
<offset> (4 bytes, not used by this program)
[46] Fix | Delete
<blocksize> (4 bytes, not used by this program)
[47] Fix | Delete
<sound data>
[48] Fix | Delete
[49] Fix | Delete
A pstring consists of 1 byte length, a string of characters, and 0 or 1
[50] Fix | Delete
byte pad to make the total length even.
[51] Fix | Delete
[52] Fix | Delete
Usage.
[53] Fix | Delete
[54] Fix | Delete
Reading AIFF files:
[55] Fix | Delete
f = aifc.open(file, 'r')
[56] Fix | Delete
where file is either the name of a file or an open file pointer.
[57] Fix | Delete
The open file pointer must have methods read(), seek(), and close().
[58] Fix | Delete
In some types of audio files, if the setpos() method is not used,
[59] Fix | Delete
the seek() method is not necessary.
[60] Fix | Delete
[61] Fix | Delete
This returns an instance of a class with the following public methods:
[62] Fix | Delete
getnchannels() -- returns number of audio channels (1 for
[63] Fix | Delete
mono, 2 for stereo)
[64] Fix | Delete
getsampwidth() -- returns sample width in bytes
[65] Fix | Delete
getframerate() -- returns sampling frequency
[66] Fix | Delete
getnframes() -- returns number of audio frames
[67] Fix | Delete
getcomptype() -- returns compression type ('NONE' for AIFF files)
[68] Fix | Delete
getcompname() -- returns human-readable version of
[69] Fix | Delete
compression type ('not compressed' for AIFF files)
[70] Fix | Delete
getparams() -- returns a namedtuple consisting of all of the
[71] Fix | Delete
above in the above order
[72] Fix | Delete
getmarkers() -- get the list of marks in the audio file or None
[73] Fix | Delete
if there are no marks
[74] Fix | Delete
getmark(id) -- get mark with the specified id (raises an error
[75] Fix | Delete
if the mark does not exist)
[76] Fix | Delete
readframes(n) -- returns at most n frames of audio
[77] Fix | Delete
rewind() -- rewind to the beginning of the audio stream
[78] Fix | Delete
setpos(pos) -- seek to the specified position
[79] Fix | Delete
tell() -- return the current position
[80] Fix | Delete
close() -- close the instance (make it unusable)
[81] Fix | Delete
The position returned by tell(), the position given to setpos() and
[82] Fix | Delete
the position of marks are all compatible and have nothing to do with
[83] Fix | Delete
the actual position in the file.
[84] Fix | Delete
The close() method is called automatically when the class instance
[85] Fix | Delete
is destroyed.
[86] Fix | Delete
[87] Fix | Delete
Writing AIFF files:
[88] Fix | Delete
f = aifc.open(file, 'w')
[89] Fix | Delete
where file is either the name of a file or an open file pointer.
[90] Fix | Delete
The open file pointer must have methods write(), tell(), seek(), and
[91] Fix | Delete
close().
[92] Fix | Delete
[93] Fix | Delete
This returns an instance of a class with the following public methods:
[94] Fix | Delete
aiff() -- create an AIFF file (AIFF-C default)
[95] Fix | Delete
aifc() -- create an AIFF-C file
[96] Fix | Delete
setnchannels(n) -- set the number of channels
[97] Fix | Delete
setsampwidth(n) -- set the sample width
[98] Fix | Delete
setframerate(n) -- set the frame rate
[99] Fix | Delete
setnframes(n) -- set the number of frames
[100] Fix | Delete
setcomptype(type, name)
[101] Fix | Delete
-- set the compression type and the
[102] Fix | Delete
human-readable compression type
[103] Fix | Delete
setparams(tuple)
[104] Fix | Delete
-- set all parameters at once
[105] Fix | Delete
setmark(id, pos, name)
[106] Fix | Delete
-- add specified mark to the list of marks
[107] Fix | Delete
tell() -- return current position in output file (useful
[108] Fix | Delete
in combination with setmark())
[109] Fix | Delete
writeframesraw(data)
[110] Fix | Delete
-- write audio frames without pathing up the
[111] Fix | Delete
file header
[112] Fix | Delete
writeframes(data)
[113] Fix | Delete
-- write audio frames and patch up the file header
[114] Fix | Delete
close() -- patch up the file header and close the
[115] Fix | Delete
output file
[116] Fix | Delete
You should set the parameters before the first writeframesraw or
[117] Fix | Delete
writeframes. The total number of frames does not need to be set,
[118] Fix | Delete
but when it is set to the correct value, the header does not have to
[119] Fix | Delete
be patched up.
[120] Fix | Delete
It is best to first set all parameters, perhaps possibly the
[121] Fix | Delete
compression type, and then write audio frames using writeframesraw.
[122] Fix | Delete
When all frames have been written, either call writeframes(b'') or
[123] Fix | Delete
close() to patch up the sizes in the header.
[124] Fix | Delete
Marks can be added anytime. If there are any marks, you must call
[125] Fix | Delete
close() after all frames have been written.
[126] Fix | Delete
The close() method is called automatically when the class instance
[127] Fix | Delete
is destroyed.
[128] Fix | Delete
[129] Fix | Delete
When a file is opened with the extension '.aiff', an AIFF file is
[130] Fix | Delete
written, otherwise an AIFF-C file is written. This default can be
[131] Fix | Delete
changed by calling aiff() or aifc() before the first writeframes or
[132] Fix | Delete
writeframesraw.
[133] Fix | Delete
"""
[134] Fix | Delete
[135] Fix | Delete
import struct
[136] Fix | Delete
import builtins
[137] Fix | Delete
import warnings
[138] Fix | Delete
[139] Fix | Delete
__all__ = ["Error", "open", "openfp"]
[140] Fix | Delete
[141] Fix | Delete
class Error(Exception):
[142] Fix | Delete
pass
[143] Fix | Delete
[144] Fix | Delete
_AIFC_version = 0xA2805140 # Version 1 of AIFF-C
[145] Fix | Delete
[146] Fix | Delete
def _read_long(file):
[147] Fix | Delete
try:
[148] Fix | Delete
return struct.unpack('>l', file.read(4))[0]
[149] Fix | Delete
except struct.error:
[150] Fix | Delete
raise EOFError from None
[151] Fix | Delete
[152] Fix | Delete
def _read_ulong(file):
[153] Fix | Delete
try:
[154] Fix | Delete
return struct.unpack('>L', file.read(4))[0]
[155] Fix | Delete
except struct.error:
[156] Fix | Delete
raise EOFError from None
[157] Fix | Delete
[158] Fix | Delete
def _read_short(file):
[159] Fix | Delete
try:
[160] Fix | Delete
return struct.unpack('>h', file.read(2))[0]
[161] Fix | Delete
except struct.error:
[162] Fix | Delete
raise EOFError from None
[163] Fix | Delete
[164] Fix | Delete
def _read_ushort(file):
[165] Fix | Delete
try:
[166] Fix | Delete
return struct.unpack('>H', file.read(2))[0]
[167] Fix | Delete
except struct.error:
[168] Fix | Delete
raise EOFError from None
[169] Fix | Delete
[170] Fix | Delete
def _read_string(file):
[171] Fix | Delete
length = ord(file.read(1))
[172] Fix | Delete
if length == 0:
[173] Fix | Delete
data = b''
[174] Fix | Delete
else:
[175] Fix | Delete
data = file.read(length)
[176] Fix | Delete
if length & 1 == 0:
[177] Fix | Delete
dummy = file.read(1)
[178] Fix | Delete
return data
[179] Fix | Delete
[180] Fix | Delete
_HUGE_VAL = 1.79769313486231e+308 # See <limits.h>
[181] Fix | Delete
[182] Fix | Delete
def _read_float(f): # 10 bytes
[183] Fix | Delete
expon = _read_short(f) # 2 bytes
[184] Fix | Delete
sign = 1
[185] Fix | Delete
if expon < 0:
[186] Fix | Delete
sign = -1
[187] Fix | Delete
expon = expon + 0x8000
[188] Fix | Delete
himant = _read_ulong(f) # 4 bytes
[189] Fix | Delete
lomant = _read_ulong(f) # 4 bytes
[190] Fix | Delete
if expon == himant == lomant == 0:
[191] Fix | Delete
f = 0.0
[192] Fix | Delete
elif expon == 0x7FFF:
[193] Fix | Delete
f = _HUGE_VAL
[194] Fix | Delete
else:
[195] Fix | Delete
expon = expon - 16383
[196] Fix | Delete
f = (himant * 0x100000000 + lomant) * pow(2.0, expon - 63)
[197] Fix | Delete
return sign * f
[198] Fix | Delete
[199] Fix | Delete
def _write_short(f, x):
[200] Fix | Delete
f.write(struct.pack('>h', x))
[201] Fix | Delete
[202] Fix | Delete
def _write_ushort(f, x):
[203] Fix | Delete
f.write(struct.pack('>H', x))
[204] Fix | Delete
[205] Fix | Delete
def _write_long(f, x):
[206] Fix | Delete
f.write(struct.pack('>l', x))
[207] Fix | Delete
[208] Fix | Delete
def _write_ulong(f, x):
[209] Fix | Delete
f.write(struct.pack('>L', x))
[210] Fix | Delete
[211] Fix | Delete
def _write_string(f, s):
[212] Fix | Delete
if len(s) > 255:
[213] Fix | Delete
raise ValueError("string exceeds maximum pstring length")
[214] Fix | Delete
f.write(struct.pack('B', len(s)))
[215] Fix | Delete
f.write(s)
[216] Fix | Delete
if len(s) & 1 == 0:
[217] Fix | Delete
f.write(b'\x00')
[218] Fix | Delete
[219] Fix | Delete
def _write_float(f, x):
[220] Fix | Delete
import math
[221] Fix | Delete
if x < 0:
[222] Fix | Delete
sign = 0x8000
[223] Fix | Delete
x = x * -1
[224] Fix | Delete
else:
[225] Fix | Delete
sign = 0
[226] Fix | Delete
if x == 0:
[227] Fix | Delete
expon = 0
[228] Fix | Delete
himant = 0
[229] Fix | Delete
lomant = 0
[230] Fix | Delete
else:
[231] Fix | Delete
fmant, expon = math.frexp(x)
[232] Fix | Delete
if expon > 16384 or fmant >= 1 or fmant != fmant: # Infinity or NaN
[233] Fix | Delete
expon = sign|0x7FFF
[234] Fix | Delete
himant = 0
[235] Fix | Delete
lomant = 0
[236] Fix | Delete
else: # Finite
[237] Fix | Delete
expon = expon + 16382
[238] Fix | Delete
if expon < 0: # denormalized
[239] Fix | Delete
fmant = math.ldexp(fmant, expon)
[240] Fix | Delete
expon = 0
[241] Fix | Delete
expon = expon | sign
[242] Fix | Delete
fmant = math.ldexp(fmant, 32)
[243] Fix | Delete
fsmant = math.floor(fmant)
[244] Fix | Delete
himant = int(fsmant)
[245] Fix | Delete
fmant = math.ldexp(fmant - fsmant, 32)
[246] Fix | Delete
fsmant = math.floor(fmant)
[247] Fix | Delete
lomant = int(fsmant)
[248] Fix | Delete
_write_ushort(f, expon)
[249] Fix | Delete
_write_ulong(f, himant)
[250] Fix | Delete
_write_ulong(f, lomant)
[251] Fix | Delete
[252] Fix | Delete
from chunk import Chunk
[253] Fix | Delete
from collections import namedtuple
[254] Fix | Delete
[255] Fix | Delete
_aifc_params = namedtuple('_aifc_params',
[256] Fix | Delete
'nchannels sampwidth framerate nframes comptype compname')
[257] Fix | Delete
[258] Fix | Delete
_aifc_params.nchannels.__doc__ = 'Number of audio channels (1 for mono, 2 for stereo)'
[259] Fix | Delete
_aifc_params.sampwidth.__doc__ = 'Sample width in bytes'
[260] Fix | Delete
_aifc_params.framerate.__doc__ = 'Sampling frequency'
[261] Fix | Delete
_aifc_params.nframes.__doc__ = 'Number of audio frames'
[262] Fix | Delete
_aifc_params.comptype.__doc__ = 'Compression type ("NONE" for AIFF files)'
[263] Fix | Delete
_aifc_params.compname.__doc__ = ("""\
[264] Fix | Delete
A human-readable version of the compression type
[265] Fix | Delete
('not compressed' for AIFF files)""")
[266] Fix | Delete
[267] Fix | Delete
[268] Fix | Delete
class Aifc_read:
[269] Fix | Delete
# Variables used in this class:
[270] Fix | Delete
#
[271] Fix | Delete
# These variables are available to the user though appropriate
[272] Fix | Delete
# methods of this class:
[273] Fix | Delete
# _file -- the open file with methods read(), close(), and seek()
[274] Fix | Delete
# set through the __init__() method
[275] Fix | Delete
# _nchannels -- the number of audio channels
[276] Fix | Delete
# available through the getnchannels() method
[277] Fix | Delete
# _nframes -- the number of audio frames
[278] Fix | Delete
# available through the getnframes() method
[279] Fix | Delete
# _sampwidth -- the number of bytes per audio sample
[280] Fix | Delete
# available through the getsampwidth() method
[281] Fix | Delete
# _framerate -- the sampling frequency
[282] Fix | Delete
# available through the getframerate() method
[283] Fix | Delete
# _comptype -- the AIFF-C compression type ('NONE' if AIFF)
[284] Fix | Delete
# available through the getcomptype() method
[285] Fix | Delete
# _compname -- the human-readable AIFF-C compression type
[286] Fix | Delete
# available through the getcomptype() method
[287] Fix | Delete
# _markers -- the marks in the audio file
[288] Fix | Delete
# available through the getmarkers() and getmark()
[289] Fix | Delete
# methods
[290] Fix | Delete
# _soundpos -- the position in the audio stream
[291] Fix | Delete
# available through the tell() method, set through the
[292] Fix | Delete
# setpos() method
[293] Fix | Delete
#
[294] Fix | Delete
# These variables are used internally only:
[295] Fix | Delete
# _version -- the AIFF-C version number
[296] Fix | Delete
# _decomp -- the decompressor from builtin module cl
[297] Fix | Delete
# _comm_chunk_read -- 1 iff the COMM chunk has been read
[298] Fix | Delete
# _aifc -- 1 iff reading an AIFF-C file
[299] Fix | Delete
# _ssnd_seek_needed -- 1 iff positioned correctly in audio
[300] Fix | Delete
# file for readframes()
[301] Fix | Delete
# _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
[302] Fix | Delete
# _framesize -- size of one frame in the file
[303] Fix | Delete
[304] Fix | Delete
_file = None # Set here since __del__ checks it
[305] Fix | Delete
[306] Fix | Delete
def initfp(self, file):
[307] Fix | Delete
self._version = 0
[308] Fix | Delete
self._convert = None
[309] Fix | Delete
self._markers = []
[310] Fix | Delete
self._soundpos = 0
[311] Fix | Delete
self._file = file
[312] Fix | Delete
chunk = Chunk(file)
[313] Fix | Delete
if chunk.getname() != b'FORM':
[314] Fix | Delete
raise Error('file does not start with FORM id')
[315] Fix | Delete
formdata = chunk.read(4)
[316] Fix | Delete
if formdata == b'AIFF':
[317] Fix | Delete
self._aifc = 0
[318] Fix | Delete
elif formdata == b'AIFC':
[319] Fix | Delete
self._aifc = 1
[320] Fix | Delete
else:
[321] Fix | Delete
raise Error('not an AIFF or AIFF-C file')
[322] Fix | Delete
self._comm_chunk_read = 0
[323] Fix | Delete
self._ssnd_chunk = None
[324] Fix | Delete
while 1:
[325] Fix | Delete
self._ssnd_seek_needed = 1
[326] Fix | Delete
try:
[327] Fix | Delete
chunk = Chunk(self._file)
[328] Fix | Delete
except EOFError:
[329] Fix | Delete
break
[330] Fix | Delete
chunkname = chunk.getname()
[331] Fix | Delete
if chunkname == b'COMM':
[332] Fix | Delete
self._read_comm_chunk(chunk)
[333] Fix | Delete
self._comm_chunk_read = 1
[334] Fix | Delete
elif chunkname == b'SSND':
[335] Fix | Delete
self._ssnd_chunk = chunk
[336] Fix | Delete
dummy = chunk.read(8)
[337] Fix | Delete
self._ssnd_seek_needed = 0
[338] Fix | Delete
elif chunkname == b'FVER':
[339] Fix | Delete
self._version = _read_ulong(chunk)
[340] Fix | Delete
elif chunkname == b'MARK':
[341] Fix | Delete
self._readmark(chunk)
[342] Fix | Delete
chunk.skip()
[343] Fix | Delete
if not self._comm_chunk_read or not self._ssnd_chunk:
[344] Fix | Delete
raise Error('COMM chunk and/or SSND chunk missing')
[345] Fix | Delete
[346] Fix | Delete
def __init__(self, f):
[347] Fix | Delete
if isinstance(f, str):
[348] Fix | Delete
file_object = builtins.open(f, 'rb')
[349] Fix | Delete
try:
[350] Fix | Delete
self.initfp(file_object)
[351] Fix | Delete
except:
[352] Fix | Delete
file_object.close()
[353] Fix | Delete
raise
[354] Fix | Delete
else:
[355] Fix | Delete
# assume it is an open file object already
[356] Fix | Delete
self.initfp(f)
[357] Fix | Delete
[358] Fix | Delete
def __enter__(self):
[359] Fix | Delete
return self
[360] Fix | Delete
[361] Fix | Delete
def __exit__(self, *args):
[362] Fix | Delete
self.close()
[363] Fix | Delete
[364] Fix | Delete
#
[365] Fix | Delete
# User visible methods.
[366] Fix | Delete
#
[367] Fix | Delete
def getfp(self):
[368] Fix | Delete
return self._file
[369] Fix | Delete
[370] Fix | Delete
def rewind(self):
[371] Fix | Delete
self._ssnd_seek_needed = 1
[372] Fix | Delete
self._soundpos = 0
[373] Fix | Delete
[374] Fix | Delete
def close(self):
[375] Fix | Delete
file = self._file
[376] Fix | Delete
if file is not None:
[377] Fix | Delete
self._file = None
[378] Fix | Delete
file.close()
[379] Fix | Delete
[380] Fix | Delete
def tell(self):
[381] Fix | Delete
return self._soundpos
[382] Fix | Delete
[383] Fix | Delete
def getnchannels(self):
[384] Fix | Delete
return self._nchannels
[385] Fix | Delete
[386] Fix | Delete
def getnframes(self):
[387] Fix | Delete
return self._nframes
[388] Fix | Delete
[389] Fix | Delete
def getsampwidth(self):
[390] Fix | Delete
return self._sampwidth
[391] Fix | Delete
[392] Fix | Delete
def getframerate(self):
[393] Fix | Delete
return self._framerate
[394] Fix | Delete
[395] Fix | Delete
def getcomptype(self):
[396] Fix | Delete
return self._comptype
[397] Fix | Delete
[398] Fix | Delete
def getcompname(self):
[399] Fix | Delete
return self._compname
[400] Fix | Delete
[401] Fix | Delete
## def getversion(self):
[402] Fix | Delete
## return self._version
[403] Fix | Delete
[404] Fix | Delete
def getparams(self):
[405] Fix | Delete
return _aifc_params(self.getnchannels(), self.getsampwidth(),
[406] Fix | Delete
self.getframerate(), self.getnframes(),
[407] Fix | Delete
self.getcomptype(), self.getcompname())
[408] Fix | Delete
[409] Fix | Delete
def getmarkers(self):
[410] Fix | Delete
if len(self._markers) == 0:
[411] Fix | Delete
return None
[412] Fix | Delete
return self._markers
[413] Fix | Delete
[414] Fix | Delete
def getmark(self, id):
[415] Fix | Delete
for marker in self._markers:
[416] Fix | Delete
if id == marker[0]:
[417] Fix | Delete
return marker
[418] Fix | Delete
raise Error('marker {0!r} does not exist'.format(id))
[419] Fix | Delete
[420] Fix | Delete
def setpos(self, pos):
[421] Fix | Delete
if pos < 0 or pos > self._nframes:
[422] Fix | Delete
raise Error('position not in range')
[423] Fix | Delete
self._soundpos = pos
[424] Fix | Delete
self._ssnd_seek_needed = 1
[425] Fix | Delete
[426] Fix | Delete
def readframes(self, nframes):
[427] Fix | Delete
if self._ssnd_seek_needed:
[428] Fix | Delete
self._ssnd_chunk.seek(0)
[429] Fix | Delete
dummy = self._ssnd_chunk.read(8)
[430] Fix | Delete
pos = self._soundpos * self._framesize
[431] Fix | Delete
if pos:
[432] Fix | Delete
self._ssnd_chunk.seek(pos + 8)
[433] Fix | Delete
self._ssnd_seek_needed = 0
[434] Fix | Delete
if nframes == 0:
[435] Fix | Delete
return b''
[436] Fix | Delete
data = self._ssnd_chunk.read(nframes * self._framesize)
[437] Fix | Delete
if self._convert and data:
[438] Fix | Delete
data = self._convert(data)
[439] Fix | Delete
self._soundpos = self._soundpos + len(data) // (self._nchannels
[440] Fix | Delete
* self._sampwidth)
[441] Fix | Delete
return data
[442] Fix | Delete
[443] Fix | Delete
#
[444] Fix | Delete
# Internal methods.
[445] Fix | Delete
#
[446] Fix | Delete
[447] Fix | Delete
def _alaw2lin(self, data):
[448] Fix | Delete
import audioop
[449] Fix | Delete
return audioop.alaw2lin(data, 2)
[450] Fix | Delete
[451] Fix | Delete
def _ulaw2lin(self, data):
[452] Fix | Delete
import audioop
[453] Fix | Delete
return audioop.ulaw2lin(data, 2)
[454] Fix | Delete
[455] Fix | Delete
def _adpcm2lin(self, data):
[456] Fix | Delete
import audioop
[457] Fix | Delete
if not hasattr(self, '_adpcmstate'):
[458] Fix | Delete
# first time
[459] Fix | Delete
self._adpcmstate = None
[460] Fix | Delete
data, self._adpcmstate = audioop.adpcm2lin(data, 2, self._adpcmstate)
[461] Fix | Delete
return data
[462] Fix | Delete
[463] Fix | Delete
def _read_comm_chunk(self, chunk):
[464] Fix | Delete
self._nchannels = _read_short(chunk)
[465] Fix | Delete
self._nframes = _read_long(chunk)
[466] Fix | Delete
self._sampwidth = (_read_short(chunk) + 7) // 8
[467] Fix | Delete
self._framerate = int(_read_float(chunk))
[468] Fix | Delete
if self._sampwidth <= 0:
[469] Fix | Delete
raise Error('bad sample width')
[470] Fix | Delete
if self._nchannels <= 0:
[471] Fix | Delete
raise Error('bad # of channels')
[472] Fix | Delete
self._framesize = self._nchannels * self._sampwidth
[473] Fix | Delete
if self._aifc:
[474] Fix | Delete
#DEBUG: SGI's soundeditor produces a bad size :-(
[475] Fix | Delete
kludge = 0
[476] Fix | Delete
if chunk.chunksize == 18:
[477] Fix | Delete
kludge = 1
[478] Fix | Delete
warnings.warn('Warning: bad COMM chunk size')
[479] Fix | Delete
chunk.chunksize = 23
[480] Fix | Delete
#DEBUG end
[481] Fix | Delete
self._comptype = chunk.read(4)
[482] Fix | Delete
#DEBUG start
[483] Fix | Delete
if kludge:
[484] Fix | Delete
length = ord(chunk.file.read(1))
[485] Fix | Delete
if length & 1 == 0:
[486] Fix | Delete
length = length + 1
[487] Fix | Delete
chunk.chunksize = chunk.chunksize + length
[488] Fix | Delete
chunk.file.seek(-1, 1)
[489] Fix | Delete
#DEBUG end
[490] Fix | Delete
self._compname = _read_string(chunk)
[491] Fix | Delete
if self._comptype != b'NONE':
[492] Fix | Delete
if self._comptype == b'G722':
[493] Fix | Delete
self._convert = self._adpcm2lin
[494] Fix | Delete
elif self._comptype in (b'ulaw', b'ULAW'):
[495] Fix | Delete
self._convert = self._ulaw2lin
[496] Fix | Delete
elif self._comptype in (b'alaw', b'ALAW'):
[497] Fix | Delete
self._convert = self._alaw2lin
[498] Fix | Delete
else:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function