【问题标题】:Get the inverse of a function, millibels to percentage & percentage to millibels获取函数的倒数,毫贝到百分比和百分比到毫巴
【发布时间】:2016-03-17 21:30:40
【问题描述】:

这里的音频新手和数学挑战。我正在使用使用 -10000 到 0 范围的 DirectSound,将其转换为 0-100 范围。 我发现这个函数here 可以根据百分比获取毫:

    private int ConvertPercentageToMillibels(double value)
    {
        double attenuation = 1.0 / 1024.0 + value / 100.0 * 1023.0 / 1024.0;
        double db = 10 * Math.Log10(attenuation) / Math.Log10(2);
        return (int)(db * 100);
    }

我需要帮助来获得这个函数的倒数,基本上是为了获得基于毫贝的百分比。这是我到目前为止所得到的,但它不起作用:

    private double ConvertMillibelsToPercentage(int value)
    {
        double db = value / 100;
        double attenuation = Math.Pow(10, db) / 10 * Math.Pow(10, 2);
        double percentage = (1.0 * attenuation) - (1024.0 * 100.0 / 1023.0 * 1024.0);
        return percentage;
    }

【问题讨论】:

    标签: c# directx directshow directsound


    【解决方案1】:

    给你!

    private double ConvertMillibelsToPercentage(int value)
    {
        double exponent = ((value / 1000.0) + 10);
        double numerator = 100.0 * (Math.Pow(2, exponent) - 1);
        return numerator / 1023.0;
    }
    

    由于在 int 和 double 之间转换会产生明显的问题,答案会略有不同。

    编辑:根据教如何钓鱼的要求,这里是达到解决方案的第一个数学步骤。我没有展示整件事,因为我不想破坏所有的乐趣。除非另有说明,否则所有日志函数都应视为 Log base 10:

    millibels = db*100; // Beginning to work backward
    millibels = 10*Log(attenuation)*(1/Log(2))*1000; // Substituting for db
    millibels = 1000*Log(attenuation)/Log(2); // Simplifying
    

    设毫贝 = m。那么:

    m = 1000*Log(attenuation)/Log(2);
    

    从这里你可以走两条路,你可以使用日志的属性来找到:

    m = 1000* Log_2(attenuation);// That is, log base 2 here
    attenuation = 2^(m/1000);
    

    或者您可以忽略该特定属性并意识到:

    attenuation = 10^(m*Log(2)/1000);
    

    通过插入您知道的衰减值,尝试从上述选项之一中计算出来:

    attenuation = (1/1024)+(percentage/100)*(1023/1024);
    

    然后求解百分比。祝你好运!

    PS 如果您遇到这样的问题,我强烈建议您去数学堆栈交换 - 那里有一些聪明的人喜欢解决数学问题。

    或者,如果您特别懒惰并且只想得到答案,您通常可以简单地将这些内容输入 Wolfram Alpha,它会“神奇地”为您提供答案。 Check this out

    【讨论】:

    • 查看编辑 - 展示了求解百分比的最初几个步骤。希望对你钓鱼有帮助!
    猜你喜欢
    • 2011-03-07
    • 2018-10-14
    • 2021-11-28
    • 1970-01-01
    • 2020-11-22
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多