使用 FMOD 仅播放声音的一部分

发布于 2024-08-22 23:31:02 字数 230 浏览 7 评论 0原文

我尝试使用 FMOD 仅播放声音的一部分,例如 200000 帧文件的第 50000-100000 帧。 我找到了几种前进的方法(即在第 50000 帧开始播放),但我还没有找到一种方法来确保声音在 100000 帧停止播放。有没有什么方法 FMOD 可以在无需添加 lbsndfile 的情况下本地执行此操作或者图片中的类似内容?

我还应该提到我正在使用流媒体选项。我必须假设这些声音是任意大的并且无法轻松/快速地加载到内存中。

I'm trying to play only part of a sound using FMOD, say frames 50000-100000 of a 200000 frame file.
I have found a couple of ways to seek forward (i.e. to start playback at frame 50000) but I have not found a way to make sure the sound stops playing at 100000. Is there any way FMOD can natively do this without having to add lbsndfile or the like into the picture?

I should also mention that I am using the streaming option. I have to assume that these sounds are arbitrarily large and cannot be comfortably/quickly loaded into memory.

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

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

发布评论

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

评论(3

玩物 2024-08-29 23:31:02

您可以使用 Channel::setDelay 来采样准确的声音开始和停止。使用 FMOD_DELAYTYPE_DSPCLOCK_START 设置声音的开始时间,使用 FMOD_DELAYTYPE_DSPCLOCK_END 设置结束时间。

查看 Channel::setDelay、FMOD_DELAYTYPE、System::getDSPClock 的文档。

You can use Channel::setDelay for sample accurate starting and stopping of sounds. Use FMOD_DELAYTYPE_DSPCLOCK_START to set the start time of the sound and FMOD_DELAYTYPE_DSPCLOCK_END to set the end time.

Check out the docs for Channel::setDelay, FMOD_DELAYTYPE, System::getDSPClock.

渔村楼浪 2024-08-29 23:31:02

当到达所需点时,您应该能够使用流回调来停止流。

选项 1:创建流时,将 lenbytes 设置为您要播放的帧数的偶数除数。在您的示例中,将“lenbytes”设置为 5000,然后在回调中保留一个计数器。当到达 10 时,停止直播。

选项 2:使用 FSOUND_Stream_AddSyncPoint,并将 pcmoffset 设置为您所需的停止点。使用 FSOUND_Stream_SetSyncCallback 注册回调。在回调中停止流。

You should be able to use the streaming callback to stop the stream when you get to the desired point.

Option 1: When you create the stream, set lenbytes to an even divisor of the number of frames you wish to play. In your example, set 'lenbytes' to 5000, then keep a counter in the callback. When you get to 10, stop the stream.

Option 2: use FSOUND_Stream_AddSyncPoint with pcmoffset set to your desired stopping point. Register a callback with FSOUND_Stream_SetSyncCallback. Stop the stream in the callback.

属性 2024-08-29 23:31:02

要以样本 50,000 开始播放并以 100,000 结束播放,您可以执行以下操作,假设声音文件采样率和系统采样率相同。由于 DSP 时钟在系统输出样本中工作,您可能需要进行一些数学计算来根据输出速率调整最终样本。有关声音采样率,请参阅 Sound::getDefaults;有关系统速率,请参阅 System::getSoftwareFormat。

unsigned int sysHi, sysLo;

// ... create sound, play sound paused ...

// Seek the data to the desired start offset
channel->setPosition(50000, FMOD_TIMEUNIT_PCM);

// For accurate sample playback get the current system "tick"
system->getDSPClock(&sysHi, &sysLo);

// Set start offset to a couple of "mixes" in the future, 2048 samples is far enough in the future to avoid issues with mixer timings
FMOD_64BIT_ADD(sysHi, sysLo, 0, 2048);
channel->setDelay(FMOD_DELAYTYPE_DSPCLOCK_START, sysHi, sysLo);

// Set end offset for 50,000 samples from our start time, which means the end sample will be 100,000
FMOD_64BIT_ADD(sysHi, sysLo, 0, 50000);
channel->setDelay(FMOD_DELAYTYPE_DSPCLOCK_END, sysHi, sysLo);

// ... unpause sound ...

To start playback at sample 50,000 and end at 100,000 you could do the following assuming the sound file sample rate and the system sample rate are the same. As DSP clock works in system output samples you may need to do some maths to adjust your end sample in terms of output rate. See Sound::getDefaults for sound sample rate and System::getSoftwareFormat for system rate.

unsigned int sysHi, sysLo;

// ... create sound, play sound paused ...

// Seek the data to the desired start offset
channel->setPosition(50000, FMOD_TIMEUNIT_PCM);

// For accurate sample playback get the current system "tick"
system->getDSPClock(&sysHi, &sysLo);

// Set start offset to a couple of "mixes" in the future, 2048 samples is far enough in the future to avoid issues with mixer timings
FMOD_64BIT_ADD(sysHi, sysLo, 0, 2048);
channel->setDelay(FMOD_DELAYTYPE_DSPCLOCK_START, sysHi, sysLo);

// Set end offset for 50,000 samples from our start time, which means the end sample will be 100,000
FMOD_64BIT_ADD(sysHi, sysLo, 0, 50000);
channel->setDelay(FMOD_DELAYTYPE_DSPCLOCK_END, sysHi, sysLo);

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