@@ -27,8 +27,6 @@ enum MicrophoneDeviceCatalog {
2727}
2828
2929class 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
0 commit comments