From 0e21053d4e73f54928eefa1bbaabb0bf6d89b191 Mon Sep 17 00:00:00 2001 From: Jamie Hardt Date: Mon, 31 Dec 2018 16:33:24 -0800 Subject: [PATCH] Debugging with a jupyter notebook --- examples/wavinfo.ipynb | 180 ++++++++++++++++++++++++++++++++++++ wavinfo/wave_ixml_reader.py | 3 - wavinfo/wave_parser.py | 3 - wavinfo/wave_reader.py | 31 ++++--- 4 files changed, 197 insertions(+), 20 deletions(-) create mode 100644 examples/wavinfo.ipynb diff --git a/examples/wavinfo.ipynb b/examples/wavinfo.ipynb new file mode 100644 index 0000000..df6ebc0 --- /dev/null +++ b/examples/wavinfo.ipynb @@ -0,0 +1,180 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import wavinfo\n", + "import pprint" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "pp = pprint.PrettyPrinter(indent=4)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "testfile_path = \"../tests/test_files/\"\n", + "sound_devices_file = testfile_path + \"A101_1.WAV\"\n", + "\n", + "info = wavinfo.WavInfoReader(sound_devices_file)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WavInfoFormat(audio_format=1, channel_count=2, sample_rate=48000, byte_rate=288000, block_align=6, bits_per_sample=24)\n" + ] + } + ], + "source": [ + "pp.pprint(info.fmt)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WavBextFormat(description='sSPEED=023.976-ND\\r\\nsTAKE=1\\r\\nsUBITS=$12311801\\r\\nsSWVER=2.67\\r\\nsPROJECT=BMH\\r\\nsSCENE=A101\\r\\nsFILENAME=A101_1.WAV\\r\\nsTAPE=18Y12M31\\r\\nsTRK1=MKH516 A\\r\\nsTRK2=Boom\\r\\nsNOTE=', originator='Sound Dev: 702T S#GR1112089007', originator_ref='USSDVGR1112089007124001008206301', originator_date='2018-12-31', originator_time='12:40:00', time_reference=2190940753, version=1, umid=b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', loudness_value=0, loudness_range=0, max_true_peak=0, max_momentary_loudness=0, max_shortterm_loudness=0, coding_history='A=PCM,F=48000,W=24,M=stereo,R=48000,T=2 Ch')\n" + ] + } + ], + "source": [ + "pp.pprint(info.bext)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "('BMH', 'A101', '1', 240239)" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "info.ixml.project, info.ixml.scene, info.ixml.take, info.data.frame_count" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "pro_tools_file = testfile_path + \"PT A101_4.A1.wav\"" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ ChunkDescriptor(ident=b'bext', start=20, length=858),\n", + " ChunkDescriptor(ident=b'iXML', start=886, length=5226),\n", + " ChunkDescriptor(ident=b'fmt ', start=6120, length=16),\n", + " ChunkDescriptor(ident=b'data', start=6144, length=864840),\n", + " ChunkDescriptor(ident=b'umid', start=870992, length=24),\n", + " ChunkDescriptor(ident=b'minf', start=871024, length=16),\n", + " ChunkDescriptor(ident=b'regn', start=871048, length=92)]\n" + ] + } + ], + "source": [ + "import wavinfo.wave_parser\n", + "\n", + "with open(pro_tools_file,'rb') as f:\n", + " chunk_tree = wavinfo.wave_parser.parse_chunk(f)\n", + "\n", + "pp.pprint(chunk_tree.children)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WavBextFormat(description='dUBITS=12311804\\r\\ndSCENE=A101\\r\\ndTAKE=4\\r\\ndTAPE=18Y12M31\\r\\ndFRAMERATE=23.976ND\\r\\ndSPEED=023.976-NDF\\r\\ndTRK1=MKH516 A\\r\\ndTRK2=Boom', originator='Sound Dev: 702T S#GR1112089007', originator_ref='aa4CKtcd13Vk', originator_date='2018-12-31', originator_time='12:40:07', time_reference=2191709524, version=0, umid=b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00', loudness_value=0, loudness_range=0, max_true_peak=0, max_momentary_loudness=0, max_shortterm_loudness=0, coding_history='A=PCM,F=48000,W=24,M=stereo,R=48000,T=2 Ch')\n" + ] + } + ], + "source": [ + "ptinfo = wavinfo.WavInfoReader(pro_tools_file)\n", + "\n", + "print(ptinfo.bext)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/wavinfo/wave_ixml_reader.py b/wavinfo/wave_ixml_reader.py index f207cb3..f08e684 100644 --- a/wavinfo/wave_ixml_reader.py +++ b/wavinfo/wave_ixml_reader.py @@ -9,10 +9,7 @@ class WavIXMLFormat: self.parsed = ET.fromstring(xml) def _get_text_value(self, xpath): - print("xpath",xpath) - print("search", "./" + xpath) e = self.parsed.find("./" + xpath) - print("result was", e) if e is not None: return e.text diff --git a/wavinfo/wave_parser.py b/wavinfo/wave_parser.py index 7771b5d..0e3f786 100644 --- a/wavinfo/wave_parser.py +++ b/wavinfo/wave_parser.py @@ -1,9 +1,6 @@ import struct - -from .wave_ixml_reader import WavIXMLFormat - from collections import namedtuple ListChunkDescriptor = namedtuple('ListChunk' , 'signature children') diff --git a/wavinfo/wave_reader.py b/wavinfo/wave_reader.py index 9f42636..e24321a 100644 --- a/wavinfo/wave_reader.py +++ b/wavinfo/wave_reader.py @@ -2,8 +2,10 @@ import struct from collections import namedtuple -WavDataDescriptor = namedtuple('WavDataDescriptor','byte_count frame_count') +from .wave_parser import parse_chunk +from .wave_ixml_reader import WavIXMLFormat +WavDataDescriptor = namedtuple('WavDataDescriptor','byte_count frame_count') WavInfoFormat = namedtuple("WavInfoFormat",'audio_format channel_count sample_rate byte_rate block_align bits_per_sample') @@ -27,11 +29,11 @@ class WavInfoReader(): self.main_list = chunks.children f.seek(0) - self.fmt = self._get_format(self.main_list,f) - self.bext = self._get_bext(self.main_list,f) - self.ixml = self._get_ixml(self.main_list,f) + self.fmt = self._get_format(f) + self.bext = self._get_bext(f) + self.ixml = self._get_ixml(f) - self.data = delf._describe_data(self.main_list,f) + self.data = self._describe_data(f) def _find_chunk_data(self, ident, from_stream, default_none=False): chunk_descriptor = None @@ -49,12 +51,13 @@ class WavInfoReader(): def _describe_data(self,f): data_chunk = next(c for c in self.main_list if c.ident == b'data') - return WavDataDescriptor(byte_count= data_chunk.length, frame_count= data_chunk.length / self.fmt.block_align) + return WavDataDescriptor(byte_count= data_chunk.length, + frame_count= int(data_chunk.length / self.fmt.block_align)) - def _get_format(self,chunks,f): - fmt_data = se._find_chunk_data(b'fmt ',f) + def _get_format(self,f): + fmt_data = self._find_chunk_data(b'fmt ',f) # The format chunk is # audio_format U16 @@ -63,7 +66,7 @@ class WavInfoReader(): # byte_rate U32 == SampleRate * NumChannels * BitsPerSample/8 # block_align U16 == NumChannels * BitsPerSample/8 # bits_per_sampl U16 - packstring = "