Results 1 to 3 of 3

Your favorite Apple, iPhone, iPad, iOS, Jailbreak, and Cydia site.


Thread: Microphone code doesn't run on iPhone device

  1. #1
    Default Microphone code doesn't run on iPhone device
    I am trying to run the following code on my device with no success. Although the code works perfectly on Simulator. I have been following this tutorial. It simply crash on device.

    Tutorial: Detecting When A User Blows Into The Mic | Mobile Orchard

    Code is:

    @interface MicBlowViewController : UIViewController
    {
    AVAudioRecorder *recorder;
    NSTimer *levelTimer;
    double lowPassResults;
    }

    - (void)levelTimerCallbackNSTimer *)timer;

    @end



    - (void)viewDidLoad
    {
    [super viewDidLoad];

    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: 3
    target: self
    selector: @selector(levelTimerCallback
    userInfo: nil
    repeats: YES];
    }
    else
    NSLog(@"%@", [error description]);
    }


    - (void)levelTimerCallbackNSTimer *)timer
    {
    [recorder updateMeters];

    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;

    if (lowPassResults < 0.95)
    NSLog(@"Mic blow detected");
    }

  2. #2
    Quote Originally Posted by saqibjaan View Post
    I am trying to run the following code on my device with no success. Although the code works perfectly on Simulator. I have been following this tutorial. It simply crash on device.

    Tutorial: Detecting When A User Blows Into The Mic | Mobile Orchard

    Code is:

    @interface MicBlowViewController : UIViewController
    {
    AVAudioRecorder *recorder;
    NSTimer *levelTimer;
    double lowPassResults;
    }

    - (void)levelTimerCallbackNSTimer *)timer;

    @end



    - (void)viewDidLoad
    {
    [super viewDidLoad];

    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: 3
    target: self
    selector: @selector(levelTimerCallback
    userInfo: nil
    repeats: YES];
    }
    else
    NSLog(@"%@", [error description]);
    }


    - (void)levelTimerCallbackNSTimer *)timer
    {
    [recorder updateMeters];

    const double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
    lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;

    if (lowPassResults < 0.95)
    NSLog(@"Mic blow detected");
    }
    I see you declared your interface but after the @end where are those methods declared from, what interface are they a part of?

  3. #3
    I have not shared the whole code. That's why you are not seeing some of the methods.

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •