Skip to content

Commit 132fd36

Browse files
Refactor audio capture handling by removing system audio components and adjusting UI elements for microphone functionality
1 parent 2fb66cb commit 132fd36

5 files changed

Lines changed: 18 additions & 70 deletions

File tree

‎.vscode/mcp.json‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"servers": {
3+
"github": {
4+
"type": "http",
5+
"url": "https://api.githubcopilot.com/mcp/"
6+
}
7+
},
8+
"inputs": [
9+
{
10+
"id": "token",
11+
"type": "promptString",
12+
"description": "",
13+
"password": true
14+
}
15+
]
16+
}

‎TinyClips/Capture/VideoRecorder.swift‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ enum MicrophoneDeviceCatalog {
2727
}
2828

2929
class VideoRecorder: NSObject, @unchecked Sendable {
30-
private let systemAudioSignalThreshold = 0.01
31-
private let systemAudioSignalTimeoutSeconds: TimeInterval = 2
3230
private let microphoneSignalThreshold = 0.01
3331
private let microphoneSignalTimeoutSeconds: TimeInterval = 2
3432
private var stream: SCStream?
@@ -39,25 +37,18 @@ class VideoRecorder: NSObject, @unchecked Sendable {
3937
private var microphoneSession: AVCaptureSession?
4038
private var microphoneOutputDelegate: MicrophoneOutputDelegate?
4139
private var microphoneObservers: [NSObjectProtocol] = []
42-
private var lastSystemAudioSignalAt = CACurrentMediaTime()
4340
private var lastMicSignalAt = CACurrentMediaTime()
4441
private var hasStartedWriting = false
4542
private var recordSystemAudio = false
4643
private var recordMicrophone = false
4744
private var outputURL: URL?
4845
private let writingQueue = DispatchQueue(label: "com.tinyclips.video-writing")
4946
private let microphoneQueue = DispatchQueue(label: "com.tinyclips.microphone-capture")
50-
var onSystemAudioLevel: ((Double) -> Void)?
51-
var onSystemAudioWarning: ((String?) -> Void)?
5247
var onMicrophoneLevel: ((Double) -> Void)?
5348
var onMicrophoneWarning: ((String?) -> Void)?
5449
var onMicrophoneDeviceName: ((String) -> Void)?
5550
var onMicrophoneError: ((String) -> Void)?
5651

57-
var isSystemAudioCaptureActive: Bool {
58-
stream != nil && recordSystemAudio
59-
}
60-
6152
var isMicrophoneCaptureActive: Bool {
6253
microphoneSession != nil && recordMicrophone
6354
}
@@ -76,7 +67,6 @@ class VideoRecorder: NSObject, @unchecked Sendable {
7667
self.recordMicrophone = settings.recordMicrophone
7768

7869
if recordSystemAudio {
79-
lastSystemAudioSignalAt = CACurrentMediaTime()
8070
config.capturesAudio = true
8171
config.sampleRate = 48000
8272
config.channelCount = 2
@@ -207,19 +197,6 @@ class VideoRecorder: NSObject, @unchecked Sendable {
207197
}
208198
}
209199

210-
private func handleSystemAudioSampleBuffer(_ sampleBuffer: CMSampleBuffer) {
211-
let level = rmsLevel(from: sampleBuffer)
212-
onSystemAudioLevel?(level)
213-
214-
let now = CACurrentMediaTime()
215-
if level > systemAudioSignalThreshold {
216-
lastSystemAudioSignalAt = now
217-
onSystemAudioWarning?(nil)
218-
} else if now - lastSystemAudioSignalAt > systemAudioSignalTimeoutSeconds {
219-
onSystemAudioWarning?("No output audio detected.")
220-
}
221-
}
222-
223200
private func rmsLevel(from sampleBuffer: CMSampleBuffer) -> Double {
224201
guard let formatDesc = CMSampleBufferGetFormatDescription(sampleBuffer),
225202
let asbdPointer = CMAudioFormatDescriptionGetStreamBasicDescription(formatDesc) else {
@@ -367,8 +344,6 @@ class VideoRecorder: NSObject, @unchecked Sendable {
367344
hasStartedWriting = false
368345
recordSystemAudio = false
369346
recordMicrophone = false
370-
onSystemAudioWarning?(nil)
371-
onSystemAudioLevel?(0)
372347
onMicrophoneWarning?(nil)
373348
onMicrophoneLevel?(0)
374349
onMicrophoneDeviceName?("")
@@ -423,7 +398,6 @@ extension VideoRecorder: SCStreamOutput {
423398
}
424399

425400
case .audio:
426-
handleSystemAudioSampleBuffer(sampleBuffer)
427401
guard hasStartedWriting, let systemAudioInput, systemAudioInput.isReadyForMoreMediaData else { return }
428402
systemAudioInput.append(sampleBuffer)
429403

‎TinyClips/TinyClipsApp.swift‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ class CaptureManager: ObservableObject {
134134
updateStopHotKeyRegistration()
135135
}
136136
}
137-
@Published var recordingSystemAudioEnabled = false
138-
@Published var systemAudioLevel: Double = 0
139-
@Published var systemAudioWarningMessage: String?
140137
@Published var recordingMicrophoneEnabled = false
141138
@Published var activeMicrophoneName: String?
142139
@Published var microphoneLevel: Double = 0
@@ -373,16 +370,6 @@ class CaptureManager: ObservableObject {
373370

374371
do {
375372
let recorder = VideoRecorder()
376-
recorder.onSystemAudioLevel = { [weak self] level in
377-
DispatchQueue.main.async {
378-
self?.systemAudioLevel = level
379-
}
380-
}
381-
recorder.onSystemAudioWarning = { [weak self] warning in
382-
DispatchQueue.main.async {
383-
self?.systemAudioWarningMessage = warning
384-
}
385-
}
386373
recorder.onMicrophoneLevel = { [weak self] level in
387374
DispatchQueue.main.async {
388375
self?.microphoneLevel = level
@@ -407,16 +394,12 @@ class CaptureManager: ObservableObject {
407394
self.videoRecorder = recorder
408395
self.activeRecordingRegion = region
409396
self.isRecording = true
410-
self.recordingSystemAudioEnabled = false
411-
self.systemAudioWarningMessage = nil
412-
self.systemAudioLevel = 0
413397
self.recordingMicrophoneEnabled = false
414398
self.microphoneWarningMessage = nil
415399
self.microphoneLevel = 0
416400
self.activeMicrophoneName = nil
417401

418402
try await recorder.start(region: region, outputURL: url)
419-
self.recordingSystemAudioEnabled = recorder.isSystemAudioCaptureActive
420403
self.recordingMicrophoneEnabled = recorder.isMicrophoneCaptureActive
421404
self.showStopPanel()
422405
} catch {
@@ -692,9 +675,6 @@ class CaptureManager: ObservableObject {
692675
}
693676

694677
private func resetRecordingAudioStatus() {
695-
recordingSystemAudioEnabled = false
696-
systemAudioLevel = 0
697-
systemAudioWarningMessage = nil
698678
recordingMicrophoneEnabled = false
699679
activeMicrophoneName = nil
700680
microphoneLevel = 0

‎TinyClips/Views/StartRecordingPanel.swift‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class StartRecordingPanel: NSPanel {
77

88
convenience init(onStart: @escaping (Bool, Bool, String) -> Void, onCancel: @escaping () -> Void) {
99
self.init(
10-
contentRect: NSRect(x: 0, y: 0, width: 620, height: 44),
10+
contentRect: NSRect(x: 0, y: 0, width: 520, height: 44),
1111
styleMask: [.borderless, .nonactivatingPanel],
1212
backing: .buffered,
1313
defer: false
@@ -91,18 +91,6 @@ private struct StartRecordingView: View {
9191
.accessibilityValue(systemAudio ? "On" : "Off")
9292
.accessibilityHint("Toggles recording output audio.")
9393

94-
if systemAudio {
95-
Label("Output audio", systemImage: "speaker.wave.2.fill")
96-
.font(.system(size: 12, weight: .medium))
97-
.foregroundStyle(.white)
98-
.padding(.horizontal, 10)
99-
.padding(.vertical, 6)
100-
.background(.white.opacity(0.12))
101-
.clipShape(RoundedRectangle(cornerRadius: 6))
102-
.help("TinyClips records the current system output mix.")
103-
.accessibilityHint("Records the current system output mix.")
104-
}
105-
10694
// Microphone toggle
10795
Button {
10896
microphone.toggle()

‎TinyClips/Views/StopRecordingPanel.swift‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
class StopRecordingPanel: NSPanel {
55
convenience init(captureManager: CaptureManager, onStop: @escaping () -> Void) {
66
self.init(
7-
contentRect: NSRect(x: 0, y: 0, width: 240, height: 44),
7+
contentRect: NSRect(x: 0, y: 0, width: 200, height: 44),
88
styleMask: [.borderless, .nonactivatingPanel],
99
backing: .buffered,
1010
defer: false
@@ -54,16 +54,6 @@ private struct StopRecordingView: View {
5454
.accessibilityLabel("Elapsed recording time")
5555
.accessibilityValue(formattedTime)
5656

57-
if captureManager.recordingSystemAudioEnabled {
58-
RecordingStatusIcon(
59-
systemName: "speaker.wave.2.fill",
60-
tint: captureManager.systemAudioWarningMessage == nil ? .green : .yellow,
61-
accessibilityLabel: "Output audio recording",
62-
accessibilityValue: captureManager.systemAudioWarningMessage ?? "Active"
63-
)
64-
.help(captureManager.systemAudioWarningMessage ?? "Output audio is being recorded.")
65-
}
66-
6757
if captureManager.recordingMicrophoneEnabled {
6858
RecordingStatusIcon(
6959
systemName: "mic.fill",

0 commit comments

Comments
 (0)