NovoCaine-如何循环文件播放?(ios)



我正在使用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]);
 }];

这对我有用:

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

您也可以修改AudioFilereDer.mm,如下:

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

在:

中找到
- (void)bufferNewAudio

这将导致无需重新纳入的循环列表。

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

希望它有帮助!

最新更新