I'm trying to record audio e.g. from the Macbook's internal microphone. This is my code:
func record() {
let sampleRate = 48000
let numChannels = 1
var inFormat = AudioStreamBasicDescription(mSampleRate: Double(sampleRate),
mFormatID: kAudioFormatLinearPCM,
mFormatFlags: kAudioFormatFlagsNativeFloatPacked,
mBytesPerPacket: UInt32(numChannels * MemoryLayout<UInt32>.size),
mFramesPerPacket: 1,
mBytesPerFrame: UInt32(numChannels * MemoryLayout<UInt32>.size),
mChannelsPerFrame: UInt32(numChannels),
mBitsPerChannel: UInt32(8 * MemoryLayout<UInt32>.size),
mReserved: UInt32(0))
var inAQ: AudioQueueRef? = nil;
var status = AudioQueueNewInput(&inFormat, callback, nil, nil, nil, 0, &inAQ)
print("AudioQueueNewInput returned " + status.description)
status = AudioQueueStart(inAQ!, nil)
print("AudioQueueStart returned " + status.description)
}
I took most of it from this answer. However, I'm getting a different error. The output is:
AudioQueueNewInput returned 0
2021-01-02 13:41:49.341243+0100 ocean[39484:6411401] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600002c79880> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2021-01-02 13:41:49.408830+0100 ocean[39484:6411401] HALC_ShellDriverPlugIn::Open: opening the plug-in failed, Error: 2003329396 (what)
2021-01-02 13:41:49.472141+0100 ocean[39484:6411401] [AQ] AudioQueueObject.cpp:1179:BuildConverter: AudioConverterNew returned -50
AudioQueueStart returned -50
OSStatus -50 indicates a bad parameter. Which of my parameters is bad?
EDIT: I had a different audio input set in the system preferences. I switched to the internal microphone and am now getting a different error:
AudioQueueNewInput returned 0
2021-01-02 14:55:03.415688+0100 ocean[40044:6458085] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000035de820> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2021-01-02 14:55:03.482119+0100 ocean[40044:6458085] HALC_ShellDriverPlugIn::Open: opening the plug-in failed, Error: 2003329396 (what)
2021-01-02 14:55:03.483443+0100 ocean[40044:6458085] [aqme] AQMEIO.cpp:352:AQMEIOManager_FindIOUnit: error -66680 finding/initializing Device.AQDefaultInput
AudioQueueStart returned -66680
-66680 means invalid device. Any hints on why that is? I updated the title, but I'd still like to know why the other audio input rejects these parameters.
Solved this by enabling "Audio Input" in Signing & Capabilities of my Target. It actually solved it for all audio input devices.