私は、デジタル信号処理を行うアプリを作成しようとしており、できるだけ軽量にしたいと考えています。しばらく私を困惑させたのは、バッファからデータを受け取る前に不要な変換が行われないようにするために、さまざまなデバイスのデフォルト値がどうなるかということでした。次のリンクhttp://club15cc.com/code-snippets/ios-2/get-the-default-output-stream-format-for-an-audio-unit-in-iosに出くわしました。それが正しい道だと信じています。
リンクからコードを拡張して、ASBD(AudioStreamBasicDescription) コンテンツを取得する前に AVAudioSession を作成およびアクティブ化しました。AudioSession を使用して、さまざまな「優先」設定を要求し、それらがどのような影響を与えるかを確認できます。また、ASBD の値を一覧表示するための Apple コードと、上記のリンクのコードを組み合わせました。
以下のコードは、Single View Application テンプレートを選択して生成された ViewController.m ファイルに挿入されます。AudioToolbox.framework と CoreAudio.framework をプロジェクトのリンクされたフレームワークとライブラリに追加する必要があることに注意してください。
#import "ViewController.h"
@import AVFoundation;
@import AudioUnit;
@interface ViewController ()
@end
@implementation ViewController
- (void) printASBD:(AudioStreamBasicDescription) asbd {
char formatIDString[5];
UInt32 formatID = CFSwapInt32HostToBig (asbd.mFormatID);
bcopy (&formatID, formatIDString, 4);
formatIDString[4] = '\0';
NSLog (@" Sample Rate: %10.0f", asbd.mSampleRate);
NSLog (@" Format ID: %10s", formatIDString);
NSLog (@" Format Flags: %10X", (unsigned int)asbd.mFormatFlags);
NSLog (@" Bytes per Packet: %10d", (unsigned int)asbd.mBytesPerPacket);
NSLog (@" Frames per Packet: %10d", (unsigned int)asbd.mFramesPerPacket);
NSLog (@" Bytes per Frame: %10d", (unsigned int)asbd.mBytesPerFrame);
NSLog (@" Channels per Frame: %10d", (unsigned int)asbd.mChannelsPerFrame);
NSLog (@" Bits per Channel: %10d", (unsigned int)asbd.mBitsPerChannel);
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSError *error = nil;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
// Get a reference to the AudioSession and activate it
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioSession setActive:YES error:&error];
// Then get RemoteIO AudioUnit and use it to get the content of the default AudioStreamBasicDescription
AudioUnit remoteIOUnit;
AudioComponentDescription audioComponentDesc = {0};
audioComponentDesc.componentType = kAudioUnitType_Output;
audioComponentDesc.componentSubType = kAudioUnitSubType_RemoteIO;
audioComponentDesc.componentManufacturer = kAudioUnitManufacturer_Apple;
// Get component
AudioComponent audioComponent = AudioComponentFindNext(NULL, &audioComponentDesc);
AudioComponentInstanceNew(audioComponent, &remoteIOUnit);
// Read the stream format
size_t asbdSize = sizeof(AudioStreamBasicDescription);
AudioStreamBasicDescription asbd = {0};
AudioUnitGetProperty(remoteIOUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
0,
(void *)&asbd,
&asbdSize);
[self printASBD:asbd];
}
@end
他の実際のハードウェアで人々が得た結果を知りたいです。コードが構築され、IOS 7.1 に展開されたことに注意してください。