I'm building a app where one of the functions is to record a voice message I want sample format 16-bit PCM but i cant seem to get it right.
I have tried lots of diffrent settings but everytime i check the file in audacity it says 32-bit float.
This is my current recorderSettings
var recorderSettings = [NSObject: AnyObject]()
recorderSettings[AVFormatIDKey] = kAudioFormatALaw
recorderSettings[AVSampleRateKey] = 16000
recorderSettings[AVNumberOfChannelsKey] = 1
recorderSettings[AVLinearPCMBitDepthKey] = 16
recorderSettings[AVLinearPCMIsFloatKey] = false
So i found the problem i needed kAudioFormatLinearPCM instead of kAudioFormatALaw
I tried that before but then i only checked the format with audacity and it reported back 32-bit float. but after reading Dom Bryan answer I checked it again with the file command and it reported back the correct format.
so correct config would be
var recorderSettings = [NSObject: AnyObject]()
recorderSettings[AVFormatIDKey] = kAudioFormatLinearPCM
recorderSettings[AVSampleRateKey] = 16000
recorderSettings[AVNumberOfChannelsKey] = 1
recorderSettings[AVLinearPCMBitDepthKey] = 16
recorderSettings[AVLinearPCMIsFloatKey] = false
Try looking into audacity settings. It preferences 32bit for flexibility and then suggests exporting in 16bit. Your code doesn't look wrong so try messing with audacity or different program.
Here is a link to audacity's preferences: http://audacity.sourceforge.net/onlinehelp-1.2/prefs.htm