开发者

iPhone/iPad sound playback with setCurrentTimeFunction. Non AVAudioPlayer

开发者 https://www.devze.com 2023-01-15 22:38 出处:网络
I\'ve recently been trying to incorporate an intensive sound management class, where sound playback precision is a must.

I've recently been trying to incorporate an intensive sound management class, where sound playback precision is a must. What I'm looking for is the option to load a sound, set the playback starting position (or playhead), play for a certain time, pause the sound, set the 'playhead' position to a new interval and resume playback again. (with dynamic intervals). I've tried using AVAudioPlayer for that matter - but it seems it's just too slow. The performance is just not what you expect, it lags when calling pause and setCurrentTime:.

It's the easiest library to use and the only one with stated setCurrentTime: function.

I come here asking for your help, a recommendation for a decent open-source SoundEngine that can handle interval setting (playhead movement) with low latency, or reference to where it is stated that OpenAL or AudioUnit tools can handle playback position sett开发者_运维技巧ing.

Thank you in advance,

~ Natanavra.


It would be worth your time to check out the openAL programmer's guide that comes with the SDK. Its got all sorts of goodies! From that:

Under source: Each source generated by alGenSources has properties which can be set or retrieved. The alSource[f, 3f, fv, i] and alGetSource[f, 3f, fv, i] families of functions can be used to set or retrieve the following source properties: ...

AL_SEC_OFFSET f, fv, i, iv the playback position, expressed in seconds
AL_SAMPLE_OFFSET f, fv, i, iv the playback position, expressed in samples
AL_BYTE_OFFSET f, fv, i, iv the playback position, expressed in bytes

So you can get the playback position in seconds and divide by 60 to get your normalized time.

float pos = 0; alGetSourcef( sourceID, AL_SEC_OFFSET, &pos );
float normalizedPos = pos / 60.0f;

OpenAL definitely has the capabilities to playback sound pause whatever you like. remember OpenAL is often used in games as it delivers sound playback with low latency and on demand playback. You have a lot of control over the sound. compared to the AVAudioPlayer class. Hope this helps Do reply

Pk

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号