3

I am attempting to record audio from the input node and sending it to a mixer to convert the audio to a lowered sample rate to be written to disk.

My audio file is created like this:

let sett = [ 
    AVSampleRateKey : NSNumber(double: 22050), 
    AVNumberOfChannelsKey : NSNumber(int: 2) ]
let file = try! AVAudioFile(forWriting: url, settings: sett)

Then for the audio engine, I at first connected the input node to my mixer node with the connection format the same as the file.processingFormat. Which crashes with the exception

required condition is false: format.sampleRate == hwFormat.sampleRate

After that I connected the input node to a mixer node with the connection format as the inputNode.outputFormatForBus(0) and then connected that mixer node to a second mixer node with the connection format of file.processingFormat. This does not crash, but when I install a tap on the second mixer, the callback is never called. I'm not sure if it's taking a long time to process on the backend or if there is something wrong.

hola
  • 3,150
  • 13
  • 21
  • Did you ever find a solution to this? I was attempting to do the same thing and found the only way to record from a mixer node with a different sample rate was if the mixer node was connected to the outputNode of the audio engine (and so playing back what's being recorded). – Tom Durrant Nov 03 '17 at 17:48
  • @TomDurrant This is a very late response, but I thought I should at least reach out allow some closure: I never did find a solution. I ended up using a different audio framework. -- Have a good one! – hola Oct 28 '19 at 01:44

0 Answers0