Note that there are some explanatory texts on larger screens.

plurals
  1. POiPhone Mic Level : Code works in one project, not in another
    primarykey
    data
    text
    <p>This <a href="http://www.mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/" rel="nofollow">tutorial</a> code works fine for me. I set it up to spit out the value of lowPAssResult. Run it on the phone, sure enough, as expected...</p> <p>2011-07-04 14:28:08.672 MicBlow[280:707] Mic blow detected : 0.036449 ...etc, The value goes up if I blow into it. All good.</p> <p>But when I take it and put it in my own project framework, it doesn't work. I put this code in my init function...</p> <pre><code>//Set up the mic stuff 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:&amp;error]; if (recorder) { [recorder prepareToRecord]; [recorder record]; recorder.meteringEnabled = YES; levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.03 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES]; } </code></pre> <p>And added this callback</p> <pre><code>- (void)levelTimerCallback:(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(@"Mic blow detected - peakPowerForChannel : %f, lowPassResults: %f",peakPowerForChannel,lowPassResults); } </code></pre> <p>And the output looks like this;</p> <p>2011-07-04 14:30:32.974 MinuteGames[290:707] Mic blow detected : 0.000001 repeatedly. Every frame</p> <p>No matter how much blowing I do. Please help, I'm sure this must be somethgn simple!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload