1

我正在为我的音频项目使用 alexbw Novocaine的 Novocaine。

我正在使用此处的示例代码进行文件读取。文件播放没有问题。我想用循环之间的间隙循环这段录音 - 关于我如何做到这一点的任何建议?

谢谢。

码头。

// AUDIO FILE READING OHHH YEAHHHH
// ========================================

NSArray *pathComponents = [NSArray arrayWithObjects:
                           [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                           @"testrecording.wav",
                           nil];
NSURL *inputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"URL: %@", inputFileURL);

fileReader = [[AudioFileReader alloc]
              initWithAudioFileURL:inputFileURL
              samplingRate:audioManager.samplingRate
              numChannels:audioManager.numOutputChannels];

[fileReader play];
[fileReader setCurrentTime:0.0]; 
//float duration = fileReader.getDuration;

[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
 {
     [fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];         
     NSLog(@"Time: %f", [fileReader getCurrentTime]);

 }];
4

2 回答 2

1

这对我有用:

[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
 {
     if( ![fileReader playing] ){

//      [fileReader release]; // for some reason this is causing an error, but I assume if you don´t do it, it will eventually cause a memory problem
//      fileReader = nil;

        [self playSound];
     } else {
         [fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];         
         NSLog(@"Time: %f", [fileReader getCurrentTime]);
    }
 }];

- (void) playSound
{
    NSArray *pathComponents = [NSArray arrayWithObjects:
                           [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                           @"testrecording.wav",
                           nil];
    NSURL *inputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
    NSLog(@"URL: %@", inputFileURL);

    fileReader = [[AudioFileReader alloc]
                  initWithAudioFileURL:inputFileURL
                  samplingRate:audioManager.samplingRate
                  numChannels:audioManager.numOutputChannels];

    [fileReader play];
    [fileReader setCurrentTime:0.0]; 
    //float duration = fileReader.getDuration;
}
于 2012-12-09T05:59:59.073 回答
0

您还可以像这样修改 AudioFileReader.mm:

if ((self.currentFileTime - self.duration) < 0.01 && framesRead == 0) {
    [self setCurrentTime:0.0];
}

在发现:

- (void)bufferNewAudio

这将导致循环文件读取器,而无需重新初始化它。

缺点是,您必须修改其中一个框架文件...

希望能帮助到你!

于 2013-08-19T11:00:33.327 回答