Recording from RemoteIO: resulting .caf is pitch shifted slower + distorted

后端 未结 1 1385
南旧
南旧 2020-12-10 19:19

So I\'ve cobbled together some routines for recording audio based on some posts here. The posts I\'ve referenced are here and here, along with reading the sites they referen

1条回答
  •  抹茶落季
    2020-12-10 20:04

    Ok - found some code that solves this - though I don't fully understand why.

    I had been setting the mBitsPerChannel to 16 for both the RemoteIO output stream and the ExtFileRef. The result was slowed down & scratchy audio. Setting the ExtFileRef mBitsPerChannel to 32 plus adding the kAudioFormatFlagsNativeEndian flag solves the problem: the .caf audio is perfect (while leaving the RemoteIO output stream settings to what they were).

    But then also setting the RemoteIO output stream settings to match my new settings also works. So I'm confused. Shouldn't this work so long as the AudioStreamBasicDescription settings are symmetrical for the RemoteIO instance and the ExtFileRef?

    Anyway... the working setting is below.

    size_t bytesPerSample = sizeof (AudioUnitSampleType);
    
    AudioStreamBasicDescription audioFormat;
    audioFormat.mSampleRate= graphSampleRate;
    audioFormat.mFormatID=kAudioFormatLinearPCM;
    audioFormat.mFormatFlags=kAudioFormatFlagsNativeEndian|kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
    audioFormat.mBytesPerPacket=bytesPerSample;
    audioFormat.mBytesPerFrame=bytesPerSample;
    audioFormat.mFramesPerPacket=1;
    audioFormat.mChannelsPerFrame=1;
    audioFormat.mBitsPerChannel= 8 * bytesPerSample;
    audioFormat.mReserved=0;
    

    0 讨论(0)
提交回复
热议问题