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"] diff --git a/korman/properties/modifiers/sound.py b/korman/properties/modifiers/sound.py index ccbaa42..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... @@ -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)