I need to implement an iphone application that will record the user's voice when you start talking, and change the pitch of the recorded sound and play it. I can record sound when a sound is detected using AVAudiorecorder, and using the Dirac library, I changed the pitch of the recorded sound. The problem with this approach is that the output sound is quite noisy. I received a response to using SoundEngine, but I did not have the opportunity to implement it. Can someone explain to me some other way to implement this?
my code
-(void)initialSetup
{
count=0;
silenceTime=0;
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatAppleLossless] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat: @"%.0f.%@",[NSDate timeIntervalSinceReferenceDate]*1000.0, @"caf"]]];
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder updateMeters];
[recorder prepareToRecord];
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"audio.caf"];
recordedTmpFile1 = [NSURL fileURLWithPath:soundFilePath];
recordSetting1 = [[NSMutableDictionary alloc] init];
recordSetting1 = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,nil];
recorder1 = [[AVAudioRecorder alloc] initWithURL:recordedTmpFile1 settings:recordSetting1 error:&error];
[recorder1 prepareToRecord];
[recorder1 setDelegate:self];
if(recorder)
{
recorder.meteringEnabled = YES;
[recorder record];
double val=[recorder peakPowerForChannel:0];
NSLog(@"The Very First Value Of The Recorder Is=%f",val);
levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.4 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
}
else
{
NSLog(@"error in initilising of the recorder=%@",[error localizedDescription]);
}
}
-(void)levelTimerCallback:(NSTimer *)timer
{
[recorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10,(0.05 *[recorder peakPowerForChannel:0]));
double audioMonitorResults1 = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * audioMonitorResults1;
double audioMonitorResults;
audioMonitorResults= [recorder peakPowerForChannel:0];
NSLog(@"This time only frequency is==>%f",audioMonitorResults1);
if(audioMonitorResults1 > .05)
{
[recorder1 updateMeters];
recorder1.meteringEnabled=YES;
[recorder1 record];
NSLog(@"SOUND IS DETECTED");
NSLog(@"%f",[recorder1 peakPowerForChannel:0]);
NSLog(@"Recording is going on");
count=1;
silenceTime=0;
}
else
{
NSLog(@"NO SOUND IS DETECTED");
silenceTime=silenceTime+0.3;
if(count==1 && silenceTime>1)
{
[levelTimer invalidate];
[recorder1 stop];
}
}
}
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
NSLog(@"Recorder stop delegate is processing");
if(flag)
{
NSLog(@"Player has finished successfully");
[self playRecording];
}
else
{
NSLog(@"problem in recording.......not recorded");
}
}
source
share