Add live-input mic permission, audio-input entitlement, and engine-config review fixes
Live input was silent on macOS because the apps ran under hardened runtime without the microphone entitlement, so AUHAL input received silent zeros and the OS never prompted. Fixes: - Add com.apple.security.device.audio-input entitlement to the macOS Builder and Demo apps (CODE_SIGN_ENTITLEMENTS wired in both targets). - Add MicrophonePermission helper (AVCaptureDevice.requestAccess) and gate live-input selection through it in the Builder view and Demo controller; deny falls back to the test loop with an explanatory alert. - Fix ShoeGazeDemo inputChannels 6 -> 1 (built-in mics are mono; 6 made CoreAudio deliver silence). Engine-config review fixes: - installScopeTap now requires the engine stopped (precondition) and reconfigureEngine reinstalls the tap on every exit path via defer, so engine.scopeTap never points at a stale channel layout. - EngineConfigView stops the engine on a post-start (iOS) sample-rate mismatch instead of running pitch-shifted, and surfaces non-mismatch start errors through the alert. - Remove redundant installScopeTap call in the demo controller (ShoeGaze.init already installs it). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,7 @@ public struct EngineConfigView: View {
|
||||
@State private var pendingOutputs: Int
|
||||
@State private var transportTick: Bool = false
|
||||
@State private var showAlert: Bool = false
|
||||
@State private var alertTitle: String = ""
|
||||
@State private var alertText: String = ""
|
||||
|
||||
// MARK: - Init
|
||||
@@ -107,7 +108,7 @@ public struct EngineConfigView: View {
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(isRunning ? .red : .green)
|
||||
}
|
||||
.alert("Sample Rate Mismatch", isPresented: $showAlert) {
|
||||
.alert(alertTitle, isPresented: $showAlert) {
|
||||
Button("OK", role: .cancel) { }
|
||||
} message: {
|
||||
Text(alertText)
|
||||
@@ -140,9 +141,12 @@ public struct EngineConfigView: View {
|
||||
onConfigApplied() // config may have applied even if start failed (e.g. rate mismatch)
|
||||
return
|
||||
}
|
||||
// Started OK. On iOS the session may have committed a different rate than requested.
|
||||
// Started OK. On iOS the session may have committed a different rate than requested — and
|
||||
// `setSampleRate` only stores the logical rate, so leaving the engine running would play
|
||||
// pitch-/time-shifted audio. Stop it (mirroring the macOS thrown-mismatch path) and alert.
|
||||
if let hardware: Double = hardwareSampleRate(),
|
||||
abs(hardware - shoeGaze.engine.sampleRate) > EngineConfigView.rateEpsilon {
|
||||
shoeGaze.engine.stop()
|
||||
presentMismatch(requested: shoeGaze.engine.sampleRate, hardware: hardware)
|
||||
}
|
||||
transportTick.toggle()
|
||||
@@ -163,10 +167,16 @@ public struct EngineConfigView: View {
|
||||
return
|
||||
}
|
||||
#endif
|
||||
print("[EngineConfigView] engine start failed: \(error)")
|
||||
// Any other failure (invalid value, board reconstruction, driver setup) still needs to be
|
||||
// surfaced — otherwise Start appears to do nothing.
|
||||
alertTitle = "Couldn’t Start Engine"
|
||||
alertText = "The engine could not start with the chosen configuration: "
|
||||
+ "\(error.localizedDescription)"
|
||||
showAlert = true
|
||||
}
|
||||
|
||||
private func presentMismatch(requested: Double, hardware: Double) {
|
||||
alertTitle = "Sample Rate Mismatch"
|
||||
alertText = "Requested \(Int(requested)) Hz, but the hardware is running at "
|
||||
+ "\(Int(hardware)) Hz. Set the sample rate to \(Int(hardware)) Hz and start again."
|
||||
showAlert = true
|
||||
|
||||
Reference in New Issue
Block a user