Removed unnecessarry stuff
This commit is contained in:
parent
21a63ccdef
commit
06314ba26a
30
stream.lua
30
stream.lua
|
@ -1,7 +1,6 @@
|
|||
local args = { ... }
|
||||
|
||||
local dfpwm = require("cc.audio.dfpwm")
|
||||
local buffer_size = 8192
|
||||
|
||||
if not http then
|
||||
print("no http, check config")
|
||||
|
@ -22,26 +21,35 @@ if not req then
|
|||
return
|
||||
end
|
||||
|
||||
local headers = req.getResponseHeaders()
|
||||
local length = tonumber(headers["Content-Length"]) or 0
|
||||
|
||||
local function decode_s8(data)
|
||||
local buffer = {}
|
||||
for i = 1, buffer_size do
|
||||
buffer[i] = 0
|
||||
for i = 1, #data do
|
||||
local v = string.byte(data, i)
|
||||
if bit32.band(v, 0x80) then
|
||||
v = bit32.bxor(v, 0x7F) - 128
|
||||
end
|
||||
buffer[i] = v
|
||||
end
|
||||
return buffer
|
||||
end
|
||||
|
||||
local decode = dfpwm.make_decoder()
|
||||
local use_dfpwm = ({ args[1]:find("%.dfpwm") })[2] == #args[1]
|
||||
|
||||
local decode = use_dfpwm and dfpwm.make_decoder() or decode_s8
|
||||
local read_bytes = 0
|
||||
while true do
|
||||
local chunk = req.read(buffer_size)
|
||||
local chunk = req.read(16384)
|
||||
if not chunk then
|
||||
break
|
||||
end
|
||||
|
||||
--local buffer = {}
|
||||
--for i = 1, #chunk do
|
||||
-- buffer[i] = string.byte(chunk, i) - 128
|
||||
--end
|
||||
|
||||
local buffer = decode(chunk)
|
||||
|
||||
while not speaker.playAudio(buffer) do
|
||||
os.pullEvent("speaker_audio_empty")
|
||||
end
|
||||
end
|
||||
|
||||
print()
|
||||
|
|
Loading…
Reference in New Issue