diff --git a/wavinfo/riff_parser.py b/wavinfo/riff_parser.py index 58db6cc..476585f 100644 --- a/wavinfo/riff_parser.py +++ b/wavinfo/riff_parser.py @@ -62,5 +62,5 @@ def parse_chunk(stream, rf64_context=None): else: data_start = stream.tell() stream.seek(displacement, 1) - return ChunkDescriptor(ident=ident, start=data_start, length=data_size, + return ChunkDescriptor(ident=ident, start=data_start, length=data_size, rf64_context=rf64_context) diff --git a/wavinfo/wave_reader.py b/wavinfo/wave_reader.py index afb97ff..7d68cde 100644 --- a/wavinfo/wave_reader.py +++ b/wavinfo/wave_reader.py @@ -103,19 +103,27 @@ class WavInfoReader: self.data = self._describe_data() def _find_chunk_data(self, ident, from_stream, default_none=False): - top_chunks = (chunk for chunk in self.main_list if type(chunk) is ChunkDescriptor and chunk.ident == ident) - chunk_descriptor = next(top_chunks, None) if default_none else next(top_chunks) - return chunk_descriptor.read_data(from_stream) if chunk_descriptor else None + top_chunks = (chunk for chunk in self.main_list \ + if type(chunk) is ChunkDescriptor and chunk.ident == ident) + + chunk_descriptor = next(top_chunks, None) \ + if default_none else next(top_chunks) + + return chunk_descriptor.read_data(from_stream) \ + if chunk_descriptor else None def _describe_data(self): - data_chunk = next(c for c in self.main_list if type(c) is ChunkDescriptor and c.ident == b'data') + data_chunk = next(c for c in self.main_list \ + if type(c) is ChunkDescriptor and c.ident == b'data') - return WavDataDescriptor(byte_count=data_chunk.length, - frame_count=int(data_chunk.length / self.fmt.block_align)) + assert isinstance(self.fmt, WavAudioFormat) + return WavDataDescriptor( + byte_count=data_chunk.length, + frame_count=int(data_chunk.length / self.fmt.block_align)) def _get_format(self, f): fmt_data = self._find_chunk_data(b'fmt ', f) - + assert fmt_data is not None, "Fmt data not found, not a valid wav file" # The format chunk is # audio_format U16 # channel_count U16