如何使用 openAL 命令从特定时刻播放声音文件(时间输入为双精度或浮点)

发布于 2024-10-25 00:11:10 字数 705 浏览 1 评论 0原文

我想知道 openAL 中是否有一个命令可用于从特定时刻(寻道时间)播放声音文件。就像我使用滑块并滑动它一样,一旦我释放滑块,声音文件应该从该特定时刻开始播放。

我已经为 iOS 实现了它。但我还没有找到这个可以从特定时间点播放文件的 openAL 方法。

alSourcei(sourceID, AL_BUFFER, 0);
alSourcei(sourceID, AL_BUFFER, bufferID);



// Set the pitch and gain of the source
alSourcef(sourceID, AL_PITCH, aPitch);
alSourcef(sourceID, AL_GAIN, aGain * fxVolume);

if(aLoop) {
    alSourcei(sourceID, AL_LOOPING, AL_TRUE);
} else {
    alSourcei(sourceID, AL_LOOPING, AL_FALSE);
}
// Set the source location
alSource3f(sourceID, AL_POSITION, aLocation.x, aLocation.y, 0.0f);
**Here we play the sound ***

alSourcePlay(sourceID);

执行上面的代码总是从初始位置播放音轨。 我想知道 openAL 中是否有任何方法可以从某个特定时刻寻找轨迹。

I want to know if there is a command in openAL that can be used to play a sound file from particular time instant ( seek time). Like if I am using a slider and slide it , once I release the slider, the sound file should play from that particular instant.

I have implemented it for iOS. But I have not found this openAL method that can play file from particular time instant.

alSourcei(sourceID, AL_BUFFER, 0);
alSourcei(sourceID, AL_BUFFER, bufferID);



// Set the pitch and gain of the source
alSourcef(sourceID, AL_PITCH, aPitch);
alSourcef(sourceID, AL_GAIN, aGain * fxVolume);

if(aLoop) {
    alSourcei(sourceID, AL_LOOPING, AL_TRUE);
} else {
    alSourcei(sourceID, AL_LOOPING, AL_FALSE);
}
// Set the source location
alSource3f(sourceID, AL_POSITION, aLocation.x, aLocation.y, 0.0f);
**Here we play the sound ***

alSourcePlay(sourceID);

Executing above code always play the sound track from initial position.
I want to know if there i any mehthod in openAL that can seek the track from some particular time instant.

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

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

发布评论

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

评论(1

谁的新欢旧爱 2024-11-01 00:11:10

你需要实施寻找。这可能非常棘手,具体取决于您希望查找的准确程度(即到最近的帧或在帧边界之间查找)。

如何实现这一点取决于声音数据的表示方式。我之前已经在 openal 上实现了 ogg vorbis 数据流传输。为此,我使用实现的 ov_seek 作为 ov_open_callbacks 的一部分。

devmaster 上有一个关于 OpenAL 流的教程,我发现它很有用。

You need to implement seeking. It can be quite tricky to do depending on how accurate you want the seeking to be (ie to nearest frame or seeking between frame boundaries).

How you implement this depends upon how your sound data is represented. I've previously implemented this for streaming with ogg vorbis data on openal. For that, I used implemented ov_seek as part of ov_open_callbacks.

There's a tutorial for OpenAL streaming on devmaster which I found useful.

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