| 246 | """ |
| 247 | |
| 248 | def initfp(self, file): |
| 249 | self._convert = None |
| 250 | self._soundpos = 0 |
| 251 | self._file = _Chunk(file, bigendian = 0) |
| 252 | if self._file.getname() != b'RIFF': |
| 253 | raise Error('file does not start with RIFF id') |
| 254 | if self._file.read(4) != b'WAVE': |
| 255 | raise Error('not a WAVE file') |
| 256 | self._fmt_chunk_read = 0 |
| 257 | self._data_chunk = None |
| 258 | while 1: |
| 259 | self._data_seek_needed = 1 |
| 260 | try: |
| 261 | chunk = _Chunk(self._file, bigendian = 0) |
| 262 | except EOFError: |
| 263 | break |
| 264 | chunkname = chunk.getname() |
| 265 | if chunkname == b'fmt ': |
| 266 | self._read_fmt_chunk(chunk) |
| 267 | self._fmt_chunk_read = 1 |
| 268 | elif chunkname == b'data': |
| 269 | if not self._fmt_chunk_read: |
| 270 | raise Error('data chunk before fmt chunk') |
| 271 | self._data_chunk = chunk |
| 272 | self._nframes = chunk.chunksize // self._framesize |
| 273 | self._data_seek_needed = 0 |
| 274 | break |
| 275 | chunk.skip() |
| 276 | if not self._fmt_chunk_read or not self._data_chunk: |
| 277 | raise Error('fmt chunk and/or data chunk missing') |
| 278 | |
| 279 | def __init__(self, f): |
| 280 | self._i_opened_the_file = None |