///////////////////////////////////////////////////////////////////////////////
// Function:
//      EndpointIsMicArray
//
// Description:
//      Determines if a given IMMDevice is a microphone array by Endpoint pointer
//
// Returns:
//      S_OK on success
///////////////////////////////////////////////////////////////////////////////
HRESULT EndpointIsMicArray(IMMDevice* pEndpoint, bool & isMicrophoneArray)
{
    if (pEndpoint == NULL)
        return E_POINTER;

    GUID subType = {0};

    HRESULT hr = GetJackSubtypeForEndpoint(pEndpoint, &subType);

    isMicrophoneArray = (subType == KSNODETYPE_MICROPHONE_ARRAY) ? true : false;

    return hr;
}// EndpointIsMicArray()
    ///////////////////////////////////////////////////////////////////////////
    // GetMicArrayDeviceIndex
    //
    // Obtain device index corresponding to microphone array device.
    //
    // Parameters: piDevice: [out] Index of microphone array device.
    //
    // Return: S_OK if successful
    //         Failure code otherwise (e.g.: if microphone array device is not found).
    //
    ///////////////////////////////////////////////////////////////////////////////
    int KinectAudioSource::GetMicArrayDeviceIndex()
    {
        CComPtr<IMMDeviceEnumerator> spEnumerator;
        CHECKHR( spEnumerator.CoCreateInstance( __uuidof(MMDeviceEnumerator),  NULL, CLSCTX_ALL ) );

        CComPtr<IMMDeviceCollection> spEndpoints;
        CHECKHR( spEnumerator->EnumAudioEndpoints( eCapture, DEVICE_STATE_ACTIVE, &spEndpoints ) );

        UINT dwCount = 0;
        CHECKHR(spEndpoints->GetCount(&dwCount));

        // Iterate over all capture devices until finding one that is a microphone array
        for ( UINT index = 0; index < dwCount; index++) {
            IMMDevice* spDevice;
            CHECKHR( spEndpoints->Item( index, &spDevice ) );
        
            GUID subType = GetJackSubtypeForEndpoint( spDevice );
            if ( subType == KSNODETYPE_MICROPHONE_ARRAY ) {
                return index;
            }
        }

        throw std::runtime_error( "デバイスが見つかりません" );
    }