objective c - Trouble hooking up AVAudioUnitEffect with AVAudioEngine -
i've been poking around avaudioengine , i'm having trouble integrating avaudiouniteffect classes. example, avaudiounitdelay...
@implementation viewcontroller { avaudioengine *engine; avaudioplayernode *player; }
...
- (ibaction)playbuttonhit:(id)sender { if (!player){ nsurl *bandsurl = [[nsbundle mainbundle] urlforresource:@"bands managers" withextension:@"mp3"]; avaudiofile *file = [[avaudiofile alloc] initforreading:bandsurl error:nil]; engine = [[avaudioengine alloc] init]; player = [[avaudioplayernode alloc] init]; [engine attachnode:player]; avaudiounitdelay *delay = [[avaudiounitdelay alloc] init]; delay.wetdrymix = 50; [engine connect:player to:delay format:file.processingformat]; [engine connect:delay to:[engine outputnode] format:file.processingformat]; [player schedulefile:file attime:nil completionhandler:nil]; [engine prepare]; [engine startandreturnerror:nil]; } [player play];
}
when method called app crashes , error: "* terminating app due uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition false: [_nodes containsobject: node1] && [_nodes containsobject: node2]'"
i'm modeling after of examples "avaudioengine in practice" session wwdc. know there's obvious i'm missing can't figure out....
it not problem of avaudiouniteffect
! tried code
nserror *err = nil; self.engine = [[avaudioengine alloc] init]; avaudioplayernode *player = [[avaudioplayernode alloc] init]; [self.engine attachnode:player]; nsurl *fileurl = [[nsbundle mainbundle] urlforresource:@"sound" withextension:@"m4a"]; avaudiofile *file = [[avaudiofile alloc] initforreading:fileurl error:&err]; avaudiomixernode *mainmixer = [self.engine mainmixernode]; [self.engine connect:player to:mainmixer format:file.processingformat]; [player schedulefile:file attime:nil completionhandler:nil]; [self.engine startandreturnerror:&err]; if (err != nil) { nslog(@"an error occured"); } [player play];
while self.engine
defined by
@property (nonatomic, strong) avaudioengine *engine;
i think bug in avaudioengine
, because causes memory leak: starts playing first samples , crashes because of heavy memory usage (more 300 mb in case of 16 kb m4a file).
update 12/07/2014: apple fixed issue ios 8 seed 3 (build 12a4318c)!
Comments
Post a Comment