feat: multiple audio fetchers support
This commit is contained in:
@@ -14,6 +14,8 @@ FFI.cdef[[
|
||||
|
||||
local malloc = FFI.C.malloc
|
||||
local free = FFI.C.free
|
||||
local FFIBytearray
|
||||
local bytearray_type
|
||||
|
||||
local function grow_buffer(self, elems)
|
||||
local new_capacity = math.ceil(self.capacity / 0.75 + elems)
|
||||
@@ -119,6 +121,20 @@ local function get_capacity(self)
|
||||
return self.capacity
|
||||
end
|
||||
|
||||
local function sub(self, offset, length)
|
||||
offset = offset or 1
|
||||
length = length or (self.size - offset + 1)
|
||||
if offset < 1 or offset > self.size then
|
||||
return FFIBytearray(0)
|
||||
end
|
||||
if offset + length - 1 > self.size then
|
||||
length = self.size - offset + 1
|
||||
end
|
||||
local buffer = malloc(length)
|
||||
FFI.copy(buffer, self.bytes + (offset - 1), length)
|
||||
return bytearray_type(buffer, length, length)
|
||||
end
|
||||
|
||||
local bytearray_methods = {
|
||||
append=append,
|
||||
insert=insert,
|
||||
@@ -127,6 +143,7 @@ local bytearray_methods = {
|
||||
clear=clear,
|
||||
reserve=reserve,
|
||||
get_capacity=get_capacity,
|
||||
sub=sub,
|
||||
}
|
||||
|
||||
local bytearray_mt = {
|
||||
@@ -168,9 +185,9 @@ local bytearray_mt = {
|
||||
}
|
||||
bytearray_mt.__pairs = bytearray_mt.__ipairs
|
||||
|
||||
local bytearray_type = FFI.metatype("bytearray_t", bytearray_mt)
|
||||
bytearray_type = FFI.metatype("bytearray_t", bytearray_mt)
|
||||
|
||||
local FFIBytearray = {
|
||||
FFIBytearray = {
|
||||
__call = function (self, n)
|
||||
local t = type(n)
|
||||
if t == "string" then
|
||||
|
||||
Reference in New Issue
Block a user