如何在 AS3 中将声音放大指定的分贝数?

发布于 2024-07-25 16:01:10 字数 1102 浏览 7 评论 0原文

几天前,这是我的问题,我找到了答案。 也许这会帮助别人。

A. 问​​题的第一部分:可以使用Flash放大声音吗? SoundTransform 的 AS3 文档这样描述了音量属性:

“音量,范围从 0(静音)到 1(最大音量)。

从表面上看,这意味着您只能使声音更安静。事实上,如果您提供一个值大于 1 (1.0),声音会被放大,但你可以做到,而且对于声音来说,你可以避免很多(音乐不太宽容,所以请尝试一下。方法不进行动态压缩,这更适合音乐。)

B. 问题的第二部分:执行操作的顺序

正确:

soundTransform = new SoundTransform();
soundTransform.volume = volume * volumeAdjustment;
audioChannel.soundTransform = soundTransform;

错误:

soundTransform = new SoundTransform();
audioChannel.soundTransform = soundTransform;
soundTransform.volume = volume * volumeAdjustment;

我在 CS3 和 CS4 中做了一些测试,并得到了不同的结果。在 CS3 中,我可以在“audioChannel.soundTransform = soundTransform;”之后设置变换的音量,但在 CS4 中它没有效果,而 CS4 使用 pass 来设置 soundTransform。 CS4 方法设计得更好,但确实破坏了我在 CS3 中运行良好的代码。

C. 最后一个问题是如何将分贝值转换为可以乘以音量的系数,以将声音放大(或静音)所需的量。

var multiplier:Number = Math.pow(10, decibels / 20); // Power vs. amplitude

请注意,“分贝”可以是正数(用于放大)或负数(用于使更安静)。 如果分贝为零,则不会发生变化。

3 分贝值将使幅度(非常接近)加倍。 10 分贝的值将使音量增加十倍(准确地说)。

A few days ago, this was my question, and I found the answer. Maybe this will help someone else.

A. The first part of the problem: can you amplify sound using Flash? The AS3 documentation for SoundTransform says this about the volume attribute:

"The volume, ranging from 0 (silent) to 1 (full volume).

At face value, this means you can only make sounds quieter. In fact, if you supply a value greater than one (1.0), sounds will be amplified. You risk saturating the sound and getting poor quality, but you can do it, and for voice, you can get away with a lot. (Music is less forgiving, so experiment. This method does not do dynamic compression, which is better suited to music.)

B. The second part of the problem: the order in which you do things.

RIGHT:

soundTransform = new SoundTransform();
soundTransform.volume = volume * volumeAdjustment;
audioChannel.soundTransform = soundTransform;

WRONG:

soundTransform = new SoundTransform();
audioChannel.soundTransform = soundTransform;
soundTransform.volume = volume * volumeAdjustment;

I did some testing in CS3 and CS4, and got different results. In CS3, I could set the volume on the transform AFTER "audioChannel.soundTransform = soundTransform;" and everything was fine. But in CS4 it had no effect. I suspect that CS3 used pass by reference to set the soundTransform, while CS4 uses pass by value semantics and copies the object passed into it. The CS4 approach is better designed, but did break my code that worked fine in CS3.

C. The last question, is how to convert a decibel value to a factor that can be multiplied by the volume to amplify (or quiet) the sound by the desired amount.

var multiplier:Number = Math.pow(10, decibels / 20); // Power vs. amplitude

Note that "decibels" may be a positive number (to amplify) or a negative number (to make quieter). If decibels is zero, no change occurs.

A value for decibels of 3 will (to a close approximation) double the amplitude.
A value of 10 decibels will increase the volume tenfold (exactly).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末 2024-08-01 16:01:10

您的分贝计算实际上应该使用 20,而不是 10:

var multiplier:Number = Math.pow(10, decibels / 20);

数字音频是幅度,而不是功率 (它表示声压,而不是声功率)。

Your decibel calculation should actually use 20, not 10:

var multiplier:Number = Math.pow(10, decibels / 20);

Digital audio is amplitude, not power (it's a representation of sound pressure, not sound power).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文