tags:

views:

12

answers:

0

I am working on changing audio file header.

Here, after recording with AVAudioRecorder, I got an audio file on disk. And I want to change audio file header's property to change audio file's samplerate.

Here is the code, but not works.

- (void) changeProperty
{
    CFURLRef inFileRef;
    inFileRef = (CFURLRef)[self getRecordFileURL];
    AudioFileID myAudioFile;
    OSStatus temp1;
    temp1 = AudioFileOpenURL(inFileRef, kAudioFileReadWritePermission, 0, &myAudioFile);

    AudioStreamBasicDescription dstFormat;
    dstFormat.mSampleRate = 12000.0f;
    dstFormat.mChannelsPerFrame = 2;
    dstFormat.mFormatID = kAudioFormatLinearPCM;
    dstFormat.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger; // little-endian
    dstFormat.mBitsPerChannel = 16;
    dstFormat.mBytesPerPacket = 4;
    dstFormat.mFramesPerPacket = 1;

    UInt32 size = sizeof(AudioStreamBasicDescription);

    OSStatus temp2;
    temp2 = AudioFileSetProperty(myAudioFile, kAudioFilePropertyDataFormat, size, &dstFormat);

    OSStatus temp3;
    temp3 = AudioFileClose(myAudioFile);
}

Temp1 and temp3 return '0'. It's fine. But, temp2 returns '1718449215'. So, I guess 'AudioFileSetProperty' is not working. Give me an answer, please. And give me some source code. Thank you for reading.