Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
fix oggdec decode on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Sep 4, 2017
1 parent dc53bdf commit f892623
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions bouldercaves/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def convertformat(self, stream):
if not conversion_required:
return stream
# use oggdec to convert the audio file on the fly to a WAV
uncompress_command = ["oggdec", "--quiet", "--output", "-", "-"]
if os.name == "nt":
oggdecexe = Winsound.ensure_oggdegexe()
uncompress_command = [oggdecexe, "--quiet", "--output", "-", "-"]
else:
uncompress_command = ["oggdec", "--quiet", "--output", "-", "-"]
with tempfile.NamedTemporaryFile() as tmpfile:
tmpfile.write(stream.read())
tmpfile.seek(0, 0)
Expand Down Expand Up @@ -387,10 +391,18 @@ def __init__(self):
global winsound
winsound = _winsound
self.threads = []
self.oggdecexe = self.ensure_oggdegexe()

@staticmethod
def ensure_oggdegexe():
filename = os.path.expanduser("~/.bouldercaves/oggdec.exe")
if os.path.isfile(filename):
return filename
os.makedirs(os.path.expanduser("~/.bouldercaves"), exist_ok=True)
oggdecexe = pkgutil.get_data(__name__, "sounds/oggdec.exe")
with open(os.path.expanduser("~/.bouldercaves/oggdec.exe"), "wb") as exefile:
with open(filename, "wb") as exefile:
exefile.write(oggdecexe)
return filename

def play(self, sample):
winsound.PlaySound(sample.filename, winsound.SND_ASYNC)
Expand All @@ -404,7 +416,7 @@ def store_sample_file(self, filename, data):
with open(oggfilename, "wb") as oggfile:
oggfile.write(data)
wavfilename = os.path.splitext(oggfilename)[0] + ".wav"
oggdeccmd = [os.path.expanduser("~/.bouldercaves/oggdec.exe"), "--quiet", oggfilename, "-o", wavfilename]
oggdeccmd = [self.oggdecexe, "--quiet", oggfilename, "-o", wavfilename]
subprocess.call(oggdeccmd)
os.remove(oggfilename)
return wavfilename
Expand Down

0 comments on commit f892623

Please sign in to comment.