1
0
Fork 0

Removed unnecessarry stuff

This commit is contained in:
Casey 2024-01-06 14:15:14 +03:00
parent 21a63ccdef
commit 06314ba26a
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 20 additions and 12 deletions

View File

@ -1,7 +1,6 @@
local args = { ... } local args = { ... }
local dfpwm = require("cc.audio.dfpwm") local dfpwm = require("cc.audio.dfpwm")
local buffer_size = 8192
if not http then if not http then
print("no http, check config") print("no http, check config")
@ -22,26 +21,35 @@ if not req then
return return
end end
local headers = req.getResponseHeaders()
local length = tonumber(headers["Content-Length"]) or 0
local function decode_s8(data)
local buffer = {} local buffer = {}
for i = 1, buffer_size do for i = 1, #data do
buffer[i] = 0 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 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 while true do
local chunk = req.read(buffer_size) local chunk = req.read(16384)
if not chunk then if not chunk then
break break
end end
--local buffer = {}
--for i = 1, #chunk do
-- buffer[i] = string.byte(chunk, i) - 128
--end
local buffer = decode(chunk) local buffer = decode(chunk)
while not speaker.playAudio(buffer) do while not speaker.playAudio(buffer) do
os.pullEvent("speaker_audio_empty") os.pullEvent("speaker_audio_empty")
end end
end end
print()