views:

749

answers:

2

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

+1  A: 

Well, I've found the solution and it is AVAudioSession !

By using the method setCategory (with AVAudioSessionCategoryPlayAndRecord as argument) I can play sounds and record sounds from the mic.

audioSession = [[AVAudioSession sharedInstance] retain];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive:YES error: nil];
John
Don't suppress error returns. Any method that has one can fail in some way; when that happens, you will want to know how it failed, so that you can prevent it from failing or recover from the failure gracefully.
Peter Hosey
A: 

I am getting

Peak Power : -160.000000 , -160.000000 Average Power : -160.000000 , -160.000000

but my voice is not recording...wen i do playback no voice is coming..can anyone help.. what can be the reason?

Sam