MCPcopy Index your code
hub / github.com/python/cpython / _read_fmt_chunk

Method _read_fmt_chunk

Lib/wave.py:389–423  ·  view source on GitHub ↗
(self, chunk)

Source from the content-addressed store, hash-verified

387 #
388
389 def _read_fmt_chunk(self, chunk):
390 try:
391 self._format, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14))
392 except struct.error:
393 raise EOFError from None
394 if self._format not in (WAVE_FORMAT_PCM, WAVE_FORMAT_IEEE_FLOAT, WAVE_FORMAT_EXTENSIBLE):
395 raise Error('unknown format: %r' % (self._format,))
396 try:
397 sampwidth = struct.unpack_from('<H', chunk.read(2))[0]
398 except struct.error:
399 raise EOFError from None
400 if self._format == WAVE_FORMAT_EXTENSIBLE:
401 try:
402 cbSize, wValidBitsPerSample, dwChannelMask = struct.unpack_from('<HHL', chunk.read(8))
403 # Read the entire UUID from the chunk
404 SubFormat = chunk.read(16)
405 if len(SubFormat) < 16:
406 raise EOFError
407 except struct.error:
408 raise EOFError from None
409 if SubFormat != KSDATAFORMAT_SUBTYPE_PCM:
410 try:
411 import uuid
412 subformat_msg = f'unknown extended format: {uuid.UUID(bytes_le=SubFormat)}'
413 except Exception:
414 subformat_msg = 'unknown extended format'
415 raise Error(subformat_msg)
416 self._sampwidth = (sampwidth + 7) // 8
417 if not self._sampwidth:
418 raise Error('bad sample width')
419 if not self._nchannels:
420 raise Error('bad # of channels')
421 self._framesize = self._nchannels * self._sampwidth
422 self._comptype = 'NONE'
423 self._compname = 'not compressed'
424
425
426class Wave_write:

Callers 1

initfpMethod · 0.95

Calls 2

ErrorClass · 0.70
readMethod · 0.45

Tested by

no test coverage detected