Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Private Attributes
sunau.Au_write Class Reference

List of all members.

Public Member Functions

def __init__
def __del__
def initfp
def setnchannels
def getnchannels
def setsampwidth
def getsampwidth
def setframerate
def getframerate
def setnframes
def getnframes
def setcomptype
def getcomptype
def getcompname
def setparams
def getparams
def tell
def writeframesraw
def writeframes
def close

Private Member Functions

def _ensure_header_written
def _write_header
def _patchheader

Private Attributes

 _opened
 _file
 _framerate
 _nchannels
 _sampwidth
 _framesize
 _nframes
 _nframeswritten
 _datawritten
 _datalength
 _info
 _comptype

Detailed Description

Definition at line 285 of file sunau.py.


Constructor & Destructor Documentation

def sunau.Au_write.__init__ (   self,
  f 
)

Definition at line 287 of file sunau.py.

00287 
00288     def __init__(self, f):
00289         if type(f) == type(''):
00290             import builtins
00291             f = builtins.open(f, 'wb')
00292             self._opened = True
00293         else:
00294             self._opened = False
00295         self.initfp(f)

Here is the caller graph for this function:

def sunau.Au_write.__del__ (   self)

Definition at line 296 of file sunau.py.

00296 
00297     def __del__(self):
00298         if self._file:
00299             self.close()
00300         self._file = None


Member Function Documentation

def sunau.Au_write._ensure_header_written (   self) [private]

Definition at line 421 of file sunau.py.

00421 
00422     def _ensure_header_written(self):
00423         if not self._nframeswritten:
00424             if not self._nchannels:
00425                 raise Error('# of channels not specified')
00426             if not self._sampwidth:
00427                 raise Error('sample width not specified')
00428             if not self._framerate:
00429                 raise Error('frame rate not specified')
00430             self._write_header()

Here is the call graph for this function:

def sunau.Au_write._patchheader (   self) [private]

Definition at line 466 of file sunau.py.

00466 
00467     def _patchheader(self):
00468         self._file.seek(8)
00469         _write_u32(self._file, self._datawritten)
00470         self._datalength = self._datawritten
00471         self._file.seek(0, 2)

Here is the call graph for this function:

def sunau.Au_write._write_header (   self) [private]

Definition at line 431 of file sunau.py.

00431 
00432     def _write_header(self):
00433         if self._comptype == 'NONE':
00434             if self._sampwidth == 1:
00435                 encoding = AUDIO_FILE_ENCODING_LINEAR_8
00436                 self._framesize = 1
00437             elif self._sampwidth == 2:
00438                 encoding = AUDIO_FILE_ENCODING_LINEAR_16
00439                 self._framesize = 2
00440             elif self._sampwidth == 4:
00441                 encoding = AUDIO_FILE_ENCODING_LINEAR_32
00442                 self._framesize = 4
00443             else:
00444                 raise Error('internal error')
00445         elif self._comptype == 'ULAW':
00446             encoding = AUDIO_FILE_ENCODING_MULAW_8
00447             self._framesize = 1
00448         else:
00449             raise Error('internal error')
00450         self._framesize = self._framesize * self._nchannels
00451         _write_u32(self._file, AUDIO_FILE_MAGIC)
00452         header_size = 25 + len(self._info)
00453         header_size = (header_size + 7) & ~7
00454         _write_u32(self._file, header_size)
00455         if self._nframes == AUDIO_UNKNOWN_SIZE:
00456             length = AUDIO_UNKNOWN_SIZE
00457         else:
00458             length = self._nframes * self._framesize
00459         _write_u32(self._file, length)
00460         self._datalength = length
00461         _write_u32(self._file, encoding)
00462         _write_u32(self._file, self._framerate)
00463         _write_u32(self._file, self._nchannels)
00464         self._file.write(self._info)
00465         self._file.write(b'\0'*(header_size - len(self._info) - 24))

Here is the call graph for this function:

Here is the caller graph for this function:

def sunau.Au_write.close (   self)

Definition at line 407 of file sunau.py.

00407 
00408     def close(self):
00409         self._ensure_header_written()
00410         if self._nframeswritten != self._nframes or \
00411                   self._datalength != self._datawritten:
00412             self._patchheader()
00413         self._file.flush()
00414         if self._opened and self._file:
00415             self._file.close()
00416         self._file = None

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 367 of file sunau.py.

00367 
00368     def getcompname(self):
00369         if self._comptype == 'ULAW':
00370             return 'CCITT G.711 u-law'
00371         elif self._comptype == 'ALAW':
00372             return 'CCITT G.711 A-law'
00373         else:
00374             return 'not compressed'

Definition at line 364 of file sunau.py.

00364 
00365     def getcomptype(self):
00366         return self._comptype

Definition at line 343 of file sunau.py.

00343 
00344     def getframerate(self):
00345         if not self._framerate:
00346             raise Error('frame rate not set')
00347         return self._framerate

Definition at line 321 of file sunau.py.

00321 
00322     def getnchannels(self):
00323         if not self._nchannels:
00324             raise Error('number of channels not set')
00325         return self._nchannels

def sunau.Au_write.getnframes (   self)

Definition at line 355 of file sunau.py.

00355 
00356     def getnframes(self):
00357         return self._nframeswritten

def sunau.Au_write.getparams (   self)

Definition at line 383 of file sunau.py.

00383 
00384     def getparams(self):
00385         return self.getnchannels(), self.getsampwidth(), \
00386                   self.getframerate(), self.getnframes(), \
00387                   self.getcomptype(), self.getcompname()

Here is the call graph for this function:

Definition at line 333 of file sunau.py.

00333 
00334     def getsampwidth(self):
00335         if not self._framerate:
00336             raise Error('sample width not specified')
00337         return self._sampwidth

Here is the caller graph for this function:

def sunau.Au_write.initfp (   self,
  file 
)

Definition at line 301 of file sunau.py.

00301 
00302     def initfp(self, file):
00303         self._file = file
00304         self._framerate = 0
00305         self._nchannels = 0
00306         self._sampwidth = 0
00307         self._framesize = 0
00308         self._nframes = AUDIO_UNKNOWN_SIZE
00309         self._nframeswritten = 0
00310         self._datawritten = 0
00311         self._datalength = 0
00312         self._info = b''
00313         self._comptype = 'ULAW' # default is U-law

def sunau.Au_write.setcomptype (   self,
  type,
  name 
)

Definition at line 358 of file sunau.py.

00358 
00359     def setcomptype(self, type, name):
00360         if type in ('NONE', 'ULAW'):
00361             self._comptype = type
00362         else:
00363             raise Error('unknown compression type')

def sunau.Au_write.setframerate (   self,
  framerate 
)

Definition at line 338 of file sunau.py.

00338 
00339     def setframerate(self, framerate):
00340         if self._nframeswritten:
00341             raise Error('cannot change parameters after starting to write')
00342         self._framerate = framerate

def sunau.Au_write.setnchannels (   self,
  nchannels 
)

Definition at line 314 of file sunau.py.

00314 
00315     def setnchannels(self, nchannels):
00316         if self._nframeswritten:
00317             raise Error('cannot change parameters after starting to write')
00318         if nchannels not in (1, 2, 4):
00319             raise Error('only 1, 2, or 4 channels supported')
00320         self._nchannels = nchannels

def sunau.Au_write.setnframes (   self,
  nframes 
)

Definition at line 348 of file sunau.py.

00348 
00349     def setnframes(self, nframes):
00350         if self._nframeswritten:
00351             raise Error('cannot change parameters after starting to write')
00352         if nframes < 0:
00353             raise Error('# of frames cannot be negative')
00354         self._nframes = nframes

def sunau.Au_write.setparams (   self,
  params 
)

Definition at line 375 of file sunau.py.

00375 
00376     def setparams(self, params):
00377         nchannels, sampwidth, framerate, nframes, comptype, compname = params
00378         self.setnchannels(nchannels)
00379         self.setsampwidth(sampwidth)
00380         self.setframerate(framerate)
00381         self.setnframes(nframes)
00382         self.setcomptype(comptype, compname)

Here is the call graph for this function:

def sunau.Au_write.setsampwidth (   self,
  sampwidth 
)

Definition at line 326 of file sunau.py.

00326 
00327     def setsampwidth(self, sampwidth):
00328         if self._nframeswritten:
00329             raise Error('cannot change parameters after starting to write')
00330         if sampwidth not in (1, 2, 4):
00331             raise Error('bad sample width')
00332         self._sampwidth = sampwidth

Here is the caller graph for this function:

def sunau.Au_write.tell (   self)

Definition at line 388 of file sunau.py.

00388 
00389     def tell(self):
00390         return self._nframeswritten

def sunau.Au_write.writeframes (   self,
  data 
)

Definition at line 401 of file sunau.py.

00401 
00402     def writeframes(self, data):
00403         self.writeframesraw(data)
00404         if self._nframeswritten != self._nframes or \
00405                   self._datalength != self._datawritten:
00406             self._patchheader()

Here is the call graph for this function:

def sunau.Au_write.writeframesraw (   self,
  data 
)

Definition at line 391 of file sunau.py.

00391 
00392     def writeframesraw(self, data):
00393         self._ensure_header_written()
00394         nframes = len(data) / self._framesize
00395         if self._comptype == 'ULAW':
00396             import audioop
00397             data = audioop.lin2ulaw(data, self._sampwidth)
00398         self._file.write(data)
00399         self._nframeswritten = self._nframeswritten + nframes
00400         self._datawritten = self._datawritten + len(data)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 312 of file sunau.py.

Definition at line 310 of file sunau.py.

Definition at line 309 of file sunau.py.

Definition at line 299 of file sunau.py.

Definition at line 303 of file sunau.py.

Definition at line 306 of file sunau.py.

Definition at line 311 of file sunau.py.

Definition at line 304 of file sunau.py.

Definition at line 307 of file sunau.py.

Definition at line 308 of file sunau.py.

Definition at line 291 of file sunau.py.

Definition at line 305 of file sunau.py.


The documentation for this class was generated from the following file: