Conflit between AVAudioRecorder and AVAudioPlayer

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-05T15:11:31Z Indexed on 2010/04/05 15:13 UTC
Read the original article Hit count: 641

Hi, here is my problem :

The code (FooController) :

   NSString *path = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"m4v"]; 
    soundEffect = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]  error:NULL];
[soundEffect play];
    // MicBlow
    micBlow = [[MicBlowController alloc]init];

And MicBlowController contains :

        NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
    NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                              [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                              [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                              [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                              nil];

and

[recorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10,(0.05*[recorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;

NSLog(@"Average input: %f Peak input %f Low pass results: %f",[recorder averagePowerForChannel:0],[recorder peakPowerForChannel:0],lowPassResults);

If I play the background sound and try to get the peak from the mic I get this log : Average input: 0.000000 Peak input -120.000000 Low pass results: 0.000001

But if I comment all parts about AVAudioPlayer it works. I think there is a problem of channel.

Thanks

© Stack Overflow or respective owner

Related posts about avaudiorecorder

Related posts about avaudioplayer