Ios 音频会话、音频流基本描述和远程IO设备默认值

Ios 音频会话、音频流基本描述和远程IO设备默认值,ios,avaudiosession,audiostreamer,remoteio,Ios,Avaudiosession,Audiostreamer,Remoteio,我正在尝试写一个应用程序,将做数字信号处理的过程中,并希望使它尽可能轻。有一件事让我困惑了一段时间,那就是各种设备的默认值可能是多少,这样我就可以避免在从缓冲区接收数据之前发生不必要的转换。我遇到了以下链接,这让我走上了我认为正确的道路 我已经扩展了链接中的代码,在获取AsbAudioStreamBasicDescription内容之前创建并激活了一个AudioSession,然后可以使用AudioSession请求各种首选设置,以查看它们的影响。我还将列出ASBD值的Apple代码与上面链接中

我正在尝试写一个应用程序,将做数字信号处理的过程中,并希望使它尽可能轻。有一件事让我困惑了一段时间,那就是各种设备的默认值可能是多少,这样我就可以避免在从缓冲区接收数据之前发生不必要的转换。我遇到了以下链接,这让我走上了我认为正确的道路

我已经扩展了链接中的代码,在获取AsbAudioStreamBasicDescription内容之前创建并激活了一个AudioSession,然后可以使用AudioSession请求各种首选设置,以查看它们的影响。我还将列出ASBD值的Apple代码与上面链接中的代码结合起来

下面的代码被放入通过选择单视图应用程序模板生成的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的,格式标志为:

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),

我猜LPCM线性脉冲编码调制并不令人惊讶,格式标志=x'29'kAudioFormatFlagIsFloat | KaudioFormatFlagis与每个通道32位一起打包似乎表明预期的8.24固定浮点

感谢您的澄清。再看一看,我认为您在这里看到的是默认设置,与设备无关,反映了kAudioFormatFlagsNativeFloatPacked的建议。看看kAudioFormatFlagIsNonInterleaved是否真的能告诉你这个设备是立体声还是单声道,这会很有趣。
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