@@ -84,6 +84,8 @@ class Error(Exception):
84
84
85
85
WAVE_FORMAT_PCM = 0x0001
86
86
WAVE_FORMAT_EXTENSIBLE = 0xFFFE
87
+ # Derived from uuid.UUID("00000001-0000-0010-8000-00aa00389b71").bytes_le
88
+ KSDATAFORMAT_SUBTYPE_PCM = b'\x01 \x00 \x00 \x00 \x00 \x00 \x10 \x00 \x80 \x00 \x00 \xaa \x00 8\x9b q'
87
89
88
90
_array_fmts = None , 'b' , 'h' , None , 'i'
89
91
@@ -386,12 +388,20 @@ def _read_fmt_chunk(self, chunk):
386
388
raise EOFError from None
387
389
if wFormatTag == WAVE_FORMAT_EXTENSIBLE :
388
390
try :
389
- # Only the first 2 bytes (of 16) of SubFormat are needed.
390
- cbSize , wValidBitsPerSample , dwChannelMask , SubFormatFmt = struct .unpack_from ('<HHLH' , chunk .read (10 ))
391
+ cbSize , wValidBitsPerSample , dwChannelMask = struct .unpack_from ('<HHL' , chunk .read (8 ))
392
+ # Read the entire UUID from the chunk
393
+ SubFormat = chunk .read (16 )
394
+ if len (SubFormat ) < 16 :
395
+ raise EOFError
391
396
except struct .error :
392
397
raise EOFError from None
393
- if SubFormatFmt != WAVE_FORMAT_PCM :
394
- raise Error (f'unknown format: { SubFormatFmt } ' )
398
+ if SubFormat != KSDATAFORMAT_SUBTYPE_PCM :
399
+ try :
400
+ import uuid
401
+ subformat_msg = f'unknown extended format: { uuid .UUID (bytes_le = SubFormat )} '
402
+ except Exception :
403
+ subformat_msg = 'unknown extended format'
404
+ raise Error (subformat_msg )
395
405
self ._sampwidth = (sampwidth + 7 ) // 8
396
406
if not self ._sampwidth :
397
407
raise Error ('bad sample width' )
0 commit comments