kAudioFormat for .aif audio file conversion?

不问归期 提交于 2019-12-10 12:23:55

问题


I would like to convert/save audio file to AIFF audio format from AAC format. Default i'm trying with LineraPCM . . But the audio format saving in AAC format. . I would like to save the audio file in AIFF format.Here's my code

NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey, 
                                  [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                  [NSNumber numberWithInt:2], AVNumberOfChannelsKey,
                                  [NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
                                  [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
                                  [NSNumber numberWithBool:NO], AVLinearPCMIsNonInterleaved,
                                  [NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
                                  [NSNumber numberWithBool:NO], AVLinearPCMIsBigEndianKey,
                                  nil];

Can anyone please advice on the kAudioFormat or audio settings to write the file using AVAssetWriterInput to save it in AIFF audio format ?


回答1:


I haven' worked with AVAssetWriter so far, but I assume its basically a format description as in Core Audio with ASBDs.

An example of a AudioBasicStreamDescription defined for AIFF see for example here:

aiffFormat.mSampleRate = sampleRate;
aiffFormat.mFormatID = kAudioFormatLinearPCM;
aiffFormat.mBytesPerPacket = 2;
aiffFormat.mFramesPerPacket = 1;
aiffFormat.mBytesPerFrame = 2;
aiffFormat.mChannelsPerFrame = 2; // for STEREO
aiffFormat.mBitsPerChannel = 16;
aiffFormat.mFormatFlags = (kLinearPCMFormatFlagIsBigEndian | kAudioFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger) ;
aiffFormat.mBitsPerChannel = sizeof(float) * 8;
aiffFormat.mBytesPerFrame = aiffFormat.mChannelsPerFrame * sizeof(Float32);
aiffFormat.mBytesPerPacket = aiffFormat.mFramesPerPacket * aiffFormat.mBytesPerFrame;

In your above code big endianess has to be set to YES. As mentioned I have never worked with AVAssetWriter, so I am not sure which further parameters have to be set or which not, but with the example stream description above, it should be not too hard to get running.



来源:https://stackoverflow.com/questions/21856074/kaudioformat-for-aif-audio-file-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!