我在我的音频项目中使用alexbw 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]);
}];发布于 2012-12-09 13:59:59
这对我很有效:
[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;
}发布于 2013-08-19 19:00:33
您也可以像这样修改AudioFileReader.mm:
if ((self.currentFileTime - self.duration) < 0.01 && framesRead == 0) {
[self setCurrentTime:0.0];
}可在以下位置找到:
- (void)bufferNewAudio这将导致循环文件读取器,而不需要重新初始化它。
缺点是,您必须修改其中一个框架文件...
希望它能帮上忙!
https://stackoverflow.com/questions/13189251
复制相似问题