OpenALを使ってたくさんの音を鳴らすiPhoneアプリを作りました。これらのサウンドはmp3であり、非常に重く(1分以上)、メモリの使用量を減らすためにストリーミングします(サウンドごとに2つのバッファー)。中断を管理するために、私はこのコードを使用します:
OpenALSupport.cファイル内:
//used to disable openAL during a call
void openALInterruptionListener ( void *inClientData, UInt32 inInterruptionState)
{
if (inInterruptionState == kAudioSessionBeginInterruption)
{
alcMakeContextCurrent (NULL);
}
}
//used to restore openAL after a call
void restoreOpenAL(void* a_context)
{
alcMakeContextCurrent(a_context);
}
私のSoundManager.mファイル:
- (void) restoreOpenAL
{
restoreOpenAL(mContext);
}
//OPENAL initialization
- (bool) initOpenAL
{
// Initialization
mDevice = alcOpenDevice(NULL);
if (mDevice) {
...
// use the device to make a context
mContext=alcCreateContext(mDevice,NULL);
// set my context to the currently active one
alcMakeContextCurrent(mContext);
AudioSessionInitialize (NULL, NULL, openALInterruptionListener, mContext);
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: &setCategoryError];
...
}
そして最後に私のAppDelegateで:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[CSoundManager getInstance] restoreOpenAL];
...
}
この方法では、呼び出し後にサウンドが返されますが、フローはランダムに再生されているように見えます。ストリーミングサウンドの中断を管理する特定の方法はありますか?それについての記事は見つかりません。
ご協力いただきありがとうございます。