From ae9e3a269527e1d4a56afb1945dfe17ac07a4409 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Tue, 3 Oct 2017 19:45:31 -0700 Subject: [PATCH 1/3] Fix korlib not reading Wave files when compiled module present. Improves chunk parsing to be more flexible. --- korman/korlib/__init__.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/korman/korlib/__init__.py b/korman/korlib/__init__.py index 7d1cfcc..3b5b690 100644 --- a/korman/korlib/__init__.py +++ b/korman/korlib/__init__.py @@ -56,20 +56,32 @@ except ImportError: def inspect_voribsfile(stream, header): raise NotImplementedError("Ogg Vorbis not supported unless _korlib is compiled") +else: + from .console import ConsoleToggler + from .texture import TEX_DETAIL_ALPHA, TEX_DETAIL_ADD, TEX_DETAIL_MULTIPLY + + def _wave_chunks(stream): + while not stream.eof(): + chunk_name = stream.read(4) + chunk_offset = stream.pos + chunk_size = stream.readInt() + stream.skip(chunk_size) + yield {"name": chunk_name, "offset": chunk_offset, "size": chunk_size} def inspect_wavefile(stream, header): assert stream.read(4) == b"RIFF" stream.readInt() assert stream.read(4) == b"WAVE" - assert stream.read(3) == b"fmt" + + # Read through the chunks until we find "fmt" and "data" + chunks = {} + for chunk in _wave_chunks(stream): + if chunk["name"] in {b"fmt ", b"data"}: + chunks[chunk["name"]] = chunk + assert chunks[b"fmt "] + assert chunks[b"data"] + + stream.seek(chunks[b"fmt "]["offset"]) header.read(stream) - # read thru the chunks until we find "data" - while stream.read(4) != b"data" and not stream.eof(): - stream.skip(stream.readInt()) - assert not stream.eof() - size = stream.readInt() - return (header, size) -else: - from .console import ConsoleToggler - from .texture import TEX_DETAIL_ALPHA, TEX_DETAIL_ADD, TEX_DETAIL_MULTIPLY + return chunks[b"data"]["size"] From 076a7088a22cc3933885ec6929f5a78f64dbba6e Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Tue, 3 Oct 2017 20:26:19 -0700 Subject: [PATCH 2/3] Use WAV header and size information instead of throwing it out. --- korman/properties/modifiers/sound.py | 1 + 1 file changed, 1 insertion(+) diff --git a/korman/properties/modifiers/sound.py b/korman/properties/modifiers/sound.py index ccbaa42..8234938 100644 --- a/korman/properties/modifiers/sound.py +++ b/korman/properties/modifiers/sound.py @@ -287,6 +287,7 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): header = plWAVHeader() if magic == b"RIFF": size = korlib.inspect_wavefile(stream, header) + return (header, size) elif magic == b"OggS": size = korlib.inspect_vorbisfile(stream, header) return (header, size) From c2ea65c719befac0fafc6a11b3899fa0d80b1bc2 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Tue, 3 Oct 2017 20:27:37 -0700 Subject: [PATCH 3/3] Fix crash when exporting sounds. --- korman/properties/modifiers/sound.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/korman/properties/modifiers/sound.py b/korman/properties/modifiers/sound.py index 8234938..e907497 100644 --- a/korman/properties/modifiers/sound.py +++ b/korman/properties/modifiers/sound.py @@ -240,7 +240,7 @@ class PlasmaSound(idprops.IDPropMixin, bpy.types.PropertyGroup): plfade.lengthInSecs = 0.0 else: plfade.lengthInSecs = blfade.length - plfade.type = getattr(plFadeParams, blfade.fade_type) + plfade.type = getattr(plSound.plFadeParams, blfade.fade_type) plfade.currTime = -1.0 # Some manual fiddling -- this is hidden deep inside the 3dsm exporter...