Pergunta

Aqui está o meu problema:

O código (fooocontroller):

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

E MicBlowController contém:

        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];

e

[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);

Se eu jogar o som de fundo e tentar obter o pico do microfone, recebo este log: entrada média: 0,000000 entrada de pico -120.000000 Resultados de passagem baixa: 0,000001

Mas se eu comentar todas as partes sobre a Avaudioplayer, ele funciona. Eu acho que há um problema de canal.

Obrigado

Foi útil?

Solução

Bem, eu encontrei a solução e é avaudiossession!

Usando o método setCategory (com avaudiosessionCategoryplayandRecord como argumento), posso reproduzir sons e gravar sons do microfone.

audioSession = [[AVAudioSession sharedInstance] retain];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive:YES error: nil];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top