Skip to content

Commit

Permalink
Fix for VorbisFile(Stream)
Browse files Browse the repository at this point in the history
Should fix Zuzu-Typ/PyOpenAL#9

(passing OggVorbis_File Objects was done incorrectly)
  • Loading branch information
Zuzu-Typ committed Aug 11, 2019
1 parent d619a85 commit de31f2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions pyogg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def _resize_array(array, new_size):
class VorbisFile:
def __init__(self, path):
vf = vorbis.OggVorbis_File()
error = vorbis.libvorbisfile.ov_fopen(vorbis.to_char_p(path), vf)
error = vorbis.libvorbisfile.ov_fopen(vorbis.to_char_p(path), ctypes.byref(vf))
if error != 0:
raise PyOggError("file couldn't be opened or doesn't exist. Error code : {}".format(error))
info = vorbis.libvorbisfile.ov_info(vf, -1)

info = vorbis.libvorbisfile.ov_info(ctypes.byref(vf), -1)

self.channels = info.contents.channels

Expand All @@ -47,7 +48,7 @@ def __init__(self, path):
bitstream_pointer = ctypes.pointer(bitstream)

while True:
new_bytes = vorbis.libvorbisfile.ov_read(vf, buffer_, 4096, 0, 2, 1, bitstream_pointer)
new_bytes = vorbis.libvorbisfile.ov_read(ctypes.byref(vf), buffer_, 4096, 0, 2, 1, bitstream_pointer)

array_ = ctypes.cast(buffer_, ctypes.POINTER(ctypes.c_char*4096)).contents

Expand All @@ -58,18 +59,18 @@ def __init__(self, path):

self.buffer = b"".join(self.buffer_array)

vorbis.libvorbisfile.ov_clear(vf)
vorbis.libvorbisfile.ov_clear(ctypes.byref(vf))

self.buffer_length = len(self.buffer)

class VorbisFileStream:
def __init__(self, path):
self.vf = vorbis.OggVorbis_File()
error = vorbis.ov_fopen(path, self.vf)
error = vorbis.ov_fopen(path, ctypes.byref(self.vf))
if error != 0:
raise PyOggError("file couldn't be opened or doesn't exist. Error code : {}".format(error))

info = vorbis.ov_info(self.vf, -1)
info = vorbis.ov_info(ctypes.byref(self.vf), -1)

self.channels = info.contents.channels

Expand All @@ -86,11 +87,11 @@ def __init__(self, path):

def __del__(self):
if self.exists:
vorbis.ov_clear(self.vf)
vorbis.ov_clear(ctypes.byref(self.vf))
self.exists = False

def clean_up(self):
vorbis.ov_clear(self.vf)
vorbis.ov_clear(ctypes.byref(self.vf))

self.exists = False

Expand All @@ -102,7 +103,7 @@ def get_buffer(self):
total_bytes_written = 0

while True:
new_bytes = vorbis.ov_read(self.vf, self.buffer_, PYOGG_STREAM_BUFFER_SIZE*self.channels - total_bytes_written, 0, 2, 1, self.bitstream_pointer)
new_bytes = vorbis.ov_read(ctypes.byref(self.vf), self.buffer_, PYOGG_STREAM_BUFFER_SIZE*self.channels - total_bytes_written, 0, 2, 1, self.bitstream_pointer)

array_ = ctypes.cast(self.buffer_, ctypes.POINTER(ctypes.c_char*(PYOGG_STREAM_BUFFER_SIZE*self.channels))).contents

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.6.8a1',
version='0.6.11a1',

description='Xiph.org\'s Ogg Vorbis, Opus and FLAC for Python',

Expand Down

0 comments on commit de31f2c

Please sign in to comment.