File tree Expand file tree Collapse file tree 2 files changed +6
-8
lines changed
Expand file tree Collapse file tree 2 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -40,11 +40,8 @@ def task_done_logger(task: asyncio.Task) -> None:
4040 return
4141
4242
43- def get_address (data : memoryview ) -> int :
44- """Get the address of a buffer using ctypes"""
45- nbytes = data .nbytes
46- buffer = (ctypes .c_int8 * nbytes ).from_buffer (data )
47- return ctypes .addressof (buffer )
43+ def get_address (mv : memoryview ) -> int :
44+ return ctypes .addressof (ctypes .c_char .from_buffer (mv ))
4845
4946
5047T = TypeVar ("T" )
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ def __init__(
4848 Raises:
4949 ValueError: If the length of `data` is smaller than the required size.
5050 """
51+ data = memoryview (data ).cast ("B" )
52+
5153 if len (data ) < num_channels * samples_per_channel * ctypes .sizeof (
5254 ctypes .c_int16
5355 ):
@@ -59,9 +61,8 @@ def __init__(
5961 # can happen if data is bigger than needed
6062 raise ValueError ("data length must be a multiple of sizeof(int16)" )
6163
62- data = memoryview (data ).cast ("B" )
63- self ._data = (ctypes .c_int16 * (len (data ) // ctypes .sizeof (ctypes .c_int16 )))()
64- ctypes .memmove (self ._data , data , len (data ))
64+ n = len (data ) // ctypes .sizeof (ctypes .c_int16 )
65+ self ._data = (ctypes .c_int16 * n ).from_buffer_copy (data )
6566
6667 self ._sample_rate = sample_rate
6768 self ._num_channels = num_channels
You can’t perform that action at this time.
0 commit comments