问题
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