Skip to content

Commit

Permalink
Opusfile as array (#26)
Browse files Browse the repository at this point in the history
* Added opus_get_version_string()

* Added as_array() to OpusFile
  • Loading branch information
mattgwwalker authored Jun 26, 2020
1 parent 3f6c91d commit c53233c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pyogg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ def __init__(self, path):

self.frequency = 48000

def as_array(self):
"""Returns the buffer as a NumPy array with the correct shape, where
the shape is in units of (number of samples per channel,
number of channels).
"""

import numpy

bytes_per_sample = ctypes.sizeof(opus.opus_int16)

return numpy.ctypeslib.as_array(
self.buffer,
(self.buffer_length
// bytes_per_sample
// self.channels,
self.channels)
)

class OpusFileStream:
def __init__(self, path):
error = ctypes.c_int()
Expand Down

0 comments on commit c53233c

Please sign in to comment.