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

Public Member Functions

def initfp
 
def __init__
 
def __del__
 
def getfp
 
def rewind
 
def close
 
def tell
 
def getnchannels
 
def getnframes
 
def getsampwidth
 
def getframerate
 
def getcomptype
 
def getcompname
 
def getparams
 
def getmarkers
 
def getmark
 
def setpos
 
def readframes
 

Detailed Description

Variables used in this class:

These variables are available to the user though appropriate
methods of this class:
_file -- the open file with methods read(), close(), and seek()
          set through the __init__() method
_nchannels -- the number of audio channels
          available through the getnchannels() method
_nframes -- the number of audio frames
          available through the getnframes() method
_sampwidth -- the number of bytes per audio sample
          available through the getsampwidth() method
_framerate -- the sampling frequency
          available through the getframerate() method
_comptype -- the AIFF-C compression type ('NONE' if AIFF)
          available through the getcomptype() method
_compname -- the human-readable AIFF-C compression type
          available through the getcomptype() method
_soundpos -- the position in the audio stream
          available through the tell() method, set through the
          setpos() method

These variables are used internally only:
_fmt_chunk_read -- 1 iff the FMT chunk has been read
_data_seek_needed -- 1 iff positioned correctly in audio
          file for readframes()
_data_chunk -- instantiation of a chunk class for the DATA chunk
_framesize -- size of one frame in the file

Definition at line 94 of file wave.py.

Constructor & Destructor Documentation

def __init__ (   self,
  f 
)

Definition at line 156 of file wave.py.

157  def __init__(self, f):
158  self._i_opened_the_file = None
159  if type(f) == type(''):
160  f = __builtin__.open(f, 'rb')
161  self._i_opened_the_file = f
162  # else, assume it is an open file object already
163  self.initfp(f)
def __del__ (   self)

Definition at line 164 of file wave.py.

165  def __del__(self):
self.close()

Member Function Documentation

def close (   self)

Definition at line 176 of file wave.py.

177  def close(self):
178  if self._i_opened_the_file:
179  self._i_opened_the_file.close()
180  self._i_opened_the_file = None
181  self._file = None
def getcompname (   self)

Definition at line 200 of file wave.py.

201  def getcompname(self):
202  return self._compname
def getcomptype (   self)

Definition at line 197 of file wave.py.

198  def getcomptype(self):
199  return self._comptype
def getfp (   self)

Definition at line 169 of file wave.py.

170  def getfp(self):
171  return self._file
def getframerate (   self)

Definition at line 194 of file wave.py.

195  def getframerate(self):
196  return self._framerate
def getmark (   self,
  id 
)

Definition at line 211 of file wave.py.

212  def getmark(self, id):
213  raise Error, 'no marks'
def getmarkers (   self)

Definition at line 208 of file wave.py.

209  def getmarkers(self):
210  return None
def getnchannels (   self)

Definition at line 185 of file wave.py.

186  def getnchannels(self):
187  return self._nchannels
def getnframes (   self)

Definition at line 188 of file wave.py.

189  def getnframes(self):
190  return self._nframes
def getparams (   self)

Definition at line 203 of file wave.py.

204  def getparams(self):
205  return self.getnchannels(), self.getsampwidth(), \
206  self.getframerate(), self.getnframes(), \
207  self.getcomptype(), self.getcompname()
def getsampwidth (   self)

Definition at line 191 of file wave.py.

192  def getsampwidth(self):
193  return self._sampwidth
def initfp (   self,
  file 
)

Definition at line 125 of file wave.py.

126  def initfp(self, file):
127  self._convert = None
128  self._soundpos = 0
129  self._file = Chunk(file, bigendian = 0)
130  if self._file.getname() != 'RIFF':
131  raise Error, 'file does not start with RIFF id'
132  if self._file.read(4) != 'WAVE':
133  raise Error, 'not a WAVE file'
134  self._fmt_chunk_read = 0
135  self._data_chunk = None
136  while 1:
137  self._data_seek_needed = 1
138  try:
139  chunk = Chunk(self._file, bigendian = 0)
140  except EOFError:
141  break
142  chunkname = chunk.getname()
143  if chunkname == 'fmt ':
144  self._read_fmt_chunk(chunk)
145  self._fmt_chunk_read = 1
146  elif chunkname == 'data':
147  if not self._fmt_chunk_read:
148  raise Error, 'data chunk before fmt chunk'
149  self._data_chunk = chunk
150  self._nframes = chunk.chunksize // self._framesize
151  self._data_seek_needed = 0
152  break
153  chunk.skip()
154  if not self._fmt_chunk_read or not self._data_chunk:
155  raise Error, 'fmt chunk and/or data chunk missing'
def readframes (   self,
  nframes 
)

Definition at line 220 of file wave.py.

221  def readframes(self, nframes):
222  if self._data_seek_needed:
223  self._data_chunk.seek(0, 0)
224  pos = self._soundpos * self._framesize
225  if pos:
226  self._data_chunk.seek(pos, 0)
227  self._data_seek_needed = 0
228  if nframes == 0:
229  return ''
230  if self._sampwidth > 1 and big_endian:
231  # unfortunately the fromfile() method does not take
232  # something that only looks like a file object, so
233  # we have to reach into the innards of the chunk object
234  import array
235  chunk = self._data_chunk
236  data = array.array(_array_fmts[self._sampwidth])
237  nitems = nframes * self._nchannels
238  if nitems * self._sampwidth > chunk.chunksize - chunk.size_read:
239  nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth
240  data.fromfile(chunk.file.file, nitems)
241  # "tell" data chunk how much was read
242  chunk.size_read = chunk.size_read + nitems * self._sampwidth
243  # do the same for the outermost chunk
244  chunk = chunk.file
245  chunk.size_read = chunk.size_read + nitems * self._sampwidth
246  data.byteswap()
247  data = data.tostring()
248  else:
249  data = self._data_chunk.read(nframes * self._framesize)
250  if self._convert and data:
251  data = self._convert(data)
252  self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth)
253  return data
def rewind (   self)

Definition at line 172 of file wave.py.

173  def rewind(self):
174  self._data_seek_needed = 1
175  self._soundpos = 0
def setpos (   self,
  pos 
)

Definition at line 214 of file wave.py.

215  def setpos(self, pos):
216  if pos < 0 or pos > self._nframes:
217  raise Error, 'position not in range'
218  self._soundpos = pos
219  self._data_seek_needed = 1
def tell (   self)

Definition at line 182 of file wave.py.

183  def tell(self):
184  return self._soundpos

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