kAudioFormat为.AIF音频文件转换? [英] kAudioFormat for .aif audio file conversion?
问题描述
我想转换/ AAC从格式保存音频文件AIFF音频格式。默认我和LineraPCM尝试。 。但音频格式保存在AAC格式。 。我想保存在AIFF format.Here是我的code中的音频文件。
的NSDictionary * outputSettings = [NSDictionary的dictionaryWithObjectsAndKeys:
[NSNumber的numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber的numberWithFloat:44100.0],AVSampleRateKey,
[的NSNumber numberWithInt:2],AVNumberOfChannelsKey,
[NSData的dataWithBytes:放大器; channelLayout长度:的sizeof(AudioChannelLayout),AVChannelLayoutKey,
[的NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber的numberWithBool:NO],AVLinearPCMIsNonInterleaved,
[NSNumber的numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber的numberWithBool:NO],AVLinearPCMIsBigEndianKey,
零];
块引用>任何人都可以请咨询对kAudioFormat或音频设置使用AVAssetWriterInput将其保存在AIFF音频格式写入文件?
解决方案
我的避风港'与AVAssetWriter工作至今
有关AIFF定义的AudioBasicStreamDescription的例子看,例如在这里:
aiffFormat.mSampleRate =采样率;
aiffFormat.mFormatID = kAudioFormatLinearPCM;
aiffFormat.mBytesPerPacket = 2;
aiffFormat.mFramesPerPacket = 1;
aiffFormat.mBytesPerFrame = 2;
aiffFormat.mChannelsPerFrame = 2; //为STEREO
aiffFormat.mBitsPerChannel = 16;
aiffFormat.mFormatFlags =(kLinearPCMFormatFlagIsBigEndian | kAudioFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger);
aiffFormat.mBitsPerChannel = sizeof的(浮点)* 8;
aiffFormat.mBytesPerFrame = aiffFormat.mChannelsPerFrame * sizeof运算(浮点32);
aiffFormat.mBytesPerPacket = aiffFormat.mFramesPerPacket * aiffFormat.mBytesPerFrame;
块引用>在您的上述code大字节顺序已被设置为YES。正如前面提到的我从来没有与AVAssetWriter工作,所以我不知道这进一步参数进行设置或没有,但上面的例子流描述,应该不是太难获得运行。
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 ?
解决方案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.
这篇关于kAudioFormat为.AIF音频文件转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!