1

これが私の問題です:

コード(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];

そして、MicBlowControllerには以下が含まれています:

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

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

バックグラウンドサウンドを再生してマイクからピークを取得しようとすると、次のログが表示されます。平均入力:0.000000ピーク入力-120.000000ローパス結果:0.000001

しかし、AVAudioPlayerに関するすべての部分にコメントすると、機能します。チャンネルの問題があると思います。

ありがとう

4

1 に答える 1

6

さて、私は解決策を見つけました、そしてそれはAVAudioSessionです!

setCategoryメソッド(引数としてAVAudioSessionCategoryPlayAndRecordを使用)を使用することで、マイクからサウンドを再生したり録音したりできます。

audioSession = [[AVAudioSession sharedInstance] retain];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: nil];
[audioSession setActive:YES error: nil];
于 2010-04-05T20:32:56.520 に答える