fix shi up

This commit is contained in:
Soph :3 2025-11-11 11:31:50 +02:00
parent 33a38d3547
commit 81337b7f4b
3 changed files with 10 additions and 46 deletions

View file

@ -2,8 +2,8 @@
## in development audio player from pipewire to cc ## in development audio player from pipewire to cc
pfowrd -> ssh -R 0.0.0.0:5821:localhost:8080 vps pfowrd -> `ssh -R 0.0.0.0:5821:localhost:8080 vps`
lua -> wget run https://files.sad.ovh/public/livestream-cc/.installer.lua lua -> `wget run https://files.sad.ovh/public/livestream-cc/.installer.lua`
rust -> cargo run -- --device pipewire --bind '127.0.0.1:8080' --frame-ms 300 --sample-rate 48000 --stereo rust -> `cargo run -- --device pipewire --bind '127.0.0.1:8080' --frame-ms 300 --sample-rate 48000 --stereo`

View file

@ -50,34 +50,16 @@ function ui()
end end
local dcode = require "dcode" local dcode = require "dcode"
-- Use the normal decoder for real audio; TrueBit is just for testing local make_decoder = dcode.make_dec
local make_decoder = dcode.make_truebit_dec -- or dcode.make_truebit_dec
local ws = http.websocket("ws://vps.sad.ovh:5821/ws") local ws = http.websocket("ws://vps.sad.ovh:5821/ws")
-------------------------------------------------------
-- metadata
-------------------------------------------------------
local raw = ws.receive() local raw = ws.receive()
local meta = textutils.unserializeJSON(raw) local meta = textutils.unserializeJSON(raw)
print(("codec=%s rate=%dHz frame_ms=%d ch_enc=%d frame_bytes/chan=%d") print(("codec=%s rate=%dHz frame_ms=%d ch_enc=%d frame_bytes/chan=%d")
:format(meta.codec, meta.sample_rate, meta.frame_ms, meta.channels_encoded, meta.frame_bytes)) :format(meta.codec, meta.sample_rate, meta.frame_ms, meta.channels_encoded, meta.frame_bytes))
---@return string[]
--[[local function find_speakers()
local names = peripheral.getNames()
local found = {}
for _, n in ipairs(names) do
if peripheral.getType(n) == "speaker" then
table.insert(found, n)
if #found == 2 then break end
end
end
return found
end]]
--local speakers = find_speakers()
--if #speakers == 0 then error("no speaker found") end
local namesSpkrsL = { local namesSpkrsL = {
"speaker_756", "speaker_756",
"speaker_755", "speaker_755",
@ -97,27 +79,18 @@ for i=1,#namesSpkrsL do
spkrsR[i] = peripheral.wrap(namesSpkrsR[i]) spkrsR[i] = peripheral.wrap(namesSpkrsR[i])
end end
--print("SpeakerL: " .. (speakers[1]).. ", SpeakerR: " .. (speakers[2] or speakers[1] ))
-------------------------------------------------------
-- deque queue implementation (fast push/pop)
-------------------------------------------------------
local function make_queue() return { buf = {}, head = 1, tail = 0 } end local function make_queue() return { buf = {}, head = 1, tail = 0 } end
local function q_len(q) return q.tail - q.head + 1 end local function q_len(q) return q.tail - q.head + 1 end
local function q_push(q, v) q.tail = q.tail + 1; q.buf[q.tail] = v end local function q_push(q, v) q.tail = q.tail + 1; q.buf[q.tail] = v end
local function q_pop(q) if q.head > q.tail then return nil end local v=q.buf[q.head]; q.buf[q.head]=nil; q.head=q.head+1; return v end local function q_pop(q) if q.head > q.tail then return nil end local v=q.buf[q.head]; q.buf[q.head]=nil; q.head=q.head+1; return v end
local function q_trim_to(q, n) while q_len(q) > n do q_pop(q) end end local function q_trim_to(q, n) while q_len(q) > n do q_pop(q) end end
-------------------------------------------------------
-- buffering policy
-------------------------------------------------------
local MIN_BUFFER, TARGET_BUFFER, MAX_BUFFER = 5, 10, 30 local MIN_BUFFER, TARGET_BUFFER, MAX_BUFFER = 5, 10, 30
local frames = make_queue() local frames = make_queue()
-------------------------------------------------------
-- helper logging
-------------------------------------------------------
local function log(event, extra) local function log(event, extra)
local t = textutils.formatTime(os.time(), true) local t = textutils.formatTime(os.time(), true)
@ -138,9 +111,8 @@ local function log(event, extra)
--ui() --ui()
print(("[%s] %-12s | %s"):format(t, event, extra or "")) print(("[%s] %-12s | %s"):format(t, event, extra or ""))
end end
-------------------------------------------------------
-- receiver
-------------------------------------------------------
local function receiver() local function receiver()
while true do while true do
local msg = ws.receive((meta.frame_ms / 1000) * 1.5) local msg = ws.receive((meta.frame_ms / 1000) * 1.5)
@ -158,9 +130,7 @@ local function receiver()
end end
end end
-------------------------------------------------------
-- playback
-------------------------------------------------------
local function player() local function player()
local buffering = true local buffering = true
local last_log = 0 local last_log = 0
@ -243,7 +213,6 @@ local function player()
end end
end end
-- Pacing is governed by speaker_audio_empty waits above.
local n = q_len(frames) local n = q_len(frames)
if n < 1 then if n < 1 then
log("underrun", "ran out after frame — rebuffering") log("underrun", "ran out after frame — rebuffering")

View file

@ -291,11 +291,6 @@ fn pick_stream_config(
Ok((default_cfg.config(), sf)) Ok((default_cfg.config(), sf))
} }
/// Build and return a CPAL input stream that performs:
/// - downmix to mono
/// - convert to i8 PCM [-128,127]
/// - DFPWM encode in frames
/// - broadcast frames over a channel
fn build_cpal_stream( fn build_cpal_stream(
device: &Device, device: &Device,
cfg: &StreamConfig, cfg: &StreamConfig,