Mac app Audio Recording with Visualizations best approach

Hey I wonder if someone can point me in the right direction.

I am building a Mac Audio App that I need to perform the following actions

  • Select audio input device
  • Show a live audio graph of device input (think GarageBand/ Logic)
  • Capture the audio for replay
  • Output the sound or make itself selectable as an input device for another app - Similar to how plugins work for GarageBand Logic etc

I have looked into using the following so far:

  • AudioKit
  • AVFoundation / AVCaptureDevice

AudioKit

This framework looks amazing and has sample apps for most of the things I want to do, however it seems that it will only accept the audio input that the Mac has selected in settings. This is a non starter for me as I want the user to be able to chose in App (like GarageBand does or Neural Dsp plugins) Using AudioEngine I can get the available input devices, but everything I have found points to them not being changeable in App - here's code to display them

struct InputDevicePicker: View {
    @State var device: Device
    var engine: AudioEngine

    var body: some View {
        Picker("Input: \(device.deviceID)", selection: $device) {
            ForEach(getDevices(), id: \.self) {
                Text($0.name)
            }
        }
        .pickerStyle(MenuPickerStyle())
        .onChange(of: device, perform: setInputDevice)
    }

    func getDevices() -> [Device] {
        AudioEngine.inputDevices.compactMap { $0 }
    }

    func setInputDevice(to device: Device) {
      // set the input device on the AudioEngine
    }
  }
}

Alternatively AVFoundation

This has a nice API for listing devices and setting the input, but when it comes to working with the data the delegate provides, I don't have the first clue how I would handle this in terms creating an audio graph and saving the data for replay. Here's the delegate method for reference

extension Recorder: AVCaptureAudioDataOutputSampleBufferDelegate {

    func captureOutput(_ output: AVCaptureOutput,
                       didOutput sampleBuffer: CMSampleBuffer,
                       from connection: AVCaptureConnection) {

        print("Audio data recieved")
        // Needs to save audio here
        // Needs to play through speakers or other audio source
        // Need to show audio graph
    }
}

It would be great if someone with experience using these could advise if this is possible on either and where I can look for examples / guidance Any help pointers, life savers would be appreciated Thanks if you got this far !

Mac app Audio Recording with Visualizations best approach
 
 
Q