Sound recording on iPhone: error with setPreferredIOBufferDuration

I am following Apple's documentation for recording audio on iPhone using class AVAudioSession. I can set a few properties with no errors ( setActive, setCategory, setPreferredHardwareSampleRate), but I can not make the Apple sample code to work setPreferredIOBufferDuration.

Here is my code:

- (void) initX {
 NSError *setPreferenceError = nil;
 NSTimeInterval preferredBufferDuration = 0.005;

 [[AVAudioSession sharedInstance]
  setPreferredIOBufferDuration: preferredBufferDuration
  error: &setPreferenceError];

 if (setPreferenceError != nil) {
  NSLog( @"%@", setPreferenceError );
 }
}

He produces the following conclusion:

Domain Error = NSOSStatusErrorDomain Code = 561211770 "Operation could not be completed (OSStatus error 561211770.)"

I call this method from the main delegate of the application, as part of the method applicationDidFinishLaunching. All I do is initialize things at this point. I imported AVFoundation / AVFoundation.h after adding AVFoundation.framework to the project.

+3
1

, Apple; C-:

OSStatus propertySetError = 0;
Float32 preferredBufferDuration = 0.005;
propertySetError = AudioSessionSetProperty(kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof(preferredBufferDuration), &preferredBufferDuration);

if (propertySetError) NSLog(@"Failed to set shorter I/O buffer on AVAudioSession, code %d", propertySetError);
+1

Source: https://habr.com/ru/post/1722563/


All Articles