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