Audio Manager Volume Ramping
Introduction
People who use the iPhone may be impressed by its volume ramping feature, that is, if you receive or make a telephone call while you are listening to music, the music volume is gradually fades then disappears and then the ringtone starts. After the call is ended, the music is gradually returns to the previous level. It is cool, and the user experience is very good!
Our audio manager will also provide this functionality to enhance the user experience while audio manager decides to mute/pause some audio streams.
This blog is to introduce how we are going to enable this volume ramping feature. This feature is currently under development. If you have questions you can contact Zheng, Huan (huan.zheng@intel.com) and Guo, Jia.
How we do that
Attenuate/Amplify Factor
To achieve the volume ramping effect with a duration of X seconds, we need to apply attenuate/amplify factors to a chunk of audio data which is of X seconds long. And the value of the factor changes gradually according to the length of time.
To get the factor, we will use the current existing envelop inside PA and fix its bugs. (3 bugs of envelop.c have been found and 2 of them are calculation overflow). The current PA envelop supports a maximum of 4 points, so it could provide a similar ADSR envelop (http://en.wikipedia.org/wiki/ADSR_envelope). But we will only use 2 points to get the linear factor. Below is a picture which depicts how we get the linear factor, it's simple and efficient and enough for us to get the ramping effect.
Calculation formula is : y3 = y1 + ((y2 - y1) * (x3 - x1)) / (x2 - x1)

Changes In PA
The code of PA that deals with volume and mix does not consider volume ramping at all, and code on this aspect is not modular. We will need to change the logic of pa_sink_input_peek, pa_mix, and possibly some other places to make volume ramping work. Current logic is complex. What we are doing is like adding a gear into a running engine, so we need to spend a lot of time on this aspect.
Our Final Target
Introduce 2 new API-to-PA module developers inside PA, to support volume ramping.
1,void pa_sink_input_set_volume_with_ramping (pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t duration);
2,void pa_sink_input_set_mute_with_ramping (pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t duration);
duration is in microsecond, E.g. 5000 * PA_USEC_PER_MSEC means ramping duration is 5 seconds.PA_USEC_PER_MSEC is defined as 1000 in PA.
By the time volume ramping is enabled, when AM decides to mute some audio streams, it will mute with ramping, so the user experience may be better. And we may consider to add a configuration item to let the app choose whether to be muted with ramping or just directly mute.
And if the maintainer agrees, we will export this feature to standard PA APIs, so that all PA developers can use this feature to enhance the audio effect.
The patch has been accepted by PulseAudio community, it will be available since 0.9.17. if you can't wait, you can taste it first in moblin :)
Quote from Lennart:
Hmm, so your three patches look pretty good.
..........
we'll have this fr 0.9.17.
- zbt's blog
- Login or register to post comments
- Printer-friendly version
Comments (11 total)
Hello
Great post really interesting
Vimax | Vigrx | Penis Enlargement Pills
on VolumeShape algorithm
Hi,
i have been working on VolumeShape algorithm for long time. i think, i have version in scilab and the same can be ported on to c as well. I dont know who is going to do the same. In case if you are interested i can find a time to create a c code for you and the same can be integrated with release and check out things in detail.
kind regards
jk
Thanks
Hi, your code may help the envelop component inside Pusle Audio. You can write a mail to Pulse audio community. :)
For here, it may not need complex algorithm. thanks any way!
Definitely
I second forum ASAP.
Very good
I think I will join it too.
Forum
I think moblin.org needs a forum ASAP.
Roadmap
It's a great feature I think.
I can't find a roadmap anywhere. Is there a planned date for actual release to be out? And what should we expect from the release?
There's no roadmap by now,
There's no roadmap by now, because we also have other development work to do. But we want to enable it within June, and submit patch to PA community. Hope Lennart will like it.
About this formula...
I think the correct one is y3 = y1 + ((y2 - y1) * (x3 - x1)) / (x2 - x1)
My type wrong, thanks for
My type wrong, thanks for pointing out. :)
This is a good feature.
I think I will join this group.