MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / initfp

Method initfp

tools/python-3.11.9-amd64/Lib/sunau.py:181–225  ·  view source on GitHub ↗
(self, file)

Source from the content-addressed store, hash-verified

179 self.close()
180
181 def initfp(self, file):
182 self._file = file
183 self._soundpos = 0
184 magic = int(_read_u32(file))
185 if magic != AUDIO_FILE_MAGIC:
186 raise Error('bad magic number')
187 self._hdr_size = int(_read_u32(file))
188 if self._hdr_size < 24:
189 raise Error('header size too small')
190 if self._hdr_size > 100:
191 raise Error('header size ridiculously large')
192 self._data_size = _read_u32(file)
193 if self._data_size != AUDIO_UNKNOWN_SIZE:
194 self._data_size = int(self._data_size)
195 self._encoding = int(_read_u32(file))
196 if self._encoding not in _simple_encodings:
197 raise Error('encoding not (yet) supported')
198 if self._encoding in (AUDIO_FILE_ENCODING_MULAW_8,
199 AUDIO_FILE_ENCODING_ALAW_8):
200 self._sampwidth = 2
201 self._framesize = 1
202 elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_8:
203 self._framesize = self._sampwidth = 1
204 elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_16:
205 self._framesize = self._sampwidth = 2
206 elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_24:
207 self._framesize = self._sampwidth = 3
208 elif self._encoding == AUDIO_FILE_ENCODING_LINEAR_32:
209 self._framesize = self._sampwidth = 4
210 else:
211 raise Error('unknown encoding')
212 self._framerate = int(_read_u32(file))
213 self._nchannels = int(_read_u32(file))
214 if not self._nchannels:
215 raise Error('bad # of channels')
216 self._framesize = self._framesize * self._nchannels
217 if self._hdr_size > 24:
218 self._info = file.read(self._hdr_size - 24)
219 self._info, _, _ = self._info.partition(b'\0')
220 else:
221 self._info = b''
222 try:
223 self._data_pos = file.tell()
224 except (AttributeError, OSError):
225 self._data_pos = None
226
227 def getfp(self):
228 return self._file

Callers 1

__init__Method · 0.95

Calls 5

_read_u32Function · 0.85
partitionMethod · 0.80
ErrorClass · 0.70
readMethod · 0.45
tellMethod · 0.45

Tested by

no test coverage detected