将对数音量定向到线性音量滑块 [英] Directsound logarithm volume to linear volume slider

查看:231
本文介绍了将对数音量定向到线性音量滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DirectX.DirectSound开发音乐播放器。我的音量有问题。直达音量是对数。这意味着,与大声声音相比,无声声音对振幅的微小变化更加敏感。这也意味着,使用线性音量滑块时,我们对音量变化有对数感觉,但感觉并不正确。我的问题是:如何使其线性?
我的代码直到这里是:

I am developing an music player with DirectX.DirectSound. I have a problem with the volume. The directsound volume is logarithm. This means that with silent sounds, is much more sensitive to small variations in amplitude than with loud sounds. It also means that with a linear volume slider we have a logarithmic sensation of volume variations, and that just doesn't feel right. My question is: How can I make it linear? My code until here is:

 if (trkBalance.Value == trkBalance.Minimum)
            {
                foreGroundSound.Volume = (int)DS.Volume.Min;

            }
            else if (trkBalance.Value == trkBalance.Maximum)
            {
                foreGroundSound.Volume = (int)DS.Volume.Max;
            }
            else
            {
               foreGroundSound.Volume = (int)(-5000 * Math.Log10(100 - trkBalance.Value));
            }


推荐答案

有一条经验法则确定响度:

There is a rule of thumb to determine the perceived loudness:


相差10 dB(doubleValue)会产生两倍于原始声音的声音/一半的声音。

A difference of 10 dB (doubleValue) results in a sound twice / half as loud as the original source.

考虑到这一点,我们可以创建一个公式,将衰减映射到声压级。

With that in mind we can create a formula that maps the attenuation to the sound pressure level.

但是首先我们必须计算实际衰减(作为分数)。 DirectSound可以将声音衰减100 dB,即 1/2 ^(100 / doubleValue)的衰减。这是最小跟踪栏值的值。最大值为1(不变)。总的来说:

But at first we have to calculate the actual attenuation (as a fraction). DirectSound can attenuate a sound by 100 dB, which is an attenuation of 1/2^(100/doubleValue). This is the value for the minimum trackbar value. The maximum value is 1 (no change). So overall:

doubleValue = 10;
minimumAttenuation = 1/2^(100/doubleValue)
attenuation = minimumAttenuation + trkBalance.Value / 100 * (1 - minimumAttenuation);

现在,我们有了一个有效范围内的值。现在我们需要找到此衰减的声压级。

Now we have a value within valid range. Now we need to find the sound pressure level for this attenuation.

我们知道响度每10 db(doubleValue)会翻一番:

And we know that the loudness doubles every 10 db (doubleValue):

attenuation = 2^(db/doubleValue) //ln
ln(attenuation) = db / doubleValue * ln(2)
db = doubleValue * ln(attenuation) / ln(2)

由于DirectSound的分辨率为百分贝,因此您可以使用

And since DirectSound takes hundreths dB, you can use

foreGroundSound.Volume = db * 100;






这些只是基于维基百科信息的一些理论思想。它可能会或可能不会。只需尝试一下。


Those are just some theoretical thoughts based on wikipedia information. It might or might not work. Just try it.

这篇关于将对数音量定向到线性音量滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆