Java:快速淡入和淡出 javax.sound.sampled.Clip 的增益

发布于 2024-09-15 16:51:10 字数 456 浏览 2 评论 0原文

我希望在加载到 Java 小程序中的 javax.sound.sampled.Clips 数组中的两个音频剪辑之间平滑过渡。目前,我停止一个剪辑并开始下一个剪辑,但由于音频突然停止和启动,这会产生可听见的咔嗒声。我需要使用剪辑界面,以便可以在剪辑之间进行循环和过渡,并保持相同的轨道位置。

我尝试在停止一个剪辑之前调低增益,然后在开始下一个剪辑时使用FloatControl.Type.MASTER_GAIN将增益调高。如果我想快速改变增益,这需要刷新缓冲区,即使如此,如果我试图太快地改变增益,我也会卡顿和卡顿。另外,刷新缓冲区需要我停止并重新启动剪辑以取回已刷新的缓冲区(因此我不会向前跳过刷新的部分),这会引入我试图摆脱的相同点击声。

有谁有过快速改变增益(200 毫秒内)的经验,比如从 0dB 到 -60dB。我想我可能必须深入到缓冲区级别并开始直接操作这些位,但我不知道如何从剪辑界面实现这一点。

有什么建议吗?

I want to smoothly transition between two audio clips that are loaded into an array of javax.sound.sampled.Clips in my Java applet. At the moment I stop one clip and start the next but this produces audible clicking noises due to the audio stopping and starting abruptly. I need to use the Clip interface so that I can do looping and transition between clips keeping the same track position.

I have tried turning the gain down before stopping one clip and then ramping the gain back up when I start the next using the FloatControl.Type.MASTER_GAIN. This requires flushing the buffer if I want to change the gain quickly and even then I get clicking and stuttering if I try to change the gain too quickly. Plus flushing the buffer requires that I stop and restart the clip to get back the buffer that was flushed (so I don't jump forward over the flushed portion) and this introduces the same clicking that I am trying to get rid of.

Does anyone have experience changing gain quickly (within 200ms), say from 0dB to -60dB. I'm thinking I may have to get down to the buffer level and start manipulating the bits directly but I don't know how to get to this from the Clip interface.

Any suggestions?

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

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

发布评论

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

评论(1

伪装你 2024-09-22 16:51:10

发现了 Clip 类的一个很棒的扩展,它允许您创建具有多个流的单个 Clip 对象,然后使用自定义过渡(例如淡入和淡出)在流之间切换。这消除了烦人的点击声!

我在 HydrogenAudio 论坛上找到了它,作者是一位名叫 googlebot 的很棒的人。它是在 GNU 许可证下开源的。

以下是论坛帖子的链接,描述了创建该课程的计划:
Hydrogenaudio.org/forums/index.php?showtopic=80673(垃圾邮件机器人说我只能发布一个链接:P)

这是一个指向 Google 代码页的链接,您可以在其中获取 Java 类文件:
http://code .google.com/p/advancedabx/source/browse/#hg/AdvancedABX/src/de/uebber/sound/lib

如果您最终使用这些类,您可能会在 open 和 addstream 中发现一些数组边界错误SwitchableArrayClip.java 类中的函数。

您需要将: 更改

// Fill it
    int numRead = 0;
    int offset = 0;
    while (numRead != -1) {
        numRead = stream.read(audioData[0], offset - numRead, len - numRead);
    }

为:

// Fill it
    int numRead = 0;
    int offset = 0;
    while (numRead != -1) {
        numRead = stream.read(audioData[0], offset, len - offset);
        offset += numRead;
    }

由于播放器是线程化的,因此还有一些其他问题,例如使用 setFramePosition。但我会让你弄清楚这些问题,或者你可以在这里提问,我会向你展示我是如何解决这些问题的。

希望这对某人有帮助!

Found an awesome extension to the Clip class that lets you create a single Clip object with multiple streams and then use custom transitions, such as fade in and out, to switch between streams. This gets rid of the annoying clicking!

I found it on the HydrogenAudio forums, written by an awesome guy who goes by the handle googlebot. It's open source under the GNU licence.

Here's a link to the forum posts describing the program the class was created for:
hydrogenaudio.org/forums/index.php?showtopic=80673 (spam bot says I can only post one link :P)

Here's a link to the Google code page where you can grab the Java class files:
http://code.google.com/p/advancedabx/source/browse/#hg/AdvancedABX/src/de/uebber/sound/lib

If you end up using these classes you might find some array bounding errors in the open and addstream functions in the SwitchableArrayClip.java class.

You will need to change:

// Fill it
    int numRead = 0;
    int offset = 0;
    while (numRead != -1) {
        numRead = stream.read(audioData[0], offset - numRead, len - numRead);
    }

to:

// Fill it
    int numRead = 0;
    int offset = 0;
    while (numRead != -1) {
        numRead = stream.read(audioData[0], offset, len - offset);
        offset += numRead;
    }

There are some other issues, such as using setFramePosition, due to the fact that the player is threaded. But I will let you figure those out or you can ask here and I will show you what I did to fix them.

Hope this helps someone!

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