使用AudioStreaming接口扩展DSF SoftUSBAudio示例代码 [英] Expanding the DSF SoftUSBAudio sample code with an AudioStreaming Interface

查看:126
本文介绍了使用AudioStreaming接口扩展DSF SoftUSBAudio示例代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

 

我正在尝试使用额外的SoftUSBInterface扩展SoftUSBAudio示例代码,以实现额外的AudioStreaming接口(链接到终端).

I'm trying to expand the SoftUSBAudio sample code with an extra SoftUSBInterface to achieve an extra AudioStreaming Interface(linked to a terminal).

据我所知,主代码文件(Audiodevice.cpp)执行以下操作:

As far as i can see, the main code file (Audiodevice.cpp) does the following:

创建一个SoftUSBDevice,用于音频控制接口的SoftUSBInterface(包括端点0),用于音频流IF的SoftUSBInterface(具有6个备用设置),用于每个备用流IF的SoftUSBEndpoint.

Create a SoftUSBDevice, SoftUSBInterface for Audio Controll Interface(incl. endpoint 0), SoftUSBInterface for Audio Streaming IF(with 6 alternate settings), SoftUSBEndpoint for each alternate streaming IF.

描述符(来自Audio10规范)已添加到SoftUSBObjects. AudioStreaming IF的标准设置没有得到它自己的端点或描述符.

Descriptors(from Audio10 specs) are added to the SoftUSBObjects. The standard setting for the AudioStreaming IF doesn't get it's own endpoint or descriptor.

然后开始仿真.

等时端点耗尽了.

设置了事件处理的端点(中断EP)

An endpoint for eventhandling is set up(interrupt EP)

来自主机的传入请求得到处理.

Incoming requests from host are processed.

 

查看以下(原始DSF)代码:

Look at the following piece of (original DSF) code:

 

HRESULT CAudioDevice :: CreateAudioStreamingInterfaces
(
    ISoftUSBDevice       * piSoftUSBDevice,
    ISoftUSBInterfaces    * piInterfaces
)
/* ++
常规说明:
  为音频流接口创建SoftUSBInterface对象,
  配置它们,并将它们添加到指定的接口集合中.
  

参数:
    piSoftUSBDevice-拥有配置的设备

    piInterfaces-音频流传输到的SoftUSBInterface集合
   接口将被添加

返回值:
   其他-来自被调用的函数
-*/
{
    HRESULT                           hr = S_OK;
    ISoftUSBInterface * piInterface = NULL;
    ISoftUSBEndpoints    * piEndpoints = NULL;
    ISoftUSBEndpoint     * piEndpoint = NULL;
    BYTE                   i = 0;
    SAFEARRAY                                    * psa = NULL;
   变量                           varIndex; VariantInit(& varIndex);
   变量                           varEndpointIndex; VariantInit(& varEndpointIndex);

    UNREFERENCED_PARAMETER(piSoftUSBDevice);

    //所有接口集合项都会默认添加
    //位置,因此设置索引以表明它是可选的
    //未指定的参数.
    varIndex.vt = VT_ERROR;
    varIndex.scode = DISP_E_PARAMNOTFOUND;

    //所有端点将保存在端点的第一个位置
    //收集,以便可以在数据被提取时获取它们
    //从端点耗尽.请注意,只有一个端点
    //每个接口.
    varEndpointIndex.vt = VT_I4;
    varEndpointIndex.lVal = 1;

    //音频流类特定接口的地址数组
   静态AudioStreamingClassSpecificInterfaceDescriptorData * apStreamIntfDescs [] =
    {
       & StreamIntfDescAlt1
        & StreamIntfDescAlt2
        & StreamIntfDescAlt3
        & StreamIntfDescAlt4
        & StreamIntfDescAlt5
        & StreamIntfDescAlt6
    };

   静态USBENDPOINTATTRIBS EndpointAttribs;
    EndpointAttribs.Bits.TransferType = USB_TRANSFER_TYPE_ISOCH;
    EndpointAttribs.Bits.SyncType = USB_SYNC_TYPE_SYNC;
    EndpointAttribs.Bits.UsageType = USB_USAGE_TYPE_DATA;

    for(i = 0; i< = 6; i ++)
    {

        //创建一个SoftUSBInterface对象并获取ISoftUSBInterface
       //界面
       IfFailHrGo(:: CoCreateInstance(CLSID_SoftUSBInterface,
              b ;            NULL
              b ;            CLSCTX_INPROC_SERVER,
              b ;            __uuidof(ISoftUSBInterface),
              b ;            reinterpret_cast< void **>(& piInterface)));


        //配置界面属性
       IfFailHrGo(piInterface-> put_InterfaceNumber(m_bStreamInterface));
       IfFailHrGo(piInterface-> put_AlternateSetting(i));
       IfFailHrGo(piInterface-> put_InterfaceClass(1));    //音频类
       IfFailHrGo(piInterface-> put_InterfaceSubClass(2)); //音频流
       IfFailHrGo(piInterface-> put_InterfaceProtocol(0));
       IfFailHrGo(piInterface-> put_Interface(STRING_IDX_AUDIO_STREAMING_INTERFACE));

       if(i> 0)//替代设置0未定义端点
       {

            //创建包含音频流的SAFEARRAY
                                      //特定于类的接口描述符数据并设置
                                      //带有它的SoftUSBInterface.DeviceSpecificDescriptor
                                      IfFailHrGo(ByteArrayToSafeArray(reinterpret_cast< BYTE *>(apStreamIntfDescs [i-1]),sizeof(*(apStreamIntfDescs [i-1])),psa));
                                      IfFailHrGo(piInterface-> put_DeviceSpecificDescriptor(psa));
                                      (void):: SafeArrayDestroy(psa);
                                      psa = NULL;

                                      //创建一个SoftUSBEndpoint对象并获取一个
                                      //上面有ISoftUSBEndpoint接口
                                      IfFailHrGo(:: CoCreateInstance(CLSID_SoftUSBEndpoint,
;               NULL
              b ; CLSCTX_INPROC_SERVER,
              b ;               __uuidof(ISoftUSBEndpoint),
              b ;               reinterpret_cast< void **>(& piEndpoint)));

                                      //配置端点属性
                                      IfFailHrGo(piEndpoint-> put_EndpointAddress(4));
                                      IfFailHrGo(piEndpoint-> put_Attributes(EndpointAttribs.Byte));
                                      IfFailHrGo(piEndpoint-> put_MaxPacketSize(0x0040));
                                      IfFailHrGo(piEndpoint-> put_Interval(1));
                                      IfFailHrGo(piEndpoint-> put_HandleStdDeviceRequests(VARIANT_TRUE));

                                      //创建包含音频流的SAFEARRAY
                                      //特定于类的端点描述符数据并设置
                                      //带有它的SoftUSBEndpoint.DeviceSpecificDescriptor
                                      IfFailHrGo(ByteArrayToSafeArray(reinterpret_cast< BYTE *>(& StreamEPDesc),sizeof(StreamEPDesc),psa));
                                      IfFailHrGo(piEndpoint-> put_DeviceSpecificDescriptor(psa));
                                      (void):: SafeArrayDestroy(psa);
                                      psa = NULL;

                                      //将端点添加到SoftUSBInterface.Endpoints
                                      IfFailHrGo(piInterface-> get_Endpoints(& piEndpoints));
                                      IfFailHrGo(piEndpoints-> Add(reinterpret_cast< SoftUSBEndpoint *>(piEndpoint),varEndpointIndex));

                                      RELEASE(piEndpoints);
                                      RELEASE(piEndpoint);
       }

       //将接口添加到指定的SoftUSBInterface0集合
       IfFailHrGo(piInterfaces-> Add(reinterpret_cast< SoftUSBInterface *>(piInterface),varIndex));
       RELEASE(piInterface);
       
    }

HRESULT CAudioDevice::CreateAudioStreamingInterfaces
(
    ISoftUSBDevice        *piSoftUSBDevice,
    ISoftUSBInterfaces    *piInterfaces
)
/*++
Routine Description:
   Creates SoftUSBInterface objects for the audio streaming interfaces,
   configures them, and adds them to the specified interface collection.
  

Arguments:
    piSoftUSBDevice - the device that owns the config

    piInterfaces - SoftUSBInterface collection to which audio streaming
    interfaces will be added

Return value:
    other - from called functions
--*/
{
    HRESULT               hr = S_OK;
    ISoftUSBInterface    *piInterface = NULL;
    ISoftUSBEndpoints    *piEndpoints = NULL;
    ISoftUSBEndpoint     *piEndpoint = NULL;
    BYTE                  i = 0;
    SAFEARRAY            *psa = NULL;
    VARIANT               varIndex; VariantInit(&varIndex);
    VARIANT               varEndpointIndex; VariantInit(&varEndpointIndex);

    UNREFERENCED_PARAMETER(piSoftUSBDevice);

    // All interface collection items will be added at the default
    // locations so set up the index to indicate it is an optional
    // parameter that has not been specified.
    varIndex.vt = VT_ERROR;
    varIndex.scode = DISP_E_PARAMNOTFOUND;

    // All endpoints will be saved in the 1st location in the endpoint
    // collection so that they can be retrived when the data is
    // drained from the endpoint. Note there is only one endpoint
    // per interface.
    varEndpointIndex.vt = VT_I4;
    varEndpointIndex.lVal = 1;

    // Array of addresses of audio streaming class-specific interfaces
    static AudioStreamingClassSpecificInterfaceDescriptorData *apStreamIntfDescs[] =
    {
        &StreamIntfDescAlt1,
        &StreamIntfDescAlt2,
        &StreamIntfDescAlt3,
        &StreamIntfDescAlt4,
        &StreamIntfDescAlt5,
        &StreamIntfDescAlt6
    };

    static USBENDPOINTATTRIBS EndpointAttribs;
    EndpointAttribs.Bits.TransferType = USB_TRANSFER_TYPE_ISOCH;
    EndpointAttribs.Bits.SyncType = USB_SYNC_TYPE_SYNC;
    EndpointAttribs.Bits.UsageType = USB_USAGE_TYPE_DATA;

    for (i = 0; i <= 6; i++)
    {

        // Create a SoftUSBInterface object and get an ISoftUSBInterface
        // interface on it
        IfFailHrGo(::CoCreateInstance(CLSID_SoftUSBInterface,
                                      NULL,
                                      CLSCTX_INPROC_SERVER,
                                      __uuidof(ISoftUSBInterface),    
                                      reinterpret_cast<void **>(&piInterface)));


        // Configure the interface properties
        IfFailHrGo(piInterface->put_InterfaceNumber(m_bStreamInterface));
        IfFailHrGo(piInterface->put_AlternateSetting(i));
        IfFailHrGo(piInterface->put_InterfaceClass(1));    // audio class
        IfFailHrGo(piInterface->put_InterfaceSubClass(2)); // audio streaming
        IfFailHrGo(piInterface->put_InterfaceProtocol(0));
        IfFailHrGo(piInterface->put_Interface(STRING_IDX_AUDIO_STREAMING_INTERFACE));

        if (i > 0) // alternate setting 0 does not define endpoints
        {

            // Create a SAFEARRAY containing the audio streaming
            // class-specific interface descriptor data and set
            // SoftUSBInterface.DeviceSpecificDescriptor with it
            IfFailHrGo(ByteArrayToSafeArray(reinterpret_cast<BYTE *>(apStreamIntfDescs[i-1]), sizeof(*(apStreamIntfDescs[i-1])), psa));
            IfFailHrGo(piInterface->put_DeviceSpecificDescriptor(psa));
            (void)::SafeArrayDestroy(psa);
            psa = NULL;

            // Create a SoftUSBEndpoint object and get an
            // ISoftUSBEndpoint interface on it
            IfFailHrGo(::CoCreateInstance(CLSID_SoftUSBEndpoint,
                                          NULL,
                                          CLSCTX_INPROC_SERVER,
                                          __uuidof(ISoftUSBEndpoint),    
                                          reinterpret_cast<void **>(&piEndpoint)));

            // Configure the endpoint properties
            IfFailHrGo(piEndpoint->put_EndpointAddress(4));
            IfFailHrGo(piEndpoint->put_Attributes(EndpointAttribs.Byte));
            IfFailHrGo(piEndpoint->put_MaxPacketSize(0x0040));
            IfFailHrGo(piEndpoint->put_Interval(1));
            IfFailHrGo(piEndpoint->put_HandleStdDeviceRequests(VARIANT_TRUE));

            // Create a SAFEARRAY containing the audio streaming
            // class-specific endpoint descriptor data and set
            // SoftUSBEndpoint.DeviceSpecificDescriptor with it
            IfFailHrGo(ByteArrayToSafeArray(reinterpret_cast<BYTE *>(&StreamEPDesc), sizeof(StreamEPDesc), psa));
            IfFailHrGo(piEndpoint->put_DeviceSpecificDescriptor(psa));
            (void)::SafeArrayDestroy(psa);
            psa = NULL;

            // Add the endpoint to SoftUSBInterface.Endpoints
            IfFailHrGo(piInterface->get_Endpoints(&piEndpoints));
            IfFailHrGo(piEndpoints->Add(reinterpret_cast<SoftUSBEndpoint *>(piEndpoint), varEndpointIndex));

            RELEASE(piEndpoints);
            RELEASE(piEndpoint);
        }

        // Add the interface to the specified SoftUSBInterface0 collection
        IfFailHrGo(piInterfaces->Add(reinterpret_cast<SoftUSBInterface *>(piInterface), varIndex));
        RELEASE(piInterface);
       
    }

 

这段代码为AS IF设置了ISoftUSBInterface.我用多个接口的描述符替换了备用描述符.

This piece of code sets up the ISoftUSBInterface for the AS IF. I replaced the alternative descriptors with descriptors for multiple interfaces.

还调整了音频控制接口的描述符(标题(大小,接口数,接口号),附加端子)

Also adjusted the descriptors of the Audio Control Interface(header(size, number of interfaces, interface numbers), extra terminal)

之后有一个额外的for循环: for(i = 0; i< = 6; i ++) < ------ 针对(i = 0; i< = 1; i ++)

With an extra for loop after: for (i = 0; i <= 6; i++)   <------ Adjusted to for (i = 0; i <= 1; i++)

我可以定义多个接口,每个接口都有一个替代设置,包括.端点.插入HUB时,它们会出现在模拟屏幕中.

I can define multiple interfaces, each with an alternative setting incl. endpoint. They appear in the simulation screen while plugging in the HUB.

但是:模拟无法启动,并且在设备管理器中,我的USB设备带有黄色的感叹号,表示该设备无法启动.

HOWEVER: The simulation won't start, and in device manager, my USB device has a yellow exclamation mark, saying the device won't start.

 

我使用一个以上接口的原因是能够使用标准USB类微型驱动程序并能够查看16个设备:

The reason for me to use more then one interface is to be able to use the standard USB class mini driver and be able to see 16 devices:

8立体声输入,8立体声输出.

8 stereo in, 8 stereo out.

这些设备可以由不同的应用程序单独使用.

These devices could be used seperately by different applications.

 

有人可以告诉我是否真的有可能通过另一个界面扩展此示例

Can someone please tell me if it's actually possible to expand this sample with another interface

并尝试让我了解如何执行此操作(将我指向正确的方向).我将非常感谢.

and try to get me on the way regarding how to do this(point me in the right direction). I would be very grateful.

 

对于仿真,我使用的是

x86的XP构建环境(从项目生成dll)

x86 build environment for XP(to make dll from project)

softEHCI控制器

softEHCI controller

 

我浏览了以下资源:

MSDN:WDM架构,AudioCore API,SoftUSBAudio等

MSDN: WDM architecture, AudioCore API's, SoftUSBAudio, and more

Audio10Specs

Audio10Specs

Format10Specs

Format10Specs

 

推荐答案

我相信您需要调用CAudioDevice :: StartSimulation才能显式启动设备.您已经超过了这一点吗?

I believe you need to call the CAudioDevice::StartSimulation in order to explicitly start the device.  Have you gotten past this point?


这篇关于使用AudioStreaming接口扩展DSF SoftUSBAudio示例代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆