2012-08-11 2 views
0

나는 오디오를 녹음하고 거꾸로 재생해야하는 응용 프로그램을 작성 중입니다. AVAudioRecorder를 사용하여 오디오를 caf 파일에 녹음했으며 AVAudioPlayer 및 MPMoviePlayerController를 사용하여 오디오를 전달할 수있었습니다. -1로 MPMoviePlayerController.currentPlaybackRate를 설정해 보았지만 아무런 잡음도 내지 않습니다. 연구에서 나는 오디오 파일을 바이트 단위로 뒤집을 필요가 있음을 발견했지만 어떻게해야할지 모르겠다. 배열에 caf 파일을 읽고 배열에서 쓸 수있는 방법이 있습니까? 어떤 도움을 주시면 감사하겠습니다.iPhone 재생 caf 오디오 뒤로

답변

0

나는 사용자가 말한 것을 기록하고 뒤로 거는 샘플 앱을 작업했습니다. 나는 이것을 달성하기 위해 CoreAudio를 사용했다. Link to app code.

각 샘플은 크기가 16 비트 (2 바이트) (모노 채널)이므로 (녹음에 사용 된 속성에 따라 다름) 녹음의 끝에서 시작하여 뒤로 읽음으로써 각 샘플을 다른 버퍼에 복사하여 한 번에로드 할 수 있습니다. 데이터의 시작 부분에 도달하면 데이터를 반전하고 재생이 취소됩니다.

// set up output file 
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)self.flippedAudioUrl, 
         kAudioFileCAFType, 
         &myPCMFormat, 
         kAudioFileFlags_EraseFile, 
         &outputAudioFile); 
// set up input file 
AudioFileID inputAudioFile; 
OSStatus theErr = noErr; 
UInt64 fileDataSize = 0; 

AudioStreamBasicDescription theFileFormat; 
UInt32 thePropertySize = sizeof(theFileFormat); 

theErr = AudioFileOpenURL((__bridge CFURLRef)self.recordedAudioUrl, kAudioFileReadPermission, 0, &inputAudioFile); 

thePropertySize = sizeof(fileDataSize); 
theErr = AudioFileGetProperty(inputAudioFile, kAudioFilePropertyAudioDataByteCount, &thePropertySize, &fileDataSize); 

UInt32 dataSize = fileDataSize; 
void* theData = malloc(dataSize); 

//Read data into buffer 
UInt32 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); 

희망이 도움이됩니다.

관련 문제