6
我使用基於Matt Gallagher的classic example的AudioUnits在iPhone上生成鈴聲。爲了避免在開始/結束時發出啁啾和咔嗒聲,我在RenderTone
回調中設置了fading the amplitude in/out。我想在淡出結束時銷燬ToneUnit,也就是在振幅達到零之後。我能想到做到這一點的唯一方法是從回調中調用一個實例方法:如何在音調淡出後正確銷燬ToneUnit?
if (PlayerState == FADING_OUT) {
amplitude -= stepsize;
if (amplitude <= 0) {
amplitude = 0;
PlayerState = OFF;
[viewController destroyToneUnit];
}
}
很不幸,這是更具挑戰性的是我想到。首先,我仍然會在最後的點擊結束,淡出應該消除。另外,我得到這個日誌通知:
<AURemoteIO::IOThread> Someone is deleting an AudioConverter while it is in use.
這條消息是什麼意思,爲什麼我得到它?
如何應該我殺了ToneUnit?我懷疑發生點擊是因爲RenderTone
和destroyToneUnit
在不同的線程上運行。我如何獲得這些同步?
在情況下,它是有幫助,這是我destroyToneUnit
實例方法:
- (void) destroyToneUnit {
AudioOutputUnitStop(toneUnit);
AudioUnitUninitialize(toneUnit);
AudioComponentInstanceDispose(toneUnit);
toneUnit = nil;
}
如果我的NSLog消息權利之前和AudioUnitUninitialize(toneUnit);
之後,兩者之間將出現的通知。
謝謝你的代碼。我有完全相同的問題。你的代碼解決了我的問題。 – 2013-12-11 08:42:41