File tree 2 files changed +8
-7
lines changed
2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -40,11 +40,8 @@ def task_done_logger(task: asyncio.Task) -> None:
40
40
return
41
41
42
42
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 ))
48
45
49
46
50
47
T = TypeVar ("T" )
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ def __init__(
48
48
Raises:
49
49
ValueError: If the length of `data` is smaller than the required size.
50
50
"""
51
+ data = memoryview (data ).cast ("B" )
52
+
51
53
if len (data ) < num_channels * samples_per_channel * ctypes .sizeof (
52
54
ctypes .c_int16
53
55
):
@@ -59,7 +61,9 @@ def __init__(
59
61
# can happen if data is bigger than needed
60
62
raise ValueError ("data length must be a multiple of sizeof(int16)" )
61
63
62
- self ._data = bytearray (data )
64
+ n = len (data ) // ctypes .sizeof (ctypes .c_int16 )
65
+ self ._data = (ctypes .c_int16 * n ).from_buffer_copy (data )
66
+
63
67
self ._sample_rate = sample_rate
64
68
self ._num_channels = num_channels
65
69
self ._samples_per_channel = samples_per_channel
@@ -133,7 +137,7 @@ def data(self) -> memoryview:
133
137
Returns:
134
138
memoryview: A memory view of the audio data.
135
139
"""
136
- return memoryview (self ._data ).cast ("h" )
140
+ return memoryview (self ._data ).cast ("B" ). cast ( " h" )
137
141
138
142
@property
139
143
def sample_rate (self ) -> int :
You can’t perform that action at this time.
0 commit comments