glava
glava copied to clipboard
Changing audio source on the fly?
Hi I'm using different audio devices(for example, HD Audio at home and a usb DAC at work), I 'm wondering is it possible to change the audio source manually/automatically when changing the default sink?
I will look into this, perhaps using a "default"
option or something that automatically handles changes to the default sink. It might be a bit awkward if the two devices don't sample at the same rate though.
Just curious. What will happen if sample rate changed? Don't Pulse Audio have only one primary and one alternative sample rates?
Just curious. What will happen if sample rate changed?
Nothing will break, but its ideal to sample at multiples of the sampling rate of the audio source, otherwise input has to be interpolated or segmented, which can produce unfavourable output in GLava.
pavucontrol lets you change it under the "recording" tab, if there isn't an option to change the input but you see glava, check out your configuration profile
@Aaahh Thanks for the hint!
I ended up with a script to do that:
pactl move-source-output $(pactl list source-outputs short | grep $(pactl list short clients | grep glava | cut -f 1) | cut -f 1) @DEFAULT_MONITOR@
I think it's still nice to have this implemented in GLava, so I'm going to leave this issue open for now.
Looking at this again, I'm not particularily sure how to implement this. I can do a few things here:
-
Frequently call
pa_context_get_server_info
, destroying & re-creating the audio monitor as the default sink changes (somewhat messy) -
Change the audio handling code such that multiple audio sinks can be used for a single GLava instance (much cleaner, doesn't require spamming the PA server for info). This method, however, would not allow you to use audio sinks that have yet to be instantiated under PA (ie. plugging in a new device).
Ideally, there would be some code to notify GLava of any changes to the default device, but I'm not sure if it's possible through PA or even something I should be doing within GLava. Perhaps a udev rule in combination with @op8867555's script is an acceptable solution for now -- in which case I would gladly add a complete solution to the README.md
file.
I think subscribing pulseaudio events might also be a good way to implement it. This script captures the idea:
LANG=C pactl subscribe | grep "Event 'change' on server" --line-buffered | while read p; do
GLAVA=$(pactl list short clients | grep glava | cut -f 1);
FROM=$(pactl list source-outputs short | grep $GLAVA | cut -f 1);
pactl move-source-output $FROM @DEFAULT_MONITOR@;
done
I guess one possible way to do this in GLava is creating a separate pulseaudio mainloop thread to subscribe/handle server events, instead of rewriting whole pulse.c to use async api (not quite sure which would performance better).
Following up on this, not sure if I missed something on docs. I use a separate speaker (Google Nest audio) for output and Glava doesn't work with that. Some context: I have a Lenovo Legion 7i but it doesn't have audio support on linux, hence ended up with an external speaker. If I change Spotify's output from Nest to this device (7i) it starts working fine.
Is there some way I can have Glava working for this specific device output?
Edit: It works when I connect it with Bluetooth, not when I'm casting from Spotify to Nest Audio. Guess I'm sticking with bluetooth unless someone has a solution for that
I have found that I suffer from this issue when my bluetooth headphones (a) power off then on or (b) switch to another connected device then back, as happens often throughout a workday.
I have been killing the GLava process then starting it again each time. The discussion here gives me enough to at least workaround the issue. Thanks.
Following up on this, not sure if I missed something on docs. I use a separate speaker (Google Nest audio) for output and Glava doesn't work with that. Some context: I have a Lenovo Legion 7i but it doesn't have audio support on linux, hence ended up with an external speaker. If I change Spotify's output from Nest to this device (7i) it starts working fine.
Is there some way I can have Glava working for this specific device output?
Edit: It works when I connect it with Bluetooth, not when I'm casting from Spotify to Nest Audio. Guess I'm sticking with bluetooth unless someone has a solution for that
Yeah, if you are casting, then you device isn't actually outputting the audio. Your Nest Audio will be streaming the music directly from Spotify, so I doubt there will ever be a solution for that.
the script from https://github.com/jarcode-foss/glava/issues/21#issuecomment-374180709 works perfectly for me! gonna add it to my session startup scripts! maybe this should be added to the docs