0

私は、デジタル信号処理を行うアプリを作成しようとしており、できるだけ軽量にしたいと考えています。しばらく私を困惑させたのは、バッファからデータを受け取る前に不要な変換が行われないようにするために、さまざまなデバイスのデフォルト値がどうなるかということでした。次のリンク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 に展開されたことに注意してください。

4

1 に答える 1

0

フォーマット フラグは次のとおりです。

kAudioFormatFlagIsFloat                  = (1 << 0),    // 0x1
kAudioFormatFlagIsBigEndian              = (1 << 1),    // 0x2
kAudioFormatFlagIsSignedInteger          = (1 << 2),    // 0x4
kAudioFormatFlagIsPacked                 = (1 << 3),    // 0x8
kAudioFormatFlagIsAlignedHigh            = (1 << 4),    // 0x10
kAudioFormatFlagIsNonInterleaved         = (1 << 5),    // 0x20
kAudioFormatFlagIsNonMixable             = (1 << 6),    // 0x40
kAudioFormatFlagsAreAllClear             = (1 << 31),

iPad 4 で得た結果は次のとおりです。

Sample Rate:                  0
Format ID:                 lpcm
Format Flags:                29
Bytes per Packet:             4
Frames per Packet:            1
Bytes per Frame:              4
Channels per Frame:           2
Bits per Channel:            32

lpcm(Linear Pulse Coded Modulation) は驚くべきことではなく、Format Flags = x'29'kAudioFormatFlagIsFloat | kAudioFormatFlagIsPackedと 32 ビット/チャンネルは、予想される 8.24 の「固定浮動小数点数」を示しているようです。

于 2014-04-22T20:25:18.267 に答える