I am trying to convert a MIDI file to an audio file (.m4a) in Swift.
Now I use MIKMIDI as a tool for sequencing and playing MIDI files, however it does not include the ability to save the playback to a file. The creator of MIKMID describes the process to do this here . In an attempt to capture and save the output to a sound file, I used this example to try to replace the MIKMIDI Graph RemoteIO node with a GeneralIO node in Swift. When I try to save the output to a file using AudioUnitRender and ExtAudioFileWrite, they return a -50 error (kAudio_ParamError).
var channels = 2
var buffFrames = 512
var bufferList = AudioBufferList.allocate(maximumBuffers: 1)
for i in 0...bufferList.count-1{
var buffer = AudioBuffer()
buffer.mNumberChannels = 2
buffer.mDataByteSize = UInt32(buffFrames*sizeofValue(AudioUnitSampleType))
buffer.mData = calloc(buffFrames, sizeofValue(AudioUnitSampleType))
bufferList[i] = buffer
result = AudioUnitRender(generalIOAudioUnit, &flags, &inTimeStamp, busNum, UInt32(buffFrames), bufferList.unsafeMutablePointer)
inTimeStamp.mSampleTime += 1
result = ExtAudioFileWrite(extAudioFile, UInt32(buffFrames), bufferList.unsafeMutablePointer)
}
-50, MIDI (offline) .m4a?
UPDATE. ExtAudioFileWrite -50, mNumberChannels channels = 1. . AudioUnitRender -50.