このメソッドはオーディオをフィルタリングし、ピッチを変更しますが、どこにも保存されません
-(void)Pitch:(NSNumber*)pitch
{
audioPlayerNode = [AVAudioPlayerNode new];
[self.audioEngine attachNode:audioPlayerNode];
AVAudioUnitTimePitch *timePitchEffect = [AVAudioUnitTimePitch new];
[self.audioEngine attachNode:timePitchEffect];
timePitchEffect.pitch = [pitch floatValue];
[self.audioEngine connect:audioPlayerNode
to:timePitchEffect
format:nil];
[self.audioEngine connect:timePitchEffect
to:self.audioEngine.outputNode
format:nil];
[audioPlayerNode scheduleFile:self.audioFile
atTime:nil
completionHandler:nil];
[self.audioEngine startAndReturnError:&audioEngineError];
}
ここでオーディオファイルを作成できますが、オーディオで利用できるサウンドはありませんが、この新しいファイルから抜け出すのを手伝ってくれる人はいますが、outputfile という名前で作成されますが、そのオーディオを再生するとサウンドがミュートされ、完全なオーディオが作成されますが、無音
-(void)saveEffectedAudioToFolder
{
AVAudioUnitTimePitch *pitchEffect = [AVAudioUnitTimePitch new];
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
[recordSetting setValue:[NSNumber numberWithFloat:pitch] forKey:AVAudioTimePitchAlgorithmSpectral];
AVAudioFormat *commonFormat = [[AVAudioFormat alloc] initWithSettings:recordSetting];
pitchEffect.pitch =pitch;
[self setupEQ];
NSError *error12;
[_audioEngine startAndReturnError:&error12];
if (!error12)
{
NSLog(@"Engine = %@",_audioEngine);
[audioPlayerNode scheduleFile:_audioFile atTime:nil completionHandler:nil];
NSError *error;
_outputFile = [[AVAudioFile alloc] initForWriting:[self testFilePathURL] settings:commonFormat.settings error:&error];
NSLog(@"outputfile = %@",_outputFile);
if (error)
{
NSLog(@"outputFile error = %@",error);
}
else
{
[SVProgressHUD dismiss];
[audioPlayerNode installTapOnBus:0 bufferSize:8192 format:_audioFile.processingFormat block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {
NSLog(@"Buffer Size = %@",buffer);
NSLog(@"when = %lld",when.sampleTime);
NSLog(@"outputfile length = %lli",_outputFile.length);
NSLog(@"input file length = %lld",_audioFile.length);
if (_outputFile.length<=_audioFile.length)
{
NSError *error;
[_outputFile writeFromBuffer:buffer error:&error];
if (error)
{
NSLog(@"writebuffererror =%@",error);
}
}
else
{
NSError *error2;
[audioPlayerNode removeTapOnBus:0];
// player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[self testFilePathURL] error:&error2];
//player2.delegate = self;
NSLog(@"Pathththt = %@",[self testFilePathURL]);
NSLog(@"error = %@",error2);
[audioPlayerNode scheduleFile:_outputFile atTime:nil completionHandler:nil];
[audioPlayerNode play];
// [self toMp3];
}
}];
}
}
else
{
NSLog(@"error12 =%@",error12);
}
}
- (void)setupEQ
{
NSLog(@"setupEQ");
_unitEq = [[AVAudioUnitEQ alloc] initWithNumberOfBands:12];
_unitEq.globalGain = 3.0;
AVAudioUnitEQFilterParameters *filterParameters;
filterParameters = _unitEq.bands[0];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[1];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[2];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[3];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[4];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[5];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[6];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[7];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain =20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[8];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain = 20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[9];
filterParameters.filterType = AVAudioUnitEQFilterTypeParametric;
filterParameters.frequency = pitch;
filterParameters.bandwidth = 1.0;
filterParameters.gain =20.0f;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[10];
filterParameters.filterType = AVAudioUnitEQFilterTypeLowPass;
filterParameters.frequency = pitch;
filterParameters.bypass = FALSE;
filterParameters = _unitEq.bands[11];
filterParameters.filterType = AVAudioUnitEQFilterTypeHighPass;
filterParameters.frequency = pitch;
filterParameters.bypass = FALSE;
[_audioEngine attachNode:_unitEq];
}