[pulseaudio-discuss] Flat volumes and restoring the app volume
tanuk at iki.fi
Mon Jan 31 12:48:46 PST 2011
On Mon, 2011-01-31 at 22:27 +0300, Gregory Petrosyan wrote:
> On Mon, Jan 31, 2011 at 1:45 PM, Colin Guthrie <gmane at colin.guthr.ie> wrote:
> > ...
> Thanks a lot for the explanation!
> >> I am asking these, because I've managed to make an app restore the
> >> volume properly using ext-stream-restore.h, but when I turn the flat
> >> volume on, behaviour is counter-intuitive to say at least.
> > Can you elaborate on this a little? When you say "you've manage to make
> > an app restore the volume properly using ext-stream-restore.h" what do
> > you mean? Do you mean you are making an editor for the stream restore
> > database or are you just meaning that you have an audio producing app
> > and you are manually using ext-stream-restore.h to get it's saved volume
> > and are doing something with it manually to set it's own volume?
> > If the latter, don't do that, the server handles all that for you
> > automatically. If the former then cool.
> I have an audio player, and I want it to
> a) save/restore the volume on shutdown/startup
> b) be able to show the "future" volume and modify it after the
> startup, but before the playback
> b) is a problem: I either have to have stream open all the time (but I
> can't do that since I do not know the sample format before the start
> of the playback, so I can't create a stream beforehand), or to
> manually read/write the m-s-r database.
> It seems that, unfortunately, it is almost impossible to make such a
> basic functionality work with PA, if using flat volumes. Because when
> using m-s-r database + flat volumes, although the "real volume"
> remains the same after the restart, e.g. displayed volume is wrong.
> Here's an example:
> (app | system)
> 60% | 100%
> [decrease the system volume]
> 31% | ~50%
> [restart the app, do not start the playback]
> 60% | ~50% (60% is more or less what is in the m-s-r database I assume)
> [start the playback]
> 31% | ~50% (finally, displayed volume is correct)
As I explained in my previous mail (I didn't notice before hitting send
that you already sent this message), m-s-r works with decibels, and
while the stream is not playing, you can calculate the new volume by
taking the current sink volume in decibels and subtracting from that the
amount of attenuation stored in the m-s-r database. There's just one
problem, this doesn't actually work reliably, because you don't what the
current sink volume is, because there's no concept of "current sink"
while you're not playing anything.
So, it's true that it's almost impossible to implement the "basic
functionality" of showing the future volume in a media player while not
playing anything. You could achieve something that is quite reliable in
practice, though: read also the saved device of the same stream-restore
entry that you're reading the volume from. If there's no saved device,
use the default sink (see pa_context_get_server_info()).
Before doing that, however, I would like to hear why you need to show
the future volume. So that the user can set the volume higher or lower
before starting playback? Why is the system volume inadequate for doing
that? What is the use case where the user wants to turn up or down the
music player volume before hearing anything, and only the music player
volume, not any other application?
More information about the pulseaudio-discuss