Hello all I'm revamping an old macOS app based on swift CoreAudio which now is crashing or after some minutes corrupts the audio stream. It is taking an USB raw audio as input and playback to the choosen output. I then decided to try using AVAudioEngine and AVAudioPlayerNode. Newbie for this so I started from the real begin: I'using sample code found here on SO (thanx all...). I suppose I could use one of the simplest snippet found here, ie play an mp3 audio file. But after days of researching I'm still (for sure my fault) not able to playback that small mp3. Running Sonoma latest on a MacPro Intel. Tried to also connect the default out dev with no luck: same messages, no sound. Here the code used:
import Foundation
import AVFoundation
class ViewController: NSViewController {
public var engine: AVAudioEngine!
public var player : AVAudioPlayerNode!
override func viewDidLoad() {
super.viewDidLoad()
engine = AVAudioEngine()
player = AVAudioPlayerNode()
engine.reset()
guard let path = Bundle.main.path(forResource: "song", ofType: "mp3") else {
print("Error getting URL")
return
}
print("\(path)")
let url: URL = URL(fileURLWithPath: path)
guard let file = try? AVAudioFile(forReading: url) else {
print("Error reading Audio File")
return
}
let format = file.processingFormat
let framecount = AVAudioFrameCount(file.length)
guard let buffer = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: framecount) else{
return
}
do{
try file.read(into: buffer)
} catch{
print("Error reading file to buffer")
return
}
let mainMixer = engine.mainMixerNode
engine.attach(player)
engine.connect(player, to:mainMixer, format: buffer.format)
engine.prepare()
try? engine.start()
player.play()
}
}
This compile OK but on running inside Xcode gives some messages: on line:
let mainMixer = engine.mainMixerNode
in the debug view windows it throws out:
AddInstanceForFactory: No factory registered for id <CFUUID 0x600002927660> F8BB1C28-BAE8-11D6-9C31-00039315CD46
HALC_ShellDriverPlugIn.cpp:107 HALC_ShellDriverPlugIn::Open: opening the plug-in failed, Error: 2003329396 (what)
HALC_ShellDriverPlugIn.cpp:107 HALC_ShellDriverPlugIn::Open: opening the plug-in failed, Error: 2003329396 (what)
and on line:
player.play()
the error(?) message is
88579 HALC_ProxyIOContext.cpp:1328 HALC_ProxyIOContext::IOWorkLoop: skipping cycle due to overload
In sandbox Xcode 15.2 only audio in is checked. For sure I'm doing something wrong. But also I cannot find the meaning of those messages. Any clue? What I'm missing? Thanks
Would like to understand what is missing and the meaning of the debug messages.