Steven 1 tahun lalu
induk
melakukan
1fbcc4f618

+ 1 - 1
KulexiuForStudent/KulexiuForStudent/Common/Base/KSAccompanyWebViewController.m

@@ -492,7 +492,7 @@
                 [self stopMp3Player]; // 停止播放
             }
             else if ([[parm ks_stringValueForKey:@"api"] isEqualToString:@"startRecording"]) { //  开始录制
-                if (self.videoRecordManager) {
+                if (self->_videoRecordManager) {
                     [self.videoRecordManager clearVideoFile];
                 }
                 [self postMessage:parm];

+ 41 - 28
KulexiuForStudent/KulexiuForStudent/Common/Base/KSVideoRecordManager.m

@@ -45,6 +45,7 @@
 
 @property (nonatomic, strong) dispatch_queue_t videoRecordQueue;
 
+@property (nonatomic, assign) BOOL isChangeSession;
 
 @end
 
@@ -167,34 +168,40 @@
 }
 
 - (void)resetSession {
-    if (_ignoreAudio == NO) {
-        [_captureSession beginConfiguration];
-        if (_audioCaptureDeviceInput) {
-            [_captureSession removeInput:_audioCaptureDeviceInput];
-        }
-        
-        NSError *error = nil;
-        // 获取音频输入对象
-        AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
-        _audioCaptureDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioCaptureDevice error:&error];
-        if (error) {
-            if (self.callback) {
-                self.callback(NO, @"获取音频设备输入出错!");
+    if ([_captureSession isRunning]) {
+        if (_ignoreAudio == NO) {
+            [_captureSession beginConfiguration];
+            self.isChangeSession = YES;
+            if (_audioCaptureDeviceInput) {
+                [_captureSession removeInput:_audioCaptureDeviceInput];
             }
-            return;
-        }
-        if ([_captureSession canAddInput:_audioCaptureDeviceInput]) {
-            [_captureSession addInput:_audioCaptureDeviceInput];
-        }
-        else {
-            if (self.callback) {
-                self.callback(NO, @"麦克风被占用!");
+            
+            NSError *error = nil;
+            // 获取音频输入对象
+            AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
+            _audioCaptureDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioCaptureDevice error:&error];
+            if (error) {
+                if (self.callback) {
+                    self.callback(NO, @"获取音频设备输入出错!");
+                }
+                return;
             }
+            if ([_captureSession canAddInput:_audioCaptureDeviceInput]) {
+                [_captureSession addInput:_audioCaptureDeviceInput];
+            }
+            else {
+                if (self.callback) {
+                    self.callback(NO, @"麦克风被占用!");
+                }
+            }
+            
+            [_captureSession commitConfiguration];
+            self.isChangeSession = NO;
         }
-        
-        [_captureSession commitConfiguration];
     }
-    [self startSession];
+    else {
+        [self startSession];
+    }
 }
 
 
@@ -209,7 +216,7 @@
 }
 
 - (void)stopSession {
-    if (_captureSession) {
+    if (_captureSession && _isChangeSession == NO) {
         @weakObj(self);
         dispatch_async(self.videoRecordQueue, ^{
             @strongObj(self);
@@ -223,6 +230,8 @@
 
 - (void)startRecord {
     if (_captureMovieFileOutput) {
+        [self clearVideoFile];
+
         // 开始录制
         [self.captureMovieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:[self getRecordFilePath]] recordingDelegate:self];
     }
@@ -391,10 +400,14 @@
 }
 
 - (void)clearVideoFile {
-    if (self.videoFileURL) {
-        [self removeVideoWithPath:self.videoFileURL.path];
-        self.videoFileURL = nil;
+    if (_isRecording) {
+        return;
+    }
+    NSURL *fileUrl = [NSURL fileURLWithPath:[self getRecordFilePath]];
+    if (fileUrl) {
+        [self removeVideoWithPath:fileUrl.path];
     }
+    self.videoFileURL = nil;
 }
 
 // 上传视频

+ 3 - 3
KulexiuForStudent/KulexiuForStudent/Module/Widget/Controller/ToneTuningViewController.m

@@ -191,9 +191,9 @@ static float correctTime = 0.5;
 
 - (void)tunerDidUpdate:(Tuner *)tuner output:(TunerOutput *)output {
     NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970];
-    if (fabs(self.lastCorrectTime - currentTime) < correctTime) {
-        return;
-    }
+//    if (fabs(self.lastCorrectTime - currentTime) < correctTime) {
+//        return;
+//    }
     self.lastCorrectTime = currentTime;
 
     if (output.amplitude < 0.01) {

+ 3 - 1
KulexiuForStudent/KulexiuForStudent/Module/Widget/Model/TuningFunction/Tuner.swift

@@ -164,7 +164,7 @@ private let frequencies: [Float] = [
          8192 (20次/秒)
          4096 (40次/秒)  def
          */
-        pitchTap = PitchTap(microphone!, bufferSize: 4096, handler: tap_handler)
+        pitchTap = PitchTap(microphone!, bufferSize: 6144, handler: tap_handler)
         microphone!.start()
         pitchTap!.start()
         engine!.output = silence
@@ -182,6 +182,8 @@ private let frequencies: [Float] = [
     }
     
     func tap_handler(freq: [Float], amp: [Float]) -> Void {
+        // Reduces sensitivity to background noise to prevent random / fluctuating data.
+        guard amp[0] > 0.1 else { return }
 #if DEBUG
         print("freq -- real_\(freq[0]) -- imag_\(freq[1])" )
         print("amp -- real_\(amp[0]) -- imag_\(amp[1])")

+ 3 - 3
KulexiuForStudent/KulexiuForStudent/Module/Widget/View/KSGaugeView/KSGaugeView.m

@@ -275,7 +275,7 @@
  */
 - (void)setValue:(float)value animated:(BOOL)animated
 {
-    [self setValue:value animated:animated duration:0.8];
+    [self setValue:value animated:animated duration:0.2];
 }
 
 /**
@@ -283,7 +283,7 @@
  */
 - (void)setValue:(float)value animated:(BOOL)animated completion:(void (^)(BOOL finished))completion
 {
-    [self setValue:value animated:animated duration:0.8 completion:completion];
+    [self setValue:value animated:animated duration:0.2 completion:completion];
 }
 
 /**
@@ -342,7 +342,7 @@
 
 - (void)setValue:(float)value
 {
-    [self setValue:value animated:NO];
+    [self setValue:value animated:YES];
 }
 
 /*

+ 2 - 2
KulexiuForStudent/KulexiuForStudent/Module/Widget/View/WMGaugeView/WMGaugeView.m

@@ -578,7 +578,7 @@
  */
 - (void)setValue:(float)value animated:(BOOL)animated
 {
-    [self setValue:value animated:animated duration:0.8];
+    [self setValue:value animated:animated duration:0.2];
 }
 
 /**
@@ -586,7 +586,7 @@
  */
 - (void)setValue:(float)value animated:(BOOL)animated completion:(void (^)(BOOL finished))completion
 {
-    [self setValue:value animated:animated duration:0.8 completion:completion];
+    [self setValue:value animated:animated duration:0.2 completion:completion];
 }
 
 /**