Thanks for helping!
I have to admit that I am a total noob when it comes to audio stuff. Would be super great if you could help me out a bit here 🙂
So I went ahead an made an instance of an AudioConverter
| let bus = 0 |
| |
| let inputFormat = audioEngine.inputNode!.inputFormatForBus(bus) |
| let outputFormat = AVAudioFormat(commonFormat: AVAudioCommonFormat.PCMFormatInt16, sampleRate: 8000.0, channels: 1, interleaved: false) |
| |
| var audioConverterRef = AudioConverterRef() |
| let status = AudioConverterNew(inputFormat.streamDescription, outputFormat.streamDescription, &audioConverterRef) |
That's working so far (status is noErr). Now I have a valid AudioConverter where I'd think that it would convert bytes that I give him in the format of inputFormat into outputFormat.
Now I install a tap on my inputNode and in the callback I do the following:
| |
| (inputBuffer: AVAudioPCMBuffer, time:AVAudioTime) |
| |
| |
| let inputAudioBufferList = inputBuffer.audioBufferList |
| let inputAudioBuffer = inputAudioBufferList[0] |
| let inputData = inputAudioBuffer.mBuffers.mData |
| let inputDataSize = inputAudioBuffer.mBuffers.mDataByteSize |
| |
| |
| |
| |
| |
| var outputBufferSize: UInt32 = 1024 |
| var convertedOutputBuffer = UnsafeMutablePointer<Void>.alloc(Int(outputBufferSize)) |
| let convertedOutputBufferSize = withUnsafeMutablePointer(&outputBufferSize, { $0 }) |
| |
| |
| |
| let status = AudioConverterConvertBuffer(audioConverterRef, inputDataSize, inputData, convertedOutputBufferSize, &convertedOutputBuffer) |
| |
| |
So it seems as if I am not smart enough to figure out the correct input params for AudioConverterConvertBuffer.
Also... when looking at the API... is this the correct way? What's the thing with kAudioUnitSubType_AUConverter? Where would that come into play?
Any help is very very much appreciated!