Browse Source

Merge pull request #74 from Deledrius/wav_fixes

Wave file fixes.
pull/77/head
Adam Johnson 7 years ago committed by GitHub
parent
commit
8bf863b674
  1. 32
      korman/korlib/__init__.py
  2. 3
      korman/properties/modifiers/sound.py

32
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"]

3
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)

Loading…
Cancel
Save