haileys / bark

live sync audio streaming for local networks
GNU Affero General Public License v3.0
663 stars 11 forks source link

bring cpal back? #10

Open ckiee opened 3 months ago

ckiee commented 3 months ago

hi ! im doing Cursed Audio Shit and would like to have cpal so i can compile with asio so i can cast my host (linux) audio into my windows vm (who, for cursed reasons, has way better audio) when the vm is active

ckiee commented 3 months ago

but I see cpal was removed recently, & im wondering what happened? were you just chasing your own latency goals?

ckiee commented 3 months ago

windows port ongoing in ckiee:wintest

ckiee commented 3 months ago

okay it turns out windows is not a fan of multicast but I hacked around it by turning off the multicast stuff (a bit in a stash too there for the host to run) and packets were flowing everywhere but no audio came out the other end. i give up for now, maybe you can enlighten me Hailey, apologies in advance for the extremely messy code I am very tired. (it's actually good in the first commits and has nice things you can cherry-pick if you'd like)

thanks for making bark :purple_heart:

haileys commented 3 months ago

Hi @ckiee! Thanks for opening this issue, I love to hear from people who are using Bark and finding it a useful piece of software!!

Your intuition that cpal was removed for latency reasons is correct. cpal's callback oriented API ended up introducing a small amount of double buffering above what Bark can achieve using ALSA directly, and this prevented me from squeezing all the latency I could out of it. Plus, using ALSA directly means we have access to knobs we didn't have using cpal, like setting a custom audio device (eg. the pipewire:NODE=1234 syntax) without having to set an environment variable and rely on pipewire-alsa reading from env further down the call stack.

I would be supportive of merging Windows ASIO support into main when it's ready, and I'll check out your branch when I get a chance.

You may want to check out the coreaudio branch, which implements the macOS CoreAudio API alongside ALSA. You'll almost certainly want to rebase your changes on top of this branch, as it includes some structural changes to support multiple audio driver interfaces.

ckiee commented 3 months ago

Hi @ckiee! Thanks for opening this issue, I love to hear from people who are using Bark and finding it a useful piece of software!!

:purple_heart:

I would be supportive of merging Windows ASIO support into main when it's ready, and I'll check out your branch when I get a chance.

feel free to, but it's incredibly messy as I was trying to get over the finish line in one day and didn't, which made me look for existing solutions and I found the excellent SonoBus which will work for now (: maybe one day I will come back to this, but no promises :P — there are a few commits I could split out to make bark build on Windows too if you'd like; switching nix to rustix (win-compat) and using the windows-rs APIs for a few other things.

I got to the point where packets were being exchanged but there were a lot of x00s even with audio playing and I wasn't in the headspace to continue debugging. But it was a nice journey regardless… My first time touching Windows APIs :P