Sunday, 15 July 2012

Microphone code doesn't run on iPhone device


i trying run following code on device no success. although code works on simulator. have been following tutorial. crash on device.

http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/

code is:

code:
 @interface micblowviewcontroller : uiviewcontroller {     avaudiorecorder *recorder;     nstimer *leveltimer;     double lowpassresults; }  - (void)leveltimercallback:(nstimer *)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)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;        if (lowpassresults < 0.95)         nslog(@"mic blow detected"); }
 

does stack trace show anything?
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment