XAudio2 Learn to adjust the volume

Source: Internet
Author: User



XAudio2 volume adjustment is divided into global and channel adjustment and connection volume adjustment. The so-called global is said to set the volume will affect the entire audio stream sound size, channel adjustment means only one channel to adjust the volume, the connection volume setting is to set voice and its output voice channel mapping volume. Give an example to illustrate:



Ixaudio2sourcevoice->ixaudio2submixvoice->ixaudio2masteringvoice,volume of a sphere



An audio graph made up of three voice. Ixaudio2sourcevoice is 2 channels, Ixaudio2submixvoice and Ixaudio2masteringvoice are 5.1 channels.



The volume by default for all voice channels is 1.0.volume of a cone



The audio data is sourcevoice to Submixvoice and eventually to Masteringvoice, during which the sample rate and number of channels are converted.



Setting the global volume can be set using Ixaudio2sourcevoice::setvolume and Ixaudio2submixvoice::setvolume and Ixaudio2masteringvoice::setvolume. Any setting will affect the overall volume size of the entire audio stream. SetVolume interfaces are inherited from the Ixaudio2voice, and the parameters are floating point types. The value is generally 0~1.0 and is used to adjust the volume size. 1.0 means no attenuation and no gain, and 0 for muting. If it is negative,volume formula it can be used to reverse the phase of the audio.



To set the channel volume, you can use Ixaudio2masteringvoice::setchannelvolumes and Ixaudio2sourcevoice: Setchannelvolumes and Ixaudio2submixvoice::setchannelvolumes to change the volume size of a channel. That is the balance of what is usually said. It is also inherited from Ixaudio2voice, which is a floating-point parameter. The value is generally 0~1.0 and is used to adjust the volume size. 1.0 means no attenuation and no gain, and 0 for muting. If it is negative, it can be used to reverse the phase of the audio,volume of a rectangular prism.







<span style="font-size:18px;">HRESULT SetChannelVolumes(
         UINT32 Channels,
         const float *pVolumes,
         UINT32 OperationSet = XAUDIO2_COMMIT_NOW
)
</span>
The first parameter represents the number of channels that this voice contains, and the second parameter represents the volume to be set for each channel, using the float pointer. For example 2-channel, then the second parameter float channelvolumes[2] = {1.0, 0.5}; The parameters and channels are matched, starting from the sitting channel.





The connection volume setting refers to setting the channel volume mapping between the current voice and its output voice, such as 2 channel output to 5.1 channels, and the current voice each channel is mapped to the volume of each channel of Target voice. Setoutputmatrix interfaces are inherited from the Ixaudio2voice, and the parameters are floating point types. The value is generally 0~1.0 and is used to adjust the volume size. 1.0 means no attenuation and no gain, and 0 for muting. If it is negative, it can be used to reverse the phase of the audio.







<span style="font-size:18px;">HRESULT SetOutputMatrix(
         IXAudio2Voice *pDestinationVoice,
         UINT32 SourceChannels,
         UINT32 DestinationChannels,
         const float *pLevelMatrix,
         UINT32 OperationSet = XAUDIO2_COMMIT_NOW
)
</span>
called by the current voice, the first parameter represents the output to the target voice object, the second parameter represents the number of channels of the current voice, the third parameter represents the channel number of Target voice, and the fourth parameter is passed to the target The map volume array for voice.





Array of [sourcechannelsxdestinationchannels] volume levels sent to the destination voice. The level sent from source channel S to destination channel D are specified in the form plevelmatrix[sourcechannelsxd + S ].
The above is described in the document, roughly meaning: Plevelmatrix is a pointer to a floating-point array with an element number of sourcechannelsxdestinationchannels, and the value in the array indicates that the current voice is mapped to the target Voice volume for each channel. The mapping method is: The source channel S is mapped to the volume value of the destination channel D corresponding to the PLEVELMATRIX[SOURCECHANNELSXD + S] in the array.



For example, 2 channels are mapped to 5.1 channels:




output left Input [Array Index] right Input [Array Index]
left 1.0 [0] 0.0 [1]
right 0.0 [2] 1.0 [3]
front Center 0.0 [4] 0.0 [5]
lfe 0.0 [6] 0.0 [7]
rear left 0.8 [8] 0.0 [9]
Rear Right 0.0 [10] 0.8 [11]








Address of this article; http://blog.csdn.net/u011417605/article/details/51037717



AC qq:1245178753



XAudio2 Learn to adjust the volume


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.