Skip to content

Instantly share code, notes, and snippets.

@tad-iizuka
Created February 26, 2017 06:12
Show Gist options
  • Save tad-iizuka/cde8ec749a4ce3eaff7067484dc1ce06 to your computer and use it in GitHub Desktop.
Save tad-iizuka/cde8ec749a4ce3eaff7067484dc1ce06 to your computer and use it in GitHub Desktop.
AVAudioConverter
audioEngine.inputNode!.installTap(onBus: 0, bufferSize: AVAudioFrameCount(format.sampleRate * 0.4), format: format, block: { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
let converter = AVAudioConverter.init(from: format, to: downFormat)
let newbuffer = AVAudioPCMBuffer(pcmFormat: downFormat,
frameCapacity: AVAudioFrameCount(downFormat.sampleRate * 0.4))
let inputBlock : AVAudioConverterInputBlock = { (inNumPackets, outStatus) -> AVAudioBuffer? in
outStatus.pointee = AVAudioConverterInputStatus.haveData
let audioBuffer : AVAudioBuffer = buffer
return audioBuffer
}
var error : NSError?
converter.convert(to: newbuffer, error: &error, withInputFrom: inputBlock)
_ = ExtAudioFileWrite(self.outref!, newbuffer.frameLength, newbuffer.audioBufferList)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment