简体   繁体   English

在ObjectAL中播放缓冲区

[英]Playing buffer in ObjectAL

I am new to ObjectAL. 我是ObjectAL的新手。 I use it to play mp3 with changed pitch. 我用它来改变音高播放mp3。

I cannot figure out how to "properly" play a loaded buffer in ObjectAL. 我无法弄清楚如何“正确”播放ObjectAL中的已加载缓冲区。 When I call [source play:buffer] the sound only comes a fraction of a second. 当我调用[source play:buffer] ,声音只有不到一秒钟。 To constantly "play" a buffer I can embed it in infinite loop and then the buffer is played correctly. 为了不断“播放”缓冲区,我可以将其嵌入无限循环中,然后正确播放缓冲区。 I assume I miss some fundamental point, can you point me in the right direction? 我想我错过了一些基本要点,您能指出我正确的方向吗?

My code: 我的代码:

[OALSimpleAudio sharedInstance].reservedSources = 0;

ALSource *source = [ALSource source];

ALBuffer *buffer = [[OpenALManager sharedInstance] bufferFromFile:@"video.mp3" reduceToMono:YES];
source.pitch = 1;

for (;;) {   // infinite loop because otherwise only a millisecond of buffer is played
    [source play:buffer];
}

Calling pitchTo or similar function actually makes the buffer play constantly, fx: 实际上,调用pitchTo或类似函数会使缓冲区不断播放fx:

[source pitchTo:1 duration:1 target:nil selector:nil];

This does not qualify as a perfect explanation, however at least it solves the problem. 这不能作为完美的解释,但是至少可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM