Back to index

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

List of all members.

Public Member Functions

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

Private Attributes

 _opened
 _file
 _soundpos
 _hdr_size
 _data_size
 _encoding
 _sampwidth
 _framesize
 _framerate
 _nchannels
 _info

Detailed Description

Definition at line 151 of file sunau.py.


Constructor & Destructor Documentation

def sunau.Au_read.__init__ (   self,
  f 
)

Definition at line 153 of file sunau.py.

00153 
00154     def __init__(self, f):
00155         if type(f) == type(''):
00156             import builtins
00157             f = builtins.open(f, 'rb')
00158             self._opened = True
00159         else:
00160             self._opened = False
00161         self.initfp(f)

Here is the caller graph for this function:

def sunau.Au_read.__del__ (   self)

Definition at line 162 of file sunau.py.

00162 
00163     def __del__(self):
00164         if self._file:
00165             self.close()


Member Function Documentation

def sunau.Au_read.close (   self)

Definition at line 280 of file sunau.py.

00280 
00281     def close(self):
00282         if self._opened and self._file:
00283             self._file.close()
00284         self._file = None

Here is the caller graph for this function:

def sunau.Au_read.getcompname (   self)

Definition at line 236 of file sunau.py.

00236 
00237     def getcompname(self):
00238         if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
00239             return 'CCITT G.711 u-law'
00240         elif self._encoding == AUDIO_FILE_ENCODING_ALAW_8:
00241             return 'CCITT G.711 A-law'
00242         else:
00243             return 'not compressed'

def sunau.Au_read.getcomptype (   self)

Definition at line 228 of file sunau.py.

00228 
00229     def getcomptype(self):
00230         if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
00231             return 'ULAW'
00232         elif self._encoding == AUDIO_FILE_ENCODING_ALAW_8:
00233             return 'ALAW'
00234         else:
00235             return 'NONE'

def sunau.Au_read.getfp (   self)

Definition at line 209 of file sunau.py.

00209 
00210     def getfp(self):
00211         return self._file

Definition at line 218 of file sunau.py.

00218 
00219     def getframerate(self):
00220         return self._framerate

def sunau.Au_read.getmark (   self,
  id 
)

Definition at line 252 of file sunau.py.

00252 
00253     def getmark(self, id):
00254         raise Error('no marks')

def sunau.Au_read.getmarkers (   self)

Definition at line 249 of file sunau.py.

00249 
00250     def getmarkers(self):
00251         return None

Definition at line 212 of file sunau.py.

00212 
00213     def getnchannels(self):
00214         return self._nchannels

def sunau.Au_read.getnframes (   self)

Definition at line 221 of file sunau.py.

00221 
00222     def getnframes(self):
00223         if self._data_size == AUDIO_UNKNOWN_SIZE:
00224             return AUDIO_UNKNOWN_SIZE
00225         if self._encoding in _simple_encodings:
00226             return self._data_size / self._framesize
00227         return 0                # XXX--must do some arithmetic here

def sunau.Au_read.getparams (   self)

Definition at line 244 of file sunau.py.

00244 
00245     def getparams(self):
00246         return self.getnchannels(), self.getsampwidth(), \
00247                   self.getframerate(), self.getnframes(), \
00248                   self.getcomptype(), self.getcompname()

Here is the call graph for this function:

Definition at line 215 of file sunau.py.

00215 
00216     def getsampwidth(self):
00217         return self._sampwidth

Here is the caller graph for this function:

def sunau.Au_read.initfp (   self,
  file 
)

Definition at line 166 of file sunau.py.

00166 
00167     def initfp(self, file):
00168         self._file = file
00169         self._soundpos = 0
00170         magic = int(_read_u32(file))
00171         if magic != AUDIO_FILE_MAGIC:
00172             raise Error('bad magic number')
00173         self._hdr_size = int(_read_u32(file))
00174         if self._hdr_size < 24:
00175             raise Error('header size too small')
00176         if self._hdr_size > 100:
00177             raise Error('header size ridiculously large')
00178         self._data_size = _read_u32(file)
00179         if self._data_size != AUDIO_UNKNOWN_SIZE:
00180             self._data_size = int(self._data_size)
00181         self._encoding = int(_read_u32(file))
00182         if self._encoding not in _simple_encodings:
00183             raise Error('encoding not (yet) supported')
00184         if self._encoding in (AUDIO_FILE_ENCODING_MULAW_8,
00185                   AUDIO_FILE_ENCODING_ALAW_8):
00186             self._sampwidth = 2
00187             self._framesize = 1
00188         elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_8:
00189             self._framesize = self._sampwidth = 1
00190         elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_16:
00191             self._framesize = self._sampwidth = 2
00192         elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_24:
00193             self._framesize = self._sampwidth = 3
00194         elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_32:
00195             self._framesize = self._sampwidth = 4
00196         else:
00197             raise Error('unknown encoding')
00198         self._framerate = int(_read_u32(file))
00199         self._nchannels = int(_read_u32(file))
00200         self._framesize = self._framesize * self._nchannels
00201         if self._hdr_size > 24:
00202             self._info = file.read(self._hdr_size - 24)
00203             for i in range(len(self._info)):
00204                 if self._info[i] == b'\0':
00205                     self._info = self._info[:i]
00206                     break
00207         else:
00208             self._info = ''

def sunau.Au_read.readframes (   self,
  nframes 
)

Definition at line 255 of file sunau.py.

00255 
00256     def readframes(self, nframes):
00257         if self._encoding in _simple_encodings:
00258             if nframes == AUDIO_UNKNOWN_SIZE:
00259                 data = self._file.read()
00260             else:
00261                 data = self._file.read(nframes * self._framesize * self._nchannels)
00262             if self._encoding == AUDIO_FILE_ENCODING_MULAW_8:
00263                 import audioop
00264                 data = audioop.ulaw2lin(data, self._sampwidth)
00265             return data
00266         return None             # XXX--not implemented yet

def sunau.Au_read.rewind (   self)

Definition at line 267 of file sunau.py.

00267 
00268     def rewind(self):
00269         self._soundpos = 0
00270         self._file.seek(self._hdr_size)

def sunau.Au_read.setpos (   self,
  pos 
)

Definition at line 274 of file sunau.py.

00274 
00275     def setpos(self, pos):
00276         if pos < 0 or pos > self.getnframes():
00277             raise Error('position not in range')
00278         self._file.seek(pos * self._framesize + self._hdr_size)
00279         self._soundpos = pos

Here is the call graph for this function:

Here is the caller graph for this function:

def sunau.Au_read.tell (   self)

Definition at line 271 of file sunau.py.

00271 
00272     def tell(self):
00273         return self._soundpos


Member Data Documentation

Definition at line 177 of file sunau.py.

Definition at line 180 of file sunau.py.

Definition at line 167 of file sunau.py.

Definition at line 197 of file sunau.py.

Definition at line 186 of file sunau.py.

Definition at line 172 of file sunau.py.

Definition at line 201 of file sunau.py.

Definition at line 198 of file sunau.py.

Definition at line 157 of file sunau.py.

Definition at line 185 of file sunau.py.

Definition at line 168 of file sunau.py.


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