2012-01-20 15 views
7

ここでは何が起こっているのですか?Core AudioとPhantom Device ID

私はCore Audio、特に入力デバイスを使用しようとしています。私はミュートしたい、音量を変える、など、私は私が理解できない何かが全く奇妙に遭遇しました。これまでのところ、Googleは役に立たなかった。

私はシステムに問い合わせて、すべてのオーディオデバイスのリストを要求すると、デバイスIDの配列が返されます。この場合、261、259、263、257 kAudioDevicePropertyDeviceNameを使用して

、私は次を得る:

261:内蔵マイク
259:内蔵入力
263:組み込み出力
257:iPhoneSimulatorAudioDevice

これはすべて順調です。

// This method returns an NSArray of all the audio devices on the system, both input and 
// On my system, it returns 261, 259, 263, 257 
- (NSArray*)getAudioDevices 
{ 
    AudioObjectPropertyAddress propertyAddress = { 
    kAudioHardwarePropertyDevices, 
    kAudioObjectPropertyScopeGlobal, 
    kAudioObjectPropertyElementMaster 
    }; 

    UInt32 dataSize = 0; 
    OSStatus status = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize); 
    if(kAudioHardwareNoError != status) 
    { 
    MZLog(@"Unable to get number of audio devices. Error: %d",status); 
    return NULL; 
    } 

    UInt32 deviceCount = dataSize/sizeof(AudioDeviceID); 

    AudioDeviceID *audioDevices = malloc(dataSize); 

    status = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &dataSize, audioDevices); 
    if(kAudioHardwareNoError != status) 
    { 
    MZLog(@"AudioObjectGetPropertyData failed when getting device IDs. Error: %d",status); 
    free(audioDevices), audioDevices = NULL; 
    return NULL; 
    } 

    NSMutableArray* devices = [NSMutableArray array]; 

    for(UInt32 i = 0; i < deviceCount; i++) 
    {  
    MZLog(@"device found: %d",audioDevices[i]); 
    [devices addObject:[NSNumber numberWithInt:audioDevices[i]]]; 
    } 

    free(audioDevices); 

    return [NSArray arrayWithArray:devices]; 
} 

私はシステムに問い合わせて、デフォルトの入力デバイスのIDを尋ねると問題が発生します。このメソッドは、すべてのデバイスの配列にではなく、のID 269を返します。

kAudioDevicePropertyDeviceNameを使用してデバイスの名前を取得しようとすると、空の文字列が返されます。名前は表示されませんが、このデバイスIDをミュートすると、内蔵のマイクがミュートされます。逆に、「Built-In Microphone」という名前の261 IDをミュートすると、マイクはでなく、のミュートを行います。

// Gets the current default audio input device 
// On my system, it returns 269, which is NOT LISTED in the array of ALL audio devices 
- (AudioDeviceID)defaultInputDevice 
{ 
    AudioDeviceID defaultAudioDevice; 
    UInt32 propertySize = 0; 
    OSStatus status = noErr; 
    AudioObjectPropertyAddress propertyAOPA; 

    propertyAOPA.mElement = kAudioObjectPropertyElementMaster; 
    propertyAOPA.mScope = kAudioObjectPropertyScopeGlobal; 
    propertyAOPA.mSelector = kAudioHardwarePropertyDefaultInputDevice; 
    propertySize = sizeof(AudioDeviceID); 

    status = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAOPA, 0, NULL, &propertySize, &defaultAudioDevice); 

    if(status) 
    { //Error 
    NSLog(@"Error %d retreiving default input device",status); 
    return 0; 
    } 

    return defaultAudioDevice; 
} 
私は手動で「ラインイン」に私の入力を切り替え、 に記載されているデフォルトの入力デバイス、の照会時にプログラムを再実行して、私は259のIDを取得する場合

はさらに、物事を混乱させるためにすべてのデバイスの配列だから、

は、要約する:私は私のシステムでは、入力デバイスと対話しようとしています

。私の「Built-In Microphone」であるデバイスID 261と対話しようとすると、何も起こりません。私が明らかにファントムIDであるデバイスID 269と対話しようとすると、内蔵のマイクが影響を受けます。 269 IDは、システムにデフォルトの入力デバイスを照会すると返されますが、すべてのデバイスのリストをシステムに照会するとリストされません。

何が起こっているか知っていますか?私は単に狂気になるのだろうか?

ありがとうございます!

答えて

3

修正済みです。

まず、ファントムデバイスIDは、単にシステムが使用していた仮想デバイスでした。

第2に、私がAudioObjectSetPropertyDataの代わりにAudioHardwareServiceSetPropertyDataを使用していたため、実際のデバイスで何も音を消したり何もしなかった理由がありました。

すべては現在動作しています。

関連する問題