Detecting Blow through iPhone MIC in Cocos and then Performing animation on an image

后端 未结 2 1658
小鲜肉
小鲜肉 2021-01-24 21:28

I am working on an app which is related to the recipes.In this app there is a section where user can blow air through the mic and can change the image as well the content on it

2条回答
  •  清酒与你
    2021-01-24 21:52

    Use return as you get first lowpass results >0.55

    I have solve the issue have a look.

    -(void)readyToBlow1 {
    
      NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
    
      NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                              [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                              [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                              [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                              nil];
    
    NSError *error;
    
    recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
    
    if (recorder) {
        [recorder prepareToRecord];
        recorder.meteringEnabled = YES;
        [recorder record];
        levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.01 target: self selector: @selector(levelTimerCallback1:) userInfo: nil repeats: YES];
     } 
      else
         NSLog(@"%@",[error description]);
    
    }
    
     - (void)levelTimerCallback1:(NSTimer *)timer {
    
        [recorder updateMeters];
    
    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
    //NSLog(@"lowPassResults= %f",lowPassResults);
    
    if (lowPassResults > 0.55)
    {
    
        lowPassResults = 0.0;
    
        [self invalidateTimers];
    
    
        NextPhase *objNextView =[[NextPhase alloc]init];
    
        [UIView transitionFromView:self.view
                            toView:objNextView.view
                          duration:2.0
                           options:UIViewAnimationOptionTransitionCurlUp
                        completion:^(BOOL finished) {
                        }
         ];
    
        [self.navigationController pushViewController:objNextView animated:NO];
    
        **return;**
    
    
      }
    
    }
    

提交回复
热议问题