Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python2....
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 tuple 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('') 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 __builtin__
[137] Fix | Delete
[138] Fix | Delete
__all__ = ["Error","open","openfp"]
[139] Fix | Delete
[140] Fix | Delete
class Error(Exception):
[141] Fix | Delete
pass
[142] Fix | Delete
[143] Fix | Delete
_AIFC_version = 0xA2805140L # Version 1 of AIFF-C
[144] Fix | Delete
[145] Fix | Delete
def _read_long(file):
[146] Fix | Delete
try:
[147] Fix | Delete
return struct.unpack('>l', file.read(4))[0]
[148] Fix | Delete
except struct.error:
[149] Fix | Delete
raise EOFError
[150] Fix | Delete
[151] Fix | Delete
def _read_ulong(file):
[152] Fix | Delete
try:
[153] Fix | Delete
return struct.unpack('>L', file.read(4))[0]
[154] Fix | Delete
except struct.error:
[155] Fix | Delete
raise EOFError
[156] Fix | Delete
[157] Fix | Delete
def _read_short(file):
[158] Fix | Delete
try:
[159] Fix | Delete
return struct.unpack('>h', file.read(2))[0]
[160] Fix | Delete
except struct.error:
[161] Fix | Delete
raise EOFError
[162] Fix | Delete
[163] Fix | Delete
def _read_ushort(file):
[164] Fix | Delete
try:
[165] Fix | Delete
return struct.unpack('>H', file.read(2))[0]
[166] Fix | Delete
except struct.error:
[167] Fix | Delete
raise EOFError
[168] Fix | Delete
[169] Fix | Delete
def _read_string(file):
[170] Fix | Delete
length = ord(file.read(1))
[171] Fix | Delete
if length == 0:
[172] Fix | Delete
data = ''
[173] Fix | Delete
else:
[174] Fix | Delete
data = file.read(length)
[175] Fix | Delete
if length & 1 == 0:
[176] Fix | Delete
dummy = file.read(1)
[177] Fix | Delete
return data
[178] Fix | Delete
[179] Fix | Delete
_HUGE_VAL = 1.79769313486231e+308 # See <limits.h>
[180] Fix | Delete
[181] Fix | Delete
def _read_float(f): # 10 bytes
[182] Fix | Delete
expon = _read_short(f) # 2 bytes
[183] Fix | Delete
sign = 1
[184] Fix | Delete
if expon < 0:
[185] Fix | Delete
sign = -1
[186] Fix | Delete
expon = expon + 0x8000
[187] Fix | Delete
himant = _read_ulong(f) # 4 bytes
[188] Fix | Delete
lomant = _read_ulong(f) # 4 bytes
[189] Fix | Delete
if expon == himant == lomant == 0:
[190] Fix | Delete
f = 0.0
[191] Fix | Delete
elif expon == 0x7FFF:
[192] Fix | Delete
f = _HUGE_VAL
[193] Fix | Delete
else:
[194] Fix | Delete
expon = expon - 16383
[195] Fix | Delete
f = (himant * 0x100000000L + lomant) * pow(2.0, expon - 63)
[196] Fix | Delete
return sign * f
[197] Fix | Delete
[198] Fix | Delete
def _write_short(f, x):
[199] Fix | Delete
f.write(struct.pack('>h', x))
[200] Fix | Delete
[201] Fix | Delete
def _write_ushort(f, x):
[202] Fix | Delete
f.write(struct.pack('>H', x))
[203] Fix | Delete
[204] Fix | Delete
def _write_long(f, x):
[205] Fix | Delete
f.write(struct.pack('>l', x))
[206] Fix | Delete
[207] Fix | Delete
def _write_ulong(f, x):
[208] Fix | Delete
f.write(struct.pack('>L', x))
[209] Fix | Delete
[210] Fix | Delete
def _write_string(f, s):
[211] Fix | Delete
if len(s) > 255:
[212] Fix | Delete
raise ValueError("string exceeds maximum pstring length")
[213] Fix | Delete
f.write(struct.pack('B', len(s)))
[214] Fix | Delete
f.write(s)
[215] Fix | Delete
if len(s) & 1 == 0:
[216] Fix | Delete
f.write(chr(0))
[217] Fix | Delete
[218] Fix | Delete
def _write_float(f, x):
[219] Fix | Delete
import math
[220] Fix | Delete
if x < 0:
[221] Fix | Delete
sign = 0x8000
[222] Fix | Delete
x = x * -1
[223] Fix | Delete
else:
[224] Fix | Delete
sign = 0
[225] Fix | Delete
if x == 0:
[226] Fix | Delete
expon = 0
[227] Fix | Delete
himant = 0
[228] Fix | Delete
lomant = 0
[229] Fix | Delete
else:
[230] Fix | Delete
fmant, expon = math.frexp(x)
[231] Fix | Delete
if expon > 16384 or fmant >= 1 or fmant != fmant: # Infinity or NaN
[232] Fix | Delete
expon = sign|0x7FFF
[233] Fix | Delete
himant = 0
[234] Fix | Delete
lomant = 0
[235] Fix | Delete
else: # Finite
[236] Fix | Delete
expon = expon + 16382
[237] Fix | Delete
if expon < 0: # denormalized
[238] Fix | Delete
fmant = math.ldexp(fmant, expon)
[239] Fix | Delete
expon = 0
[240] Fix | Delete
expon = expon | sign
[241] Fix | Delete
fmant = math.ldexp(fmant, 32)
[242] Fix | Delete
fsmant = math.floor(fmant)
[243] Fix | Delete
himant = long(fsmant)
[244] Fix | Delete
fmant = math.ldexp(fmant - fsmant, 32)
[245] Fix | Delete
fsmant = math.floor(fmant)
[246] Fix | Delete
lomant = long(fsmant)
[247] Fix | Delete
_write_ushort(f, expon)
[248] Fix | Delete
_write_ulong(f, himant)
[249] Fix | Delete
_write_ulong(f, lomant)
[250] Fix | Delete
[251] Fix | Delete
from chunk import Chunk
[252] Fix | Delete
[253] Fix | Delete
class Aifc_read:
[254] Fix | Delete
# Variables used in this class:
[255] Fix | Delete
#
[256] Fix | Delete
# These variables are available to the user though appropriate
[257] Fix | Delete
# methods of this class:
[258] Fix | Delete
# _file -- the open file with methods read(), close(), and seek()
[259] Fix | Delete
# set through the __init__() method
[260] Fix | Delete
# _nchannels -- the number of audio channels
[261] Fix | Delete
# available through the getnchannels() method
[262] Fix | Delete
# _nframes -- the number of audio frames
[263] Fix | Delete
# available through the getnframes() method
[264] Fix | Delete
# _sampwidth -- the number of bytes per audio sample
[265] Fix | Delete
# available through the getsampwidth() method
[266] Fix | Delete
# _framerate -- the sampling frequency
[267] Fix | Delete
# available through the getframerate() method
[268] Fix | Delete
# _comptype -- the AIFF-C compression type ('NONE' if AIFF)
[269] Fix | Delete
# available through the getcomptype() method
[270] Fix | Delete
# _compname -- the human-readable AIFF-C compression type
[271] Fix | Delete
# available through the getcomptype() method
[272] Fix | Delete
# _markers -- the marks in the audio file
[273] Fix | Delete
# available through the getmarkers() and getmark()
[274] Fix | Delete
# methods
[275] Fix | Delete
# _soundpos -- the position in the audio stream
[276] Fix | Delete
# available through the tell() method, set through the
[277] Fix | Delete
# setpos() method
[278] Fix | Delete
#
[279] Fix | Delete
# These variables are used internally only:
[280] Fix | Delete
# _version -- the AIFF-C version number
[281] Fix | Delete
# _decomp -- the decompressor from builtin module cl
[282] Fix | Delete
# _comm_chunk_read -- 1 iff the COMM chunk has been read
[283] Fix | Delete
# _aifc -- 1 iff reading an AIFF-C file
[284] Fix | Delete
# _ssnd_seek_needed -- 1 iff positioned correctly in audio
[285] Fix | Delete
# file for readframes()
[286] Fix | Delete
# _ssnd_chunk -- instantiation of a chunk class for the SSND chunk
[287] Fix | Delete
# _framesize -- size of one frame in the file
[288] Fix | Delete
[289] Fix | Delete
_file = None # Set here since __del__ checks it
[290] Fix | Delete
[291] Fix | Delete
def initfp(self, file):
[292] Fix | Delete
self._version = 0
[293] Fix | Delete
self._decomp = None
[294] Fix | Delete
self._convert = None
[295] Fix | Delete
self._markers = []
[296] Fix | Delete
self._soundpos = 0
[297] Fix | Delete
self._file = file
[298] Fix | Delete
chunk = Chunk(file)
[299] Fix | Delete
if chunk.getname() != 'FORM':
[300] Fix | Delete
raise Error, 'file does not start with FORM id'
[301] Fix | Delete
formdata = chunk.read(4)
[302] Fix | Delete
if formdata == 'AIFF':
[303] Fix | Delete
self._aifc = 0
[304] Fix | Delete
elif formdata == 'AIFC':
[305] Fix | Delete
self._aifc = 1
[306] Fix | Delete
else:
[307] Fix | Delete
raise Error, 'not an AIFF or AIFF-C file'
[308] Fix | Delete
self._comm_chunk_read = 0
[309] Fix | Delete
self._ssnd_chunk = None
[310] Fix | Delete
while 1:
[311] Fix | Delete
self._ssnd_seek_needed = 1
[312] Fix | Delete
try:
[313] Fix | Delete
chunk = Chunk(self._file)
[314] Fix | Delete
except EOFError:
[315] Fix | Delete
break
[316] Fix | Delete
chunkname = chunk.getname()
[317] Fix | Delete
if chunkname == 'COMM':
[318] Fix | Delete
self._read_comm_chunk(chunk)
[319] Fix | Delete
self._comm_chunk_read = 1
[320] Fix | Delete
elif chunkname == 'SSND':
[321] Fix | Delete
self._ssnd_chunk = chunk
[322] Fix | Delete
dummy = chunk.read(8)
[323] Fix | Delete
self._ssnd_seek_needed = 0
[324] Fix | Delete
elif chunkname == 'FVER':
[325] Fix | Delete
self._version = _read_ulong(chunk)
[326] Fix | Delete
elif chunkname == 'MARK':
[327] Fix | Delete
self._readmark(chunk)
[328] Fix | Delete
chunk.skip()
[329] Fix | Delete
if not self._comm_chunk_read or not self._ssnd_chunk:
[330] Fix | Delete
raise Error, 'COMM chunk and/or SSND chunk missing'
[331] Fix | Delete
if self._aifc and self._decomp:
[332] Fix | Delete
import cl
[333] Fix | Delete
params = [cl.ORIGINAL_FORMAT, 0,
[334] Fix | Delete
cl.BITS_PER_COMPONENT, self._sampwidth * 8,
[335] Fix | Delete
cl.FRAME_RATE, self._framerate]
[336] Fix | Delete
if self._nchannels == 1:
[337] Fix | Delete
params[1] = cl.MONO
[338] Fix | Delete
elif self._nchannels == 2:
[339] Fix | Delete
params[1] = cl.STEREO_INTERLEAVED
[340] Fix | Delete
else:
[341] Fix | Delete
raise Error, 'cannot compress more than 2 channels'
[342] Fix | Delete
self._decomp.SetParams(params)
[343] Fix | Delete
[344] Fix | Delete
def __init__(self, f):
[345] Fix | Delete
if isinstance(f, basestring):
[346] Fix | Delete
f = __builtin__.open(f, 'rb')
[347] Fix | Delete
try:
[348] Fix | Delete
self.initfp(f)
[349] Fix | Delete
except:
[350] Fix | Delete
f.close()
[351] Fix | Delete
raise
[352] Fix | Delete
else:
[353] Fix | Delete
# assume it is an open file object already
[354] Fix | Delete
self.initfp(f)
[355] Fix | Delete
[356] Fix | Delete
#
[357] Fix | Delete
# User visible methods.
[358] Fix | Delete
#
[359] Fix | Delete
def getfp(self):
[360] Fix | Delete
return self._file
[361] Fix | Delete
[362] Fix | Delete
def rewind(self):
[363] Fix | Delete
self._ssnd_seek_needed = 1
[364] Fix | Delete
self._soundpos = 0
[365] Fix | Delete
[366] Fix | Delete
def close(self):
[367] Fix | Delete
decomp = self._decomp
[368] Fix | Delete
try:
[369] Fix | Delete
if decomp:
[370] Fix | Delete
self._decomp = None
[371] Fix | Delete
decomp.CloseDecompressor()
[372] Fix | Delete
finally:
[373] Fix | Delete
self._file.close()
[374] Fix | Delete
[375] Fix | Delete
def tell(self):
[376] Fix | Delete
return self._soundpos
[377] Fix | Delete
[378] Fix | Delete
def getnchannels(self):
[379] Fix | Delete
return self._nchannels
[380] Fix | Delete
[381] Fix | Delete
def getnframes(self):
[382] Fix | Delete
return self._nframes
[383] Fix | Delete
[384] Fix | Delete
def getsampwidth(self):
[385] Fix | Delete
return self._sampwidth
[386] Fix | Delete
[387] Fix | Delete
def getframerate(self):
[388] Fix | Delete
return self._framerate
[389] Fix | Delete
[390] Fix | Delete
def getcomptype(self):
[391] Fix | Delete
return self._comptype
[392] Fix | Delete
[393] Fix | Delete
def getcompname(self):
[394] Fix | Delete
return self._compname
[395] Fix | Delete
[396] Fix | Delete
## def getversion(self):
[397] Fix | Delete
## return self._version
[398] Fix | Delete
[399] Fix | Delete
def getparams(self):
[400] Fix | Delete
return self.getnchannels(), self.getsampwidth(), \
[401] Fix | Delete
self.getframerate(), self.getnframes(), \
[402] Fix | Delete
self.getcomptype(), self.getcompname()
[403] Fix | Delete
[404] Fix | Delete
def getmarkers(self):
[405] Fix | Delete
if len(self._markers) == 0:
[406] Fix | Delete
return None
[407] Fix | Delete
return self._markers
[408] Fix | Delete
[409] Fix | Delete
def getmark(self, id):
[410] Fix | Delete
for marker in self._markers:
[411] Fix | Delete
if id == marker[0]:
[412] Fix | Delete
return marker
[413] Fix | Delete
raise Error, 'marker %r does not exist' % (id,)
[414] Fix | Delete
[415] Fix | Delete
def setpos(self, pos):
[416] Fix | Delete
if pos < 0 or pos > self._nframes:
[417] Fix | Delete
raise Error, 'position not in range'
[418] Fix | Delete
self._soundpos = pos
[419] Fix | Delete
self._ssnd_seek_needed = 1
[420] Fix | Delete
[421] Fix | Delete
def readframes(self, nframes):
[422] Fix | Delete
if self._ssnd_seek_needed:
[423] Fix | Delete
self._ssnd_chunk.seek(0)
[424] Fix | Delete
dummy = self._ssnd_chunk.read(8)
[425] Fix | Delete
pos = self._soundpos * self._framesize
[426] Fix | Delete
if pos:
[427] Fix | Delete
self._ssnd_chunk.seek(pos + 8)
[428] Fix | Delete
self._ssnd_seek_needed = 0
[429] Fix | Delete
if nframes == 0:
[430] Fix | Delete
return ''
[431] Fix | Delete
data = self._ssnd_chunk.read(nframes * self._framesize)
[432] Fix | Delete
if self._convert and data:
[433] Fix | Delete
data = self._convert(data)
[434] Fix | Delete
self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth)
[435] Fix | Delete
return data
[436] Fix | Delete
[437] Fix | Delete
#
[438] Fix | Delete
# Internal methods.
[439] Fix | Delete
#
[440] Fix | Delete
[441] Fix | Delete
def _decomp_data(self, data):
[442] Fix | Delete
import cl
[443] Fix | Delete
dummy = self._decomp.SetParam(cl.FRAME_BUFFER_SIZE,
[444] Fix | Delete
len(data) * 2)
[445] Fix | Delete
return self._decomp.Decompress(len(data) // self._nchannels,
[446] Fix | Delete
data)
[447] Fix | Delete
[448] Fix | Delete
def _ulaw2lin(self, data):
[449] Fix | Delete
import audioop
[450] Fix | Delete
return audioop.ulaw2lin(data, 2)
[451] Fix | Delete
[452] Fix | Delete
def _adpcm2lin(self, data):
[453] Fix | Delete
import audioop
[454] Fix | Delete
if not hasattr(self, '_adpcmstate'):
[455] Fix | Delete
# first time
[456] Fix | Delete
self._adpcmstate = None
[457] Fix | Delete
data, self._adpcmstate = audioop.adpcm2lin(data, 2,
[458] Fix | Delete
self._adpcmstate)
[459] Fix | Delete
return data
[460] Fix | Delete
[461] Fix | Delete
def _read_comm_chunk(self, chunk):
[462] Fix | Delete
self._nchannels = _read_short(chunk)
[463] Fix | Delete
self._nframes = _read_long(chunk)
[464] Fix | Delete
self._sampwidth = (_read_short(chunk) + 7) // 8
[465] Fix | Delete
self._framerate = int(_read_float(chunk))
[466] Fix | Delete
self._framesize = self._nchannels * self._sampwidth
[467] Fix | Delete
if self._aifc:
[468] Fix | Delete
#DEBUG: SGI's soundeditor produces a bad size :-(
[469] Fix | Delete
kludge = 0
[470] Fix | Delete
if chunk.chunksize == 18:
[471] Fix | Delete
kludge = 1
[472] Fix | Delete
print 'Warning: bad COMM chunk size'
[473] Fix | Delete
chunk.chunksize = 23
[474] Fix | Delete
#DEBUG end
[475] Fix | Delete
self._comptype = chunk.read(4)
[476] Fix | Delete
#DEBUG start
[477] Fix | Delete
if kludge:
[478] Fix | Delete
length = ord(chunk.file.read(1))
[479] Fix | Delete
if length & 1 == 0:
[480] Fix | Delete
length = length + 1
[481] Fix | Delete
chunk.chunksize = chunk.chunksize + length
[482] Fix | Delete
chunk.file.seek(-1, 1)
[483] Fix | Delete
#DEBUG end
[484] Fix | Delete
self._compname = _read_string(chunk)
[485] Fix | Delete
if self._comptype != 'NONE':
[486] Fix | Delete
if self._comptype == 'G722':
[487] Fix | Delete
try:
[488] Fix | Delete
import audioop
[489] Fix | Delete
except ImportError:
[490] Fix | Delete
pass
[491] Fix | Delete
else:
[492] Fix | Delete
self._convert = self._adpcm2lin
[493] Fix | Delete
self._sampwidth = 2
[494] Fix | Delete
return
[495] Fix | Delete
# for ULAW and ALAW try Compression Library
[496] Fix | Delete
try:
[497] Fix | Delete
import cl
[498] Fix | Delete
except ImportError:
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function