⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsound.c

📁 一个类似windows
💻 C
📖 第 1 页 / 共 3 页
字号:
        bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;        bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,                                    wfx.nBlockAlign);        bufdesc.lpwfxFormat=&wfx;        rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);        ok(rc==DS_OK && secondary!=NULL,           "IDirectSound_CreateSoundBuffer() failed to create a secondary "           "buffer %s\n",DXGetErrorString8(rc));        if (rc==DS_OK && secondary!=NULL) {            LPDIRECTSOUND3DBUFFER buffer3d;            rc=IDirectSound_QueryInterface(secondary, &IID_IDirectSound3DBuffer,                                           (void **)&buffer3d);            ok(rc==DS_OK && buffer3d!=NULL,"IDirectSound_QueryInterface() "               "failed:  %s\n",DXGetErrorString8(rc));            if (rc==DS_OK && buffer3d!=NULL) {                ref=IDirectSound3DBuffer_AddRef(buffer3d);                ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "                   "should have 2\n",ref);            }            ref=IDirectSoundBuffer_AddRef(secondary);            ok(ref==2,"IDirectSoundBuffer_AddRef() has %d references, "               "should have 2\n",ref);        }        /* release with buffer */        ref=IDirectSound_Release(dso);        ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",           ref);        if (ref!=0)            return DSERR_GENERIC;    } else        return rc;    return DS_OK;}static HRESULT test_primary(LPGUID lpGuid){    HRESULT rc;    LPDIRECTSOUND dso=NULL;    LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;    DSBUFFERDESC bufdesc;    DSCAPS dscaps;    WAVEFORMATEX wfx;    int ref;    /* Create the DirectSound object */    rc=DirectSoundCreate(lpGuid,&dso,NULL);    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,       "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));    if (rc!=DS_OK)        return rc;    /* Get the device capabilities */    ZeroMemory(&dscaps, sizeof(dscaps));    dscaps.dwSize=sizeof(dscaps);    rc=IDirectSound_GetCaps(dso,&dscaps);    ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));    if (rc!=DS_OK)        goto EXIT;    /* DSOUND: Error: Invalid buffer description pointer */    rc=IDirectSound_CreateSoundBuffer(dso,0,0,NULL);    ok(rc==DSERR_INVALIDPARAM,       "IDirectSound_CreateSoundBuffer() should have failed: %s\n",       DXGetErrorString8(rc));    /* DSOUND: Error: Invalid buffer description pointer */    rc=IDirectSound_CreateSoundBuffer(dso,0,&primary,NULL);    ok(rc==DSERR_INVALIDPARAM && primary==0,       "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"       "dsbo=%p\n",DXGetErrorString8(rc),primary);    /* DSOUND: Error: Invalid buffer description pointer */    rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,0,NULL);    ok(rc==DSERR_INVALIDPARAM && primary==0,       "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"       "dsbo=0x%p\n",DXGetErrorString8(rc),primary);    ZeroMemory(&bufdesc, sizeof(bufdesc));    /* DSOUND: Error: Invalid size */    /* DSOUND: Error: Invalid buffer description */    rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);    ok(rc==DSERR_INVALIDPARAM && primary==0,       "IDirectSound_CreateSoundBuffer() should have failed: rc=%s,"       "primary=%p\n",DXGetErrorString8(rc),primary);    /* We must call SetCooperativeLevel before calling CreateSoundBuffer */    /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */    rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);    ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",       DXGetErrorString8(rc));    if (rc!=DS_OK)        goto EXIT;    /* Testing the primary buffer */    primary=NULL;    ZeroMemory(&bufdesc, sizeof(bufdesc));    bufdesc.dwSize=sizeof(bufdesc);    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;    bufdesc.lpwfxFormat = &wfx;    init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);    rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);    ok(rc==DSERR_INVALIDPARAM,"IDirectSound_CreateSoundBuffer() should have "       "returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc));    if (rc==DS_OK && primary!=NULL)        IDirectSoundBuffer_Release(primary);    primary=NULL;    ZeroMemory(&bufdesc, sizeof(bufdesc));    bufdesc.dwSize=sizeof(bufdesc);    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;    rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);    ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),       "IDirectSound_CreateSoundBuffer() failed to create a primary buffer: "       "%s\n",DXGetErrorString8(rc));    if (rc==DSERR_CONTROLUNAVAIL)        trace("  No Primary\n");    else if (rc==DS_OK && primary!=NULL) {        LONG vol;        /* Try to create a second primary buffer */        /* DSOUND: Error: The primary buffer already exists.         * Any changes made to the buffer description will be ignored. */        rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&second,NULL);        ok(rc==DS_OK && second==primary,           "IDirectSound_CreateSoundBuffer() should have returned original "           "primary buffer: %s\n",DXGetErrorString8(rc));        ref=IDirectSoundBuffer_Release(second);        ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "           "should have 1\n",ref);        /* Try to duplicate a primary buffer */        /* DSOUND: Error: Can't duplicate primary buffers */        rc=IDirectSound_DuplicateSoundBuffer(dso,primary,&third);        /* rc=0x88780032 */        ok(rc!=DS_OK,"IDirectSound_DuplicateSoundBuffer() primary buffer "           "should have failed %s\n",DXGetErrorString8(rc));        rc=IDirectSoundBuffer_GetVolume(primary,&vol);        ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",           DXGetErrorString8(rc));        if (winetest_interactive) {            trace("Playing a 5 seconds reference tone at the current "                  "volume.\n");            if (rc==DS_OK)                trace("(the current volume is %ld according to DirectSound)\n",                      vol);            trace("All subsequent tones should be identical to this one.\n");            trace("Listen for stutter, changes in pitch, volume, etc.\n");        }        test_buffer(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive &&                    !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0,FALSE,0);        ref=IDirectSoundBuffer_Release(primary);        ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "           "should have 0\n",ref);    }    /* Set the CooperativeLevel back to normal */    /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */    rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);    ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",       DXGetErrorString8(rc));EXIT:    ref=IDirectSound_Release(dso);    ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);    if (ref!=0)        return DSERR_GENERIC;    return rc;}/* * Test the primary buffer at different formats while keeping the * secondary buffer at a constant format. */static HRESULT test_primary_secondary(LPGUID lpGuid){    HRESULT rc;    LPDIRECTSOUND dso=NULL;    LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;    DSBUFFERDESC bufdesc;    DSCAPS dscaps;    WAVEFORMATEX wfx, wfx2;    int f,ref;    /* Create the DirectSound object */    rc=DirectSoundCreate(lpGuid,&dso,NULL);    ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,       "DirectSoundCreate() failed: %s\n",DXGetErrorString8(rc));    if (rc!=DS_OK)        return rc;    /* Get the device capabilities */    ZeroMemory(&dscaps, sizeof(dscaps));    dscaps.dwSize=sizeof(dscaps);    rc=IDirectSound_GetCaps(dso,&dscaps);    ok(rc==DS_OK,"IDirectSound_GetCaps() failed: %s\n",DXGetErrorString8(rc));    if (rc!=DS_OK)        goto EXIT;    /* We must call SetCooperativeLevel before creating primary buffer */    /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */    rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);    ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",       DXGetErrorString8(rc));    if (rc!=DS_OK)        goto EXIT;    ZeroMemory(&bufdesc, sizeof(bufdesc));    bufdesc.dwSize=sizeof(bufdesc);    bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;    rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);    ok(rc==DS_OK && primary!=NULL,       "IDirectSound_CreateSoundBuffer() failed to create a primary buffer "       "%s\n",DXGetErrorString8(rc));    if (rc==DS_OK && primary!=NULL) {        for (f=0;f<NB_FORMATS;f++) {            /* We must call SetCooperativeLevel to be allowed to call             * SetFormat */            /* DSOUND: Setting DirectSound cooperative level to             * DSSCL_PRIORITY */            rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);            ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",               DXGetErrorString8(rc));            if (rc!=DS_OK)                goto EXIT;            init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],                        formats[f][2]);            wfx2=wfx;            rc=IDirectSoundBuffer_SetFormat(primary,&wfx);            ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n",               DXGetErrorString8(rc));            /* There is no garantee that SetFormat will actually change the             * format to what we asked for. It depends on what the soundcard             * supports. So we must re-query the format.             */            rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);            ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",               DXGetErrorString8(rc));            if (rc==DS_OK &&                (wfx.wFormatTag!=wfx2.wFormatTag ||                 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||                 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||                 wfx.nChannels!=wfx2.nChannels)) {                trace("Requested primary format tag=0x%04x %ldx%dx%d "                      "avg.B/s=%ld align=%d\n",                      wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,                      wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);                trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",                      wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,                      wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);            }            /* Set the CooperativeLevel back to normal */            /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */            rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);            ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",               DXGetErrorString8(rc));            init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);            secondary=NULL;            ZeroMemory(&bufdesc, sizeof(bufdesc));            bufdesc.dwSize=sizeof(bufdesc);            bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;            bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,                                        wfx.nBlockAlign);            bufdesc.lpwfxFormat=&wfx2;            if (winetest_interactive) {                trace("  Testing a primary buffer at %ldx%dx%d with a "                      "secondary buffer at %ldx%dx%d\n",                      wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,                      wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);            }            rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);            ok(rc==DS_OK && secondary!=NULL,               "IDirectSound_CreateSoundBuffer() failed to create a secondary "               "buffer %s\n",DXGetErrorString8(rc));            if (rc==DS_OK && secondary!=NULL) {                test_buffer(dso,secondary,0,FALSE,0,FALSE,0,                            winetest_interactive,1.0,0,NULL,0,0,FALSE,0);                ref=IDirectSoundBuffer_Release(secondary);                ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "                   "should have 0\n",ref);            }        }        ref=IDirectSoundBuffer_Release(primary);        ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "           "should have 0\n",ref);    }    /* Set the CooperativeLevel back to normal */    /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */    rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);    ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %s\n",       DXGetErrorString8(rc));EXIT:    ref=IDirectSound_Release(dso);    ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);    if (ref!=0)        return DSERR_GENERIC;    return rc;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -