I am struggling to see why the following low-level audio recording function - which is based on tn2091 - Device input using the HAL Output Audio Unit - (a great article, btw, although a bit dated, and it would be wonderful if it was updated to use Swift and non deprecated stuff at some point!) fails to work under macOS:
func createMicUnit() -> AUAudioUnit {
let compDesc = AudioComponentDescription(
componentType: kAudioUnitType_Output,
componentSubType: kAudioUnitSubType_HALOutput, // I am on macOS, os this is good
componentManufacturer: kAudioUnitManufacturer_Apple,
componentFlags: 0, componentFlagsMask: 0)
return try! AUAudioUnit(componentDescription: compDesc, options: [])
}
func startMic() {
// mic permision is already granted at this point, but let's check
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
precondition(status == .authorized) // yes, all good
let unit = createMicUnit()
unit.isInputEnabled = true
unit.isOutputEnabled = false
precondition(!unit.canPerformInput) // can't record yet, and know why?
print(deviceName(unit.deviceID)) // "MacBook Pro Speakers" - this is why
let micDeviceID = defaultInputDeviceID
print(deviceName(micDeviceID)) // "MacBook Pro Microphone" - this is better
try! unit.setDeviceID(micDeviceID) // let's switch device to mic
precondition(unit.canPerformInput) // now we can record
print("\(String(describing: unit.channelMap))") // channel map is "nil" by default
unit.channelMap = [0] // not sure if this helps or not
let sampleRate = deviceActualFrameRate(micDeviceID)
print(sampleRate) // 48000.0
let format = AVAudioFormat(
commonFormat: .pcmFormatFloat32, sampleRate: sampleRate,
channels: 1, interleaved: false)!
try! unit.outputBusses[1].setFormat(format)
unit.inputHandler = { flags, timeStamp, frameCount, bus in
fatalError("never gets here") // now the weird part - this is never called!
}
try! unit.allocateRenderResources()
try! unit.startHardware() // let's go!
print("mic should be working now... why it doesn't?")
// from now on the (UI) app continues its normal run loop
}
All sanity checks pass with flying colors but unit's inputHandler is not being called. Any idea why?
Thank you!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Using CoreBluetooth I am getting these values from CBCentralManagerDelegate's didDiscover peripheral delegate method:
kCBAdvDataTxPowerLevel: 12 (could be other number like 7, 0 or a small negative number)
This one is taken from advertisementData parameter. This key might be absent.
rssi: -68 (or -60, -100, etc)
this is taken from the "rssi" parameter (always present).
I am looking for a formula to calculate approximate distance based on these two numbers. Is that possible?
I know that ideally I need to know rssi0 (rssi at 1 meter), but I don't see how I can get that via CoreBluetooth API or other means (without actually measuring rssi at one meter distance which is not good for me). How could I approximate rssi0 value with "kCBAdvDataTxPowerLevel"?
Hi, is it possible to have the SwiftUI's NavigationView set to show both panels side by side in landscape mode on iPhone Plus/Max sized devices? Similar to how Messages.app does it. Thank you.
When calling CBCentralManager's connectPeripheral:options: with some Bluetooth devices I'm getting the "Bluetooth Pairing Request" alert on iOS and a similar "Connection Request from:" alert on macOS. Is there a way to determine upfront if the alert is going to be presented or not? Alternatively is there a way to prohibit presenting this alert (in which case the connect request could fail, which is totally fine)? I tried specifying these options:
var manager: CBCentralManager
...
manager.connect(
peripheral,
options: [
CBConnectPeripheralOptionNotifyOnConnectionKey: false,
CBConnectPeripheralOptionNotifyOnDisconnectionKey: false,
CBConnectPeripheralOptionNotifyOnNotificationKey: false
]
)
but those didn't help (and by the doc they shouldn't help as they relate to the use case of app running in background, which is not applicable in my case – my app runs and calls connect when it is in foreground, the unwanted alert is displayed immediately).
Posting this on behalf of my colleague, who has a project in mind that requires a huge amount of RAM. Is it true that modern Mac Pro's can only have up to 192GB of RAM which is about 8 times less than 5 years old intel based Mac Pros?