// @pymethod |PyIDirectSound|CreateSoundBuffer|The IDirectSound::CreateSoundBuffer method creates a DirectSoundBuffer object to hold a sequence of audio samples.
PyObject *PyIDirectSound::CreateSoundBuffer(PyObject *self, PyObject *args)
{
	PyObject *obDSBD = NULL;
	PyObject *obUnk = NULL;
	IUnknown *pUnkIn = NULL;

	IDirectSound *pIDS = GetI(self);
	if ( pIDS == NULL )
		return NULL;
	if ( !PyArg_ParseTuple(args, "O|O:CreateSoundBuffer", 
		&obDSBD,  // @pyparm <o PyDSCBUFFERDESC>|lpDSCBufferDesc||a DSBUFFERDESC structure containing values for the sound buffer being created.
		&obUnk) ) // @pyparm <o PyIUknown>|unk|None|The IUnknown for COM aggregation.
		return NULL;

	if (!PyDSBUFFERDESC_Check(obDSBD)) {
		PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type DSBUFFERDESC");
		return NULL;
	}

	if (obUnk && !PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnkIn, TRUE)) {
		return NULL;
	}
	

	DSBUFFERDESC *pdsbd = &((PyDSBUFFERDESC*)obDSBD)->m_dsbd;
	HRESULT hr;
	IDirectSoundBuffer *buffer;

	PY_INTERFACE_PRECALL;
	hr = pIDS->CreateSoundBuffer(pdsbd, &buffer, pUnkIn);
	PY_INTERFACE_POSTCALL;

	if (FAILED(hr)) {
		PyWin_SetAPIError("CreateSoundBuffer", hr);
		return NULL;
	}

	PyIDirectSoundBuffer *rc = new PyIDirectSoundBuffer(buffer);

	Py_INCREF(self);
	rc->m_DS = self;

	return rc;
}
示例#2
0
文件: d3d8.cpp 项目: lcsondes/flsubs
extern "C" IDirect3D8* __stdcall MyDirect3DCreate8(UINT SDKVersion)
{
    printf("Direct3DCreate8\n");

    //get real D3D8
    auto realCreate = GetProcAddress(realD3D8Dll, "Direct3DCreate8");

    IDirect3D8* d3d8 = (*(IDirect3D8*(__stdcall*)(UINT))realCreate)(SDKVersion);

    try
    {
        //Swap CreateDevice (virtual #15) with our function
        *(void**)&realCreateDevice = SwapVPtr(d3d8, 15, &MyDirect3D8_CreateDevice);
        printf("IDirect3D8::CreateDevice %p -> %p\n", realCreateDevice, &MyDirect3D8_CreateDevice);
    }
    catch(const exception& e)
    {
        printf("Couldn't replace IDirect3D8::CreateDevice with own wrapper\n%s\n", e.what());
    }

    //hack DirectSound
    IDirectSound* dsound;
    HRESULT hr = DirectSoundCreate(nullptr, &dsound, nullptr);

    if(FAILED(hr))
    {
        printf("Couldn't create DirectSound object\n");
    }

    // Create a sound buffer similar to what Freelancer is using

    WAVEFORMATEX wfex = {
        1,
        1,
        11025,
        22050,
        2,
        16,
        0
    };

    DSBUFFERDESC dsbd = {
        sizeof(DSBUFFERDESC),
        0x400C0,
        DSBSIZE_MIN,
        0,
        &wfex
    };

    IDirectSoundBuffer* dsbuf;
    hr = dsound->CreateSoundBuffer(&dsbd, &dsbuf, nullptr);

    if(FAILED(hr))
    {
        printf("Couldn't create mock DirectSound buffer\n");
    }

    try
    {
        *(void**)&realCreateBuffer = SwapVPtr(dsound, 3, &MyDirectSound_CreateSoundBuffer);
        printf("IDirectSound::CreateSoundBuffer %p -> %p\n", realCreateBuffer, &MyDirectSound_CreateSoundBuffer);
        *(void**)&realDuplicate = SwapVPtr(dsound, 5, &MyDirectSound_DuplicateSoundBuffer);
        printf("IDirectSound::DuplicateSoundBuffer %p -> %p\n", realDuplicate, &MyDirectSound_DuplicateSoundBuffer);

        *(void**)&realRelease_buf = SwapVPtr(dsbuf, 2, &MyDirectSoundBuffer_Release);
        printf("IDirectSoundBuffer::Release %p -> %p\n", realRelease_buf, &MyDirectSoundBuffer_Release);
        *(void**)&realLock = SwapVPtr(dsbuf, 11, &MyDirectSoundBuffer_Lock);
        printf("IDirectSoundBuffer::Lock %p->%p\n", realLock, &MyDirectSoundBuffer_Lock);
        *(void**)&realPlay = SwapVPtr(dsbuf, 12, &MyDirectSoundBuffer_Play);
        printf("IDirectSoundBuffer::Play %p->%p\n", realPlay, &MyDirectSoundBuffer_Play);
        *(void**)&realUnlock = SwapVPtr(dsbuf, 19, &MyDirectSoundBuffer_Unlock);
        printf("IDirectSoundBuffer::Unlock %p->%p\n", realUnlock, &MyDirectSoundBuffer_Unlock);
    }
    catch(const exception& e)
    {
        printf("Couldn't replace IDirectSoundBuffer functions with own wrappers\n%s\n", e.what());
    }

    (*realRelease_buf)(dsbuf);
    dsound->Release();

    return d3d8;
}