How to destroy ToneUnit after Tone Fade Out?

I generate tones on an iPhone using AudioUnits based on Matt Gallagher classic example . To avoid chirping and clicking at the beginning / end, I fade the amplitude to / from in the RenderTone callback. I would like to destroy ToneUnit at the end of the extinction, that is, after the amplitude reaches zero. The only way I can do this is to call the instance method from the callback:

  if (PlayerState == FADING_OUT) { amplitude -= stepsize; if (amplitude <= 0) { amplitude = 0; PlayerState = OFF; [viewController destroyToneUnit]; } } 

Unfortunately, this is harder than I thought. Firstly, I still get a click at the end that should have eliminated. For another, I get this log notification:

 <AURemoteIO::IOThread> Someone is deleting an AudioConverter while it is in use. 

What does this message mean and why do I receive it?

How do I kill ToneUnit? I suspect a click is occurring because destroyToneUnit and destroyToneUnit are working on different threads. How can I sync this data?


In case this is useful, here is my destroyToneUnit instance destroyToneUnit :

 - (void) destroyToneUnit { AudioOutputUnitStop(toneUnit); AudioUnitUninitialize(toneUnit); AudioComponentInstanceDispose(toneUnit); toneUnit = nil; } 

If I sign NSLog messages right before and after AudioUnitUninitialize(toneUnit); , a notification appears between them.

+6
source share
1 answer

I also ran into the same problem. When I called destroyToneUnit from the main thread, the warning disappeared.

 [viewController performSelectorOnMainThread:@selector(destroyToneUnit) withObject:nil waitUntilDone:NO]; 
+6
source

Source: https://habr.com/ru/post/944076/


All Articles