我目前能夠反向錄製和回放(感謝幾個例子),但是我想讓用戶能夠從表格視圖中選擇一個以前記錄的.AAC文件並將其反轉。 我已經嘗試將輸入文件url更改爲用戶文件的url,但是我要麼獲得靜態或0.0持續時間的音頻文件。這種類型的逆轉可能與AAC文件?如果是這樣,我如何糾正我的設置來接受它?如何反轉AAC音頻文件?
recordedAudioUrl = [NSURL URLWithString:[savedURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"url is %@", [recordedAudioUrl absoluteString]);
flippedAudioUrl = [NSURL URLWithString:[reverseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"url is %@", [flippedAudioUrl absoluteString]);
AudioFileID outputAudioFile;
AudioStreamBasicDescription myPCMFormat;
myPCMFormat.mSampleRate = 16000.00;
myPCMFormat.mFormatID = kAudioFormatLinearPCM ;
myPCMFormat.mFormatFlags = kAudioFormatFlagsCanonical;
myPCMFormat.mChannelsPerFrame = 1;
myPCMFormat.mFramesPerPacket = 1;
myPCMFormat.mBitsPerChannel = 16;
myPCMFormat.mBytesPerPacket = 2;
myPCMFormat.mBytesPerFrame = 2;
AudioFileCreateWithURL((__bridge CFURLRef)flippedAudioUrl,
kAudioFileCAFType,
&myPCMFormat,
kAudioFileFlags_EraseFile,
&outputAudioFile);
AudioFileID inputAudioFile;
OSStatus theErr = noErr;
UInt64 fileDataSize = 0;
AudioStreamBasicDescription theFileFormat;
UInt32 thePropertySize = sizeof(theFileFormat);
theErr = AudioFileOpenURL((__bridge CFURLRef)recordedAudioUrl, kAudioFileReadPermission, 0, &inputAudioFile);
thePropertySize = sizeof(fileDataSize);
theErr = AudioFileGetProperty(inputAudioFile, kAudioFilePropertyAudioDataByteCount, &thePropertySize, &fileDataSize);
UInt32 dataSize = fileDataSize;
void* theData = malloc(dataSize);
//Read data into buffer
SInt64 readPoint = dataSize;
UInt32 writePoint = 0;
while(readPoint > 0)
{
UInt32 bytesToRead = 2;
AudioFileReadBytes(inputAudioFile, false, readPoint, &bytesToRead, theData);
AudioFileWriteBytes(outputAudioFile, false, writePoint, &bytesToRead, theData);
writePoint += 2;
readPoint -= 2;
}
free(theData);
AudioFileClose(inputAudioFile);
AudioFileClose(outputAudioFile);
}
不清楚你想要做什麼,你可以添加更多的信息? 「記錄錄音」? – Danijel
用戶記錄以.AAC格式保存的音頻文件。 .AAC文件可以從tableview中訪問,在這裏他們可以選擇一個然後反轉它。 –
你需要將它保存爲reversed.aac嗎?或者只是播放它? – Danijel