I want to give an input file, output a reverberation effects of files, but renderOffline: always AVAudioEngineManualRenderingStatusError toBuffer method return status, how can I write to achieve effect, thank you very much
Here's how I wrote it
(BOOL)renderAudioFileWithReverb:(NSString *)inputFilePath outputFilePath:(NSString *)outputFilePath error:(NSError **)errorPtr {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetoothA2DP error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; NSURL *fileURL = [NSURL fileURLWithPath:inputFilePath]; AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading:fileURL error:errorPtr]; if (!audioFile) return NO;
// [self.engine stop];
AVAudioEngine *engine = [[AVAudioEngine alloc] init];
AVAudioPlayerNode *playerNode = [[AVAudioPlayerNode alloc] init];
AVAudioUnitReverb *reverbNode = [[AVAudioUnitReverb alloc] init];
AVAudioFormat *format = audioFile.processingFormat;
[engine attachNode:playerNode];
[engine attachNode:reverbNode];
[reverbNode loadFactoryPreset:AVAudioUnitReverbPresetMediumHall];
reverbNode.wetDryMix = 50;
[engine connect:playerNode to:reverbNode format:format];
[engine connect:reverbNode to:engine.mainMixerNode format:format];
[playerNode scheduleFile:audioFile atTime:nil completionHandler:nil];
AVAudioFrameCount maxFrames = 4096;
NSError *error;
[engine enableManualRenderingMode:AVAudioEngineManualRenderingModeOffline format:format maximumFrameCount:maxFrames error:&error];
[engine startAndReturnError:&error];
[playerNode play];
AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc]initWithPCMFormat:engine.manualRenderingFormat frameCapacity:engine.manualRenderingMaximumFrameCount];
AVAudioFile *outputFile = [[AVAudioFile alloc] initForWriting: [NSURL fileURLWithPath:outputFilePath] settings:audioFile.fileFormat.settings error:&error];
while (engine.manualRenderingSampleTime < audioFile.length) {
AVAudioFrameCount frameCount = audioFile.length - engine.manualRenderingSampleTime;
AVAudioEngineManualRenderingStatus statu = [engine renderOffline:frameCount toBuffer:buffer error:&error];
switch (statu) {
case AVAudioEngineManualRenderingStatusSuccess:
{
BOOL result = [outputFile writeFromBuffer:buffer error:&error];
NSLog(@"1");
}
break;
case AVAudioEngineManualRenderingStatusError:
{
}
break;
default:
break;
}
}
return YES;
}
I tried installTapOnBus and I couldn't output a normal file, so I wanted to pass in a file and output a file with reverberation, and I didn't need to play it,thank you very much。