可以在AKAudioPlayer中使用AKAudioFile和replaceWith导致失真吗?

时间:2018-05-23 16:07:39

标签: audiokit

我正在将AudioKit构建成一个实验心理学添加测试中间感(内部身体感觉),现在它非常简单,我只有一个AudioManager.m类声明:

    @implementation AudioManager {
    AKAudioPlayer* player;
    bool canPlay;
}

    +(AudioManager *)sharedManager {
        static dispatch_once_t pred = 0;
        static AudioManager *instance = nil;
        dispatch_once(&pred, ^{
            instance = [[AudioManager alloc] init];
            [instance setup];
        });
        return instance;
    }

小玩家方法如:

-(NSError*)playHTTIntro {
    return [self playWavInResources:@"Htt1"];
}
然后从特定视图控制器调用

    -(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[AudioManager sharedManager] playHTTGuess];
}
我遇到的奇怪问题是随着文件被调用和播放,增加幅度和失真会累积

当我播放10或15个文件时,语音音频文件几乎无法理解

上面的playWavInResources实现为:

    -(NSError*)playWavInResources:(NSString*)wavName {
    if(player)
        [player stop];

    NSError* error;
    AKAudioFile* audioFile = [[AKAudioFile alloc] initForReading:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:wavName ofType:@"wav"]] error:&error];
    if(!error) {
        if(player)
            [player replaceWithFile:audioFile error:&error];
        else
            player = [[AKAudioPlayer alloc] initWithFile:audioFile looping:false lazyBuffering:false error:&error completionHandler:nil];
        AudioKit.output = player;

        // Start audio engine if not already
        NSError* error;
        [AudioKit startAndReturnError:&error];
        if(!error)
            [player start];
    }
    return error;
}

以前有人有这个问题吗?

0 个答案:

没有答案