Created
February 26, 2017 06:12
-
-
Save tad-iizuka/cde8ec749a4ce3eaff7067484dc1ce06 to your computer and use it in GitHub Desktop.
AVAudioConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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