Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Wave_write Class Reference

Public Member Functions

def __init__
 
def initfp
 
def __del__
 
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 setmark
 
def getmark
 
def getmarkers
 
def tell
 
def writeframesraw
 
def writeframes
 
def close
 

Detailed Description

Variables used in this class:

These variables are user settable through appropriate methods
of this class:
_file -- the open file with methods write(), close(), tell(), seek()
          set through the __init__() method
_comptype -- the AIFF-C compression type ('NONE' in AIFF)
          set through the setcomptype() or setparams() method
_compname -- the human-readable AIFF-C compression type
          set through the setcomptype() or setparams() method
_nchannels -- the number of audio channels
          set through the setnchannels() or setparams() method
_sampwidth -- the number of bytes per audio sample
          set through the setsampwidth() or setparams() method
_framerate -- the sampling frequency
          set through the setframerate() or setparams() method
_nframes -- the number of audio frames written to the header
          set through the setnframes() or setparams() method

These variables are used internally only:
_datalength -- the size of the audio samples written to the header
_nframeswritten -- the number of frames actually written
_datawritten -- the size of the audio samples actually written

Definition at line 269 of file wave.py.

Constructor & Destructor Documentation

def __init__ (   self,
  f 
)

Definition at line 295 of file wave.py.

296  def __init__(self, f):
297  self._i_opened_the_file = None
298  if type(f) == type(''):
299  f = __builtin__.open(f, 'wb')
300  self._i_opened_the_file = f
301  self.initfp(f)
def __del__ (   self)

Definition at line 313 of file wave.py.

314  def __del__(self):
315  self.close()

Member Function Documentation

def close (   self)

Definition at line 425 of file wave.py.

426  def close(self):
427  if self._file:
428  self._ensure_header_written(0)
429  if self._datalength != self._datawritten:
430  self._patchheader()
431  self._file.flush()
432  self._file = None
433  if self._i_opened_the_file:
434  self._i_opened_the_file.close()
435  self._i_opened_the_file = None
def getcompname (   self)

Definition at line 374 of file wave.py.

375  def getcompname(self):
376  return self._compname
def getcomptype (   self)

Definition at line 371 of file wave.py.

372  def getcomptype(self):
373  return self._comptype
def getframerate (   self)

Definition at line 350 of file wave.py.

351  def getframerate(self):
352  if not self._framerate:
353  raise Error, 'frame rate not set'
354  return self._framerate
def getmark (   self,
  id 
)

Definition at line 395 of file wave.py.

396  def getmark(self, id):
397  raise Error, 'no marks'
def getmarkers (   self)

Definition at line 398 of file wave.py.

399  def getmarkers(self):
400  return None
def getnchannels (   self)

Definition at line 326 of file wave.py.

327  def getnchannels(self):
328  if not self._nchannels:
329  raise Error, 'number of channels not set'
330  return self._nchannels
def getnframes (   self)

Definition at line 360 of file wave.py.

361  def getnframes(self):
362  return self._nframeswritten
def getparams (   self)

Definition at line 386 of file wave.py.

387  def getparams(self):
388  if not self._nchannels or not self._sampwidth or not self._framerate:
389  raise Error, 'not all parameters set'
390  return self._nchannels, self._sampwidth, self._framerate, \
391  self._nframes, self._comptype, self._compname
def getsampwidth (   self)

Definition at line 338 of file wave.py.

339  def getsampwidth(self):
340  if not self._sampwidth:
341  raise Error, 'sample width not set'
342  return self._sampwidth
def initfp (   self,
  file 
)

Definition at line 302 of file wave.py.

303  def initfp(self, file):
304  self._file = file
305  self._convert = None
306  self._nchannels = 0
307  self._sampwidth = 0
308  self._framerate = 0
309  self._nframes = 0
310  self._nframeswritten = 0
311  self._datawritten = 0
312  self._datalength = 0
def setcomptype (   self,
  comptype,
  compname 
)

Definition at line 363 of file wave.py.

364  def setcomptype(self, comptype, compname):
365  if self._datawritten:
366  raise Error, 'cannot change parameters after starting to write'
367  if comptype not in ('NONE',):
368  raise Error, 'unsupported compression type'
369  self._comptype = comptype
370  self._compname = compname
def setframerate (   self,
  framerate 
)

Definition at line 343 of file wave.py.

344  def setframerate(self, framerate):
345  if self._datawritten:
346  raise Error, 'cannot change parameters after starting to write'
347  if framerate <= 0:
348  raise Error, 'bad frame rate'
349  self._framerate = framerate
def setmark (   self,
  id,
  pos,
  name 
)

Definition at line 392 of file wave.py.

393  def setmark(self, id, pos, name):
394  raise Error, 'setmark() not supported'
def setnchannels (   self,
  nchannels 
)

Definition at line 319 of file wave.py.

320  def setnchannels(self, nchannels):
321  if self._datawritten:
322  raise Error, 'cannot change parameters after starting to write'
323  if nchannels < 1:
324  raise Error, 'bad # of channels'
325  self._nchannels = nchannels
def setnframes (   self,
  nframes 
)

Definition at line 355 of file wave.py.

356  def setnframes(self, nframes):
357  if self._datawritten:
358  raise Error, 'cannot change parameters after starting to write'
359  self._nframes = nframes
def setparams (   self,
  nchannels,
  sampwidth,
  framerate,
  nframes,
  comptype,
  compname 
)

Definition at line 377 of file wave.py.

378  def setparams(self, (nchannels, sampwidth, framerate, nframes, comptype, compname)):
379  if self._datawritten:
380  raise Error, 'cannot change parameters after starting to write'
381  self.setnchannels(nchannels)
382  self.setsampwidth(sampwidth)
383  self.setframerate(framerate)
384  self.setnframes(nframes)
385  self.setcomptype(comptype, compname)
def setsampwidth (   self,
  sampwidth 
)

Definition at line 331 of file wave.py.

332  def setsampwidth(self, sampwidth):
333  if self._datawritten:
334  raise Error, 'cannot change parameters after starting to write'
335  if sampwidth < 1 or sampwidth > 4:
336  raise Error, 'bad sample width'
337  self._sampwidth = sampwidth
def tell (   self)

Definition at line 401 of file wave.py.

402  def tell(self):
403  return self._nframeswritten
def writeframes (   self,
  data 
)

Definition at line 420 of file wave.py.

421  def writeframes(self, data):
422  self.writeframesraw(data)
423  if self._datalength != self._datawritten:
424  self._patchheader()
def writeframesraw (   self,
  data 
)

Definition at line 404 of file wave.py.

405  def writeframesraw(self, data):
406  self._ensure_header_written(len(data))
407  nframes = len(data) // (self._sampwidth * self._nchannels)
408  if self._convert:
409  data = self._convert(data)
410  if self._sampwidth > 1 and big_endian:
411  import array
412  data = array.array(_array_fmts[self._sampwidth], data)
413  data.byteswap()
414  data.tofile(self._file)
415  self._datawritten = self._datawritten + len(data) * self._sampwidth
416  else:
417  self._file.write(data)
418  self._datawritten = self._datawritten + len(data)
419  self._nframeswritten = self._nframeswritten + nframes

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