CC: Tweaked

CC: Tweaked

57M Downloads

The speaker audio of the client is out of sync with the server

wellcoming opened this issue · 0 comments

commented

Minecraft Version

1.18.x

Version

1.100.8

Details

I am making a dual track audio playback program, but due to some factors (It seems that the server is synchronized, but there are some backlogs of audio cache on the client), the two channels will not play at the same time. Is there any way to restrict the two speakers to keep synchronized?

code:

local dfpwm = require("cc.audio.dfpwm")
local decoder = dfpwm.make_decoder()

f1=fs.open("test1.dfpwm","rb")
f2=fs.open("test2.dfpwm","rb")

local s1_name="speaker_0"
local s2_name="speaker_1"

local s1=peripheral.wrap(s1_name)
local s2=peripheral.wrap(s2_name)

function play1()
    local buffer=decoder(f1.read(1024))
    local name
    while not s1.playAudio(buffer) do
        while name~=s1_name do
            _,name=os.pullEvent("speaker_audio_empty")
        end
        name=nil
    end
end

function play2()
    local buffer=decoder(f2.read(1024))
    local name
    while not s2.playAudio(buffer) do
        while name~=s2_name do
            _,name=os.pullEvent("speaker_audio_empty")
        end
        name=nil
    end
end

while true do
    parallel.waitForAll(play1,play2)
end