5

オーディオを録音して、他のサウンド形式に変換しようとしています。AVAudioRecorder クラスを使用して録音しています。これらは、使用した録音設定です。

 NSDictionary *recordSetting = [[NSMutableDictionary alloc] init];
 [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];//kAudioFormatMicrosoftGSM,kAudioFormatLinearPCM
 [recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey]; 
 [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
 [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
 [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
 [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];

録音は美しく機能しています。次に、このサウンド ファイルを mp3 形式に変換します。AudioToolBox フレームワークでこれを行うことはできますか。私はこれを試しました

 AudioStreamBasicDescription sourceFormat,destinationFormat;
 //Setting up source Format setting..here wav
 sourceFormat.mSampleRate   = 8000.0;
 sourceFormat.mFormatID    = kAudioFormatLinearPCM;
 sourceFormat.mFormatFlags   = kAudioFormatFlagIsSignedInteger ;
 sourceFormat.mBytesPerPacket  = 4;
 sourceFormat.mFramesPerPacket  = 1;
 sourceFormat.mBytesPerFrame   = 4;
 sourceFormat.mChannelsPerFrame  = 2;
 sourceFormat.mBitsPerChannel  = 16;

 destinationFormat.mSampleRate  = 8000.0;
 destinationFormat.mFormatID   = kAudioFormatMPEGLayer3;
 destinationFormat.mFormatFlags  = 0;
 destinationFormat.mBytesPerPacket = 4;
 destinationFormat.mFramesPerPacket = 1;
 destinationFormat.mBytesPerFrame = 4;
 destinationFormat.mChannelsPerFrame = 2;
 destinationFormat.mBitsPerChannel = 16;

 OSStatus returnCode     =     AudioConverterNew(&sourceFormat,&destinationFormat,&converter);
 if (returnCode) {
    NSLog(@"error getting converter : %d",returnCode);
    return;
 }

関数 AudioConverterNew() でエラー kAudioConverterErr_FormatNotSupported ('fmt') が発生しています。さまざまな mFormatID と mFormatFlag の組み合わせを試しました。しかし、オペラント (ソースまたは宛先) の 1 つが mp3 の場合は常に、このエラーが発生します。これらの質問について教えてください。

  1. AudioToolbox フレームワークと関数を使用して、サウンドを圧縮形式と非圧縮形式の間で変換できますか (現在、.wav と .mp3 の間で変換したいと考えています)。AudioConverterNew のドキュメントでは、「リニア PCM と圧縮形式の間のエンコードとデコードがサポートされている」と述べています。しかし、彼らは具体的にどの圧縮形式を言っているわけではありません。

  2. 質問 1 に対する答えが「いいえ」の場合、上記のフォーマット間でサウンドを変換するには、どのフレームワークを使用する必要がありますか?

  3. 上記の 2 とは関係ありませんが、さまざまなサウンド形式 (wav、mp3、aac など) とそのデジタル表現 (cpm、lpcm など) に関する情報がある Web サイトへのリンクを教えてください。
4

1 に答える 1

1

いくつかの答え

  1. はい、.mp3 形式の場合を除き、AudioToolbox フレームワークを使用してサウンドを変換できます。著作権の問題により、mp3 はフレームワーク内のターゲット形式として使用できません。

  2. mp3 に変換したい場合は、おそらく LAME ライブラリを使用する必要があります: http://lame.cvs.sourceforge.net/viewvc/lame/lame/USAGE

  3. .mp3 仕様の 1 つを次に示します: http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html 他の形式は、Web 検索で簡単に見つけることができます

それが役立つことを願っています

于 2012-07-02T13:15:48.357 に答える