You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
530 B
Lua

local remove = table.remove
local unpack = string.unpack -- luacheck: ignore
local rep = string.rep
local fmt = setmetatable({}, {
__index = function(self, n)
self[n] = '<' .. rep('i2', n)
return self[n]
end
})
local PCMString = require('class')('PCMString')
function PCMString:__init(str)
self._len = #str
self._str = str
end
function PCMString:read(n)
local i = self._i or 1
if i + n * 2 < self._len then
local pcm = {unpack(fmt[n], self._str, i)}
self._i = remove(pcm)
return pcm
end
end
return PCMString