I'm trying to use AVAudioEngine to record sounds from the microphone together with various sound effect files to a AVAudioFile.I create an AVAudioFile like this:let settings = self.engine.mainMixerNode.outputFormatForBus(0).settingstry self.audioFile = AVAudioFile(forWriting: self.audioURL, settings: settings, commonFormat: .PCMFormatFloat32, interleaved: false)I install a tap on the audio engine's mainMixerNode, where I write the buffer to the file:self.engine.mainMixerNode.installTapOnBus(0, bufferSize: 4096, format: self.engine.mainMixerNode.outputFormatForBus(0)) { (buffer, time) -> Void in do { try self.audioFile?.writeFromBuffer(buffer) } catch let error as NSError { NSLog("Error writing %@", error.localizedDescription) }}I'm using self.engine.mainMixerNode.outputFormatForBus(0).settingswhen creating the audio file since Apple states that "The buffer format MUST match the file's processing format which is why outputFormatForBus: was used when creating the AVAudioFile object above". In the documentation for installTapOnBus they also say this: " The tap and connection formats (if non-nil) on the specified bus should be identical"However, this gives me a very large, uncompressed audio file. I want to save the file as .m4a but don't understand where to specify the settings I want to use:[AVFormatIDKey: NSNumber(unsignedInt: kAudioFormatMPEG4AAC),AVSampleRateKey : NSNumber(double: 32000.0),AVNumberOfChannelsKey: NSNumber(int: 1),AVEncoderBitRatePerChannelKey: NSNumber(int: 16),AVEncoderAudioQualityKey: NSNumber(int: Int32(AVAudioQuality.High.rawValue))]If I pass in these settings instead when creating the audio file, the app crashes when I record.Any suggestions or ideas on how to solve this?
Post
Replies
Boosts
Views
Activity
I'm using AVAudioEngine to record input from the microphone as well as various sound effects to a single file.My AVAudioEngine graph looks like this:soundfileNode ----> mainMixer ---> outputNode (speaker)
|
| (AVAudioConnectionPoint)
v
inputNode (mic) --> secondaryMixer ---> tap (write to file)I'm splitting the output from my mainMixer using AVAudioConnectionPoints to make it output audio to a secondaryMixer and to the speaker. I'm doing this so that only the sound from the sound file nodes are played back through the speaker while recording, as I don't want the mic input to be heard during recording.The error occurs when the output from the mainMixer is written to an audio file using a tap I have installed on the secondaryMixer. The recorded sound "stutters" - there is a very short silence - or gap - about 3 times every second, which probably occurs every time my tap closure is called. It's as if not the entire buffer is written to the output file. The sound from the mic is written to the file exactly as it should, with no gaps, so the problem seems to be the AVAudioConnectionPoint from the mainMixer to the secondaryMixer, which isn't in complete sync or drops parts of the buffer.Has anyone else experienced this problem?
Since upgrading to XCode 10 my iOS simulators have become really slow. There's a lot of lag when scrolling in tableviews or scrollviews. Is anyone else having this problem?