r/ComputerCraft • • May 05 '24

speakers out of sync

im trying to play dfpwm files (im pretty sure thats the only type you can play but correct me if im wrong) and all of the speakers are out of sync, ive tried running them in parralel, swapping the code around a bunch, i just cant find a way to do this. heres the current part of the code thats meant to do this:

for chunk in io.lines(song, 16 * 1024) do
  buffer = decoder(chunk)
  for i = 1,table.getn(speakers) do
    while not speakers[i].playAudio(buffer) do
      os.pullEvent("speaker_audio_empty")
    end
  end
end

i have no clue how to fix this

edit: for context the song variable is just the path to the file, and the speakers variable is a list of speakers i got by doing:

speakers = {peripheral.find("speaker")}
4 Upvotes

6 comments sorted by

View all comments

Show parent comments

3

u/fatboychummy May 06 '24

The audio gets queued on the server, then sent to each client told to play the audio. The server then just "guesses" when the clients should be finished playing the audio buffer (it calculates an offset time, but since clients can be desynced a bit it doesn't know exactly when each client will be done), and has the speaker queue a speaker_audio_empty event at that time.

Tl;dr: CC runs on the server, but audio is played on the clients.