I'm using a recorder to record sound from the iPhone in caf format. Then, I want it to be in wav format. So I convert it with a code found on the net :
AudioChannelLayout channelLayout;
memset(&channelLayout, 0, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
NSMutableDictionary *outputSettings = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:audioFormat], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
nil];
But the problem is that the file get is like this : (afinfo)
File type ID: WAVE
Num Tracks: 1
----
Data format: 1 ch, 16000 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer
Channel layout: Mono
estimated duration: 2.229125 sec
audio bytes: 71332
audio packets: 35666
bit rate: 256000 bits per second
packet size upper bound: 2
maximum packet size: 2
audio data file offset: 4096
optimized
source bit depth: I16
and I need a file like this :
File type ID: WAVE
Num Tracks: 1
----
Data format: 1 ch, 16000 Hz, 'lpcm' (0x0000000C) 16-bit little-endian signed integer
no channel layout.
estimated duration: 2.229125 sec
audio bytes: 71332
audio packets: 35666
bit rate: 256000 bits per second
packet size upper bound: 2
maximum packet size: 2
audio data file offset: 44
optimized
source bit depth: I16
As you can see, the main difference is that one is "audio data file offset: 44" and the other one "audio data file offset: 4096" And there is the channelLayout too, one Mono (the wrong) and the other one with "no channel layout"
Please help me, I'm really disappointed .. Just for the channel layout, how can I have no channel ?
I used [NSData dataWithBytes:nil length:0] instead of [NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)] which resulted in no channel layout.
NSMutableDictionary *outputSettings = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:audioFormat], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt:1], AVNumberOfChannelsKey,
[NSData dataWithBytes:nil length:0], AVChannelLayoutKey,
nil];
User contributions licensed under CC BY-SA 3.0