Android Volume Setup process dry version

Source: Internet
Author: User

1. Volume series definition

The maximum volume Max_stream_volume is defined in Audioservice.java, and the phone's settings property can overwrite it.

2. Volume initialization

Initstreamvolume into the audiopolicymanagerbase streamdescriptor mstreams[audiosystem::num_stream_types];

3. Set the master volume

How does the master volume work?

Final volume = Master Volume * Stream volume

4. Set the stream volume

The Setstreamvolumeindex function, in Audiopolicy, uses the Volindextoampl to convert the index integer to the amplitude ratio of the float type, which is the amplitude/reference amplitude.

The specific method is: through the input index to find the corresponding sound pressure value of db, and then the following formula to calculate the amplifier, this value is the amplitude ratio.



A line of code in the function Volindextoampl

FLOAT amplification = exp (decibels * 0.115129f);

That's the formula.


By multiplying this value by the amplitude of the source, the adjusted volume is obtained. This is also the principle of digital gain adjustment.

After this value is obtained, the global variable mstreamtypes is deposited into the Audioflinger, which is Mstreamtypes[stream].volume =value.

When thread tries to play a sound, it does so in preparetracks_l:

int32_t VL = t->prevvolume[0];            int32_t VR = t->prevvolume[1];            Const int32_t Vlinc =t->volumeinc[0];           Const int32_t Vrinc =t->volumeinc[1];            Do {                *out++ + = (VL >> +) * (int32_t) *in++;                *out++ + = (VR >> +) * (int32_t) *in++;                VL + = Vlinc;                VR + = Vrinc;            } while (--framecount);

When the system is muted, it is simple to set the following parameters to 0:

VL = VR = 0;VLF = VRF = VAF = 0.

Setting parameters for Audiomixer

Maudiomixer->setparameter (name, PARAM,AUDIOMIXER::VOLUME0, &VLF);

Maudiomixer->setparameter (name, param,audiomixer::volume1, &VRF);

So finally, the volume is set by audiomixer actually multiplying VOLUME0 and VOLUME1.

As in Track__16bitsstereo

int32_t VL = t->prevvolume[0];            int32_t VR = t->prevvolume[1];            Const int32_t Vlinc =t->volumeinc[0];           Const int32_t Vrinc =t->volumeinc[1];            Do {                *out++ + = (VL >> +) * (int32_t) *in++;                *out++ + = (VR >> +) * (int32_t) *in++;                VL + = Vlinc;                VR + = Vrinc;            } while (--framecount);


Android Volume Setup process dry version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.