如何使用 openAL 命令从特定时刻播放声音文件(时间输入为双精度或浮点)
我想知道 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要实施寻找。这可能非常棘手,具体取决于您希望查找的准确程度(即到最近的帧或在帧边界之间查找)。
如何实现这一点取决于声音数据的表示方式。我之前已经在 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.