FMOD 无缝循环和序列播放

发布于 2024-12-03 07:09:45 字数 899 浏览 4 评论 0原文

我开始使用 FMOD 库,因为我需要在 C# 应用程序中不间断地播放声音(循环中的一个声音和序列中的许多声音)。谁能告诉我正确的方法吗?我尝试根据示例制作一些东西,但它没有像我希望的那样工作。 首先,当我尝试设置声音是否循环播放时,

if (value)  
    sound1.setMode(FMOD.MODE.LOOP_NORMAL);
else 
    sound1.setMode(FMOD.MODE.LOOP_OFF);

没有任何反应。只有当我在开始播放之前设置模式时,它才能正常工作。

第二个问题是:如何通知声音已结束?我尝试这样做:

channel.setCallback(eofCallback);

其中 eofCallback 是对 SoundEndCallback 的引用

    private FMOD.RESULT SoundEndCallback(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, IntPtr commanddata1, IntPtr commanddata2)
    {
        FMOD.RESULT result;

        if (type == FMOD.CHANNEL_CALLBACKTYPE.END)
        {
            //logic here
        }
        return FMOD.RESULT.OK;
    }

,但只有当我在通道上手动调用 stop() 时才会到达此回调,而不是在曲目结束时到达。

或者最终你知道还有其他图书馆可以轻松满足我的需要吗?我选择 FMOD,因为它非常流行,但我不喜欢它老式的类似 C++ 的编码方式(没有事件、没有异常等)。

I started using FMOD library, because I need to play sounds without gaps in C# application (both one sound in a loop and many sounds in a sequence). Can anyone show me the correct way to do it? I tried make something based on examples, but it's not working as I would like it to work.
Firstly, when I try to set if the sound is looped, while it's playing,

if (value)  
    sound1.setMode(FMOD.MODE.LOOP_NORMAL);
else 
    sound1.setMode(FMOD.MODE.LOOP_OFF);

nothing is going on. It only works fine, when I set th mode, before I start playback.

The second issue is: how can I be notified that the sound has reached the end? I tried to do it this way:

channel.setCallback(eofCallback);

where eofCallback is a reference to SoundEndCallback

    private FMOD.RESULT SoundEndCallback(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, IntPtr commanddata1, IntPtr commanddata2)
    {
        FMOD.RESULT result;

        if (type == FMOD.CHANNEL_CALLBACKTYPE.END)
        {
            //logic here
        }
        return FMOD.RESULT.OK;
    }

But this callback is reached only when I manually invoke stop() on channel, not when the track ends.

Or eventually do you know any other library that would give me easily what I need? I chose FMOD, because it's quite popular, but I don't like its oldschool C++-like way of coding (no events, no exceptions, etc.).

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

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

发布评论

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

评论(2

懷念過去 2024-12-10 07:09:45

我对第二个问题有答案:要得到通知,您必须首先像前面提到的那样设置回调,然后您必须使用 System.update() 方法(必须在循环中定期调用它)。这是一种民意调查,

And I have teh answer for my second question: to get notified you have to firstly set callback as mentioned before, and after that you've got to use System.update() method (it must be called periodically in a loop). This is a kind of polling,

亚希 2024-12-10 07:09:45

要在运行时设置声音的循环模式,请使用 Channel::setMode,Sound::setMode 就像为从该声音播放的任何通道设置默认值(它不会影响当前播放的声音)。

至于 Channel::setCallback,请确保定期调用 System::update 以便为诸如声音播放到最后之类的事件触发回调。

To set the loop mode of a sound at runtime use Channel::setMode, Sound::setMode is like setting the defaults for any channels played from that sound (it won't affect currently playing sounds).

As for Channel::setCallback, make sure you are calling System::update regularly to have the callbacks fire for events like the sound playing to the end.

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