Update of /cvsroot/pywin32/pywin32/com/win32comext/directsound/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4072/com/win32comext/directsound/src
Modified Files:
PyIDirectSound.cpp PyIDirectSoundBuffer.cpp directsound.cpp
directsound_pch.h
Added Files:
PyDSCBCAPS.cpp PyDSCBUFFERDESC.cpp PyDSCCAPS.cpp
PyIDirectSoundCapture.cpp PyIDirectSoundCapture.h
PyIDirectSoundCaptureBuffer.cpp PyIDirectSoundCaptureBuffer.h
Log Message:
Added IDirectSoundCapture, IDirectSoundCaptureBuffer, related structures and functions.
Basic regression are included.
--- NEW FILE: PyIDirectSoundCapture.h ---
// This file declares the IDirectSound Interface for Python.
// ---------------------------------------------------
//
// Interface Declaration
class PyIDirectSoundCapture : public PyIUnknown
{
public:
MAKE_PYCOM_CTOR(PyIDirectSoundCapture);
static IDirectSoundCapture *GetI(PyObject *self);
static PyComTypeObject type;
static PyObject *QueryInterface(PyObject *self, PyObject *args);
// The Python methods
static PyObject *Initialize(PyObject *self, PyObject *args);
static PyObject *CreateCaptureBuffer(PyObject *self, PyObject *args);
static PyObject *GetCaps(PyObject *self, PyObject *args);
PyIDirectSoundCapture(IUnknown *pdisp);
~PyIDirectSoundCapture();
PyObject *m_DS;
};
--- NEW FILE: PyIDirectSoundCaptureBuffer.cpp ---
// This file implements the IDirectSound Interface for Python.
#include "directsound_pch.h"
#include "PySoundObjects.h"
#include "PyIDirectSoundCaptureBuffer.h"
#include "PyIDirectSoundNotify.h"
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
//
// Interface Implementation
PyIDirectSoundCaptureBuffer::PyIDirectSoundCaptureBuffer(IUnknown *pdisp):
PyIUnknown(pdisp), m_DS(NULL)
{
ob_type = &type;
}
PyIDirectSoundCaptureBuffer::~PyIDirectSoundCaptureBuffer()
{
// Release should be called before IDirectSound::Release, which may be
// triggered below
SafeRelease(this);
// This may trigger IDirectSound::Release
if (m_DS)
Py_DECREF(m_DS);
}
/* static */ IDirectSoundCaptureBuffer *PyIDirectSoundCaptureBuffer::GetI(PyObject *self)
{
return (IDirectSoundCaptureBuffer*)PyIUnknown::GetI(self);
}
/* static */ PyObject *PyIDirectSoundCaptureBuffer::QueryInterface(PyObject *self, PyObject *args)
{
PyObject *obiid;
PyObject *obUseIID = NULL;
if (!PyArg_ParseTuple(args, "O|O:QueryInterface", &obiid, &obUseIID ))
return NULL;
PyObject *rc = PyIUnknown::QueryInterface(self, args);
// Special treatment for PyIDirectSoundNotify
// This is a workaround for a reference counting bug in IDirectSound:
// If IDirectSound::Release() is called before IDirectSoundCaptureBuffer::Release()
// or IDirectSoundNotify::Release(), we will get an Access Violation
// We work around this by manipulating the reference count on the Python objects
// that encapsulate them
if (PyIBase::is_object(rc, &PyIDirectSoundNotify::type))
{
PyIDirectSoundNotify *notify = (PyIDirectSoundNotify*)rc;
PyIDirectSoundCaptureBuffer *me = (PyIDirectSoundCaptureBuffer*)self;
Py_INCREF(me->m_DS);
notify->m_DS = me->m_DS;
}
return rc;
}
// @pymethod |PyIDirectSoundCaptureBuffer|GetCaps|Returns the capabilities of the DirectSound Capture Buffer.
PyObject *PyIDirectSoundCaptureBuffer::GetCaps(PyObject *self, PyObject *args)
{
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetCaps") )
return NULL;
HRESULT hr;
PyDSCBCAPS *caps = new PyDSCBCAPS();
PY_INTERFACE_PRECALL;
hr = pIDSCB->GetCaps(caps->GetCAPS());
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCaps", hr);
return NULL;
}
Py_INCREF(caps);
return caps;
}
// @pymethod |PyIDirectSoundCaptureBuffer|GetFormat|Retrieves the current format of the sound capture buffer as a WAVEFORMATEX object.
PyObject *PyIDirectSoundCaptureBuffer::GetFormat(PyObject *self, PyObject *args)
{
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetFormat") )
return NULL;
HRESULT hr;
PyWAVEFORMATEX *wfx = new PyWAVEFORMATEX();
PY_INTERFACE_PRECALL;
// We don't support getting more than standard wave headers
hr = pIDSCB->GetFormat(&wfx->m_wfx, sizeof(WAVEFORMATEX), NULL);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetFormat", hr);
return NULL;
}
Py_INCREF(wfx);
return wfx;
}
// @pymethod |PyIDirectSoundCaptureBuffer|GetStatus|Retrieves the current status of the sound capture buffer.
PyObject *PyIDirectSoundCaptureBuffer::GetStatus(PyObject *self, PyObject *args)
{
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetStatus") )
return NULL;
HRESULT hr;
DWORD dwStatus;
PY_INTERFACE_PRECALL;
hr = pIDSCB->GetStatus(&dwStatus);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetStatus", hr);
return NULL;
}
return PyInt_FromLong(dwStatus);
}
// @pymethod |PyIDirectSoundCaptureBuffer|Initialize|Not normally used. Used IDirectSoundCapture.CreateCaptureBuffer instead.
PyObject *PyIDirectSoundCaptureBuffer::Initialize(PyObject *self, PyObject *args)
{
PyObject *obDSCBD = NULL;
PyObject *obDSC = NULL;
IDirectSoundCapture *pIDSC = NULL;
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "OO:Initialize", &obDSC, &obDSCBD) )
return NULL;
// Todo - check and initialize pIDS
if (!PyDSCBUFFERDESC_Check(obDSCBD)) {
PyErr_SetString(PyExc_TypeError, "Argument 2 must be of type DSCBUFFERDESC");
return NULL;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSCB->Initialize(pIDSC, &((PyDSCBUFFERDESC*)obDSCBD)->m_dscbd);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Initialize", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundCaptureBuffer|GetCurrentPosition|Returns a tuple of the current capture and read position in the buffer. The capture position is ahead of the read position. These positions are not always identical due to possible buffering of captured data either on the physical device or in the host. The data after the read position up to and including the capture position is not necessarily valid data.
PyObject *PyIDirectSoundCaptureBuffer::GetCurrentPosition(PyObject *self, PyObject *args)
{
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetCurrentPosition") )
return NULL;
HRESULT hr;
DWORD dwCapture = 0, dwRead = 0;
PY_INTERFACE_PRECALL;
hr = pIDSCB->GetCurrentPosition(&dwCapture, &dwRead);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCurrentPosition", hr);
return NULL;
}
PyObject *result = PyTuple_New(2);
if (!result)
return NULL;
PyTuple_SetItem(result, 0, PyInt_FromLong(dwCapture));
PyTuple_SetItem(result, 1, PyInt_FromLong(dwRead));
return result;
}
// @pymethod |PyIDirectSoundCaptureBuffer|Start|The PyIDirectSoundCaptureBuffer::Start method puts the capture buffer into the capture state and begins capturing data into the buffer. If the capture buffer is already in the capture state then the method has no effect.
PyObject *PyIDirectSoundCaptureBuffer::Start(PyObject *self, PyObject *args)
{
// @pyparm int|dwFlags|0|Flags that specify the behavior for the capture buffer when capturing sound data. Possible values for dwFlags can be one of the following:
// DSCBSTART_LOOPING
DWORD dwFlags;
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "i:Start", &dwFlags) )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSCB->Start(dwFlags);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Start", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundCaptureBuffer|Stop|The IDirectSoundCaptureBuffer::Stop method puts the capture buffer into the "stop" state and stops capturing data. If the capture buffer is already in the stop state then the method has no effect.
PyObject *PyIDirectSoundCaptureBuffer::Stop(PyObject *self, PyObject *args)
{
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":Stop") )
return NULL;
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSCB->Stop();
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Stop", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundCaptureBuffer|Update|Retrieve data from the capture buffer.
PyObject *PyIDirectSoundCaptureBuffer::Update(PyObject *self, PyObject *args)
{
// @pyparm int|dwReadCursor||Offset, in bytes, from the start of the buffer to where the update begins.
// @pyparm int|dwReadBytes||Size, in bytes, of the portion of the buffer to update.
// @pyparm int|dwFlags|0|Flags modifying the update event. This value can be 0 or the following flag: DSCBLOCK_ENTIREBUFFER
// The dwReadBytes parameter is to be ignored and the entire capture buffer is to be locked.
DWORD dwReadCursor = 0;
DWORD dwReadBytes = 0;
DWORD dwFlags = 0;
IDirectSoundCaptureBuffer *pIDSCB = GetI(self);
if ( pIDSCB == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "ii|i:Update", &dwReadCursor, &dwReadBytes, &dwFlags) )
return NULL;
HRESULT hr;
LPVOID lpAudioPtr1 = NULL;
DWORD dwAudioBytes1 = 0;
LPVOID lpAudioPtr2 = NULL;
DWORD dwAudioBytes2 = 0;
PY_INTERFACE_PRECALL;
hr = pIDSCB->Lock(dwReadCursor, dwReadBytes, &lpAudioPtr1, &dwAudioBytes1,
&lpAudioPtr2, &dwAudioBytes2, dwFlags);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Update(Lock)", hr);
return NULL;
}
// The capture buffer is circular, so we may get two pointers and have to
// do the wrap-around ourselves.
PyObject *obData = PyString_FromStringAndSize((char*)lpAudioPtr1, dwAudioBytes1);
if (!obData)
{
PyErr_SetString(PyExc_MemoryError, "Update: could not allocate result string");
goto error;
}
if (lpAudioPtr2)
{
PyObject *obData2 = PyString_FromStringAndSize((char*)lpAudioPtr2, dwAudioBytes2);
PyString_Concat(&obData, obData2);
if (!obData)
{
PyErr_SetString(PyExc_MemoryError, "Update: could not append to result string");
goto error;
}
}
{
// need extra block for local variables from PY_INTERFACE_UPCALL macro
PY_INTERFACE_PRECALL;
hr = pIDSCB->Unlock(lpAudioPtr1, dwAudioBytes1, lpAudioPtr2, dwAudioBytes2);
PY_INTERFACE_POSTCALL;
}
if (FAILED(hr)) {
Py_DECREF(obData);
PyWin_SetAPIError("Update(Unlock)", hr);
return NULL;
}
return obData;
error:
{
// need extra block for local variables from PY_INTERFACE_UPCALL macro
PY_INTERFACE_PRECALL;
hr = pIDSCB->Unlock(lpAudioPtr1, dwAudioBytes1, lpAudioPtr2, dwAudioBytes2);
PY_INTERFACE_POSTCALL;
}
return NULL;
}
// @object PyIDirectSoundCaptureBuffer|The methods of the IDirectSoundCaptureBuffer interface are used to manipulate sound capture buffers.
static struct PyMethodDef PyIDirectSoundCaptureBuffer_methods[] =
{
{ "QueryInterface", PyIDirectSoundCaptureBuffer::QueryInterface, 1 },
{ "GetCaps", PyIDirectSoundCaptureBuffer::GetCaps, 1 }, // @pymeth Initialize|Description of GetCaps.
{ "GetFormat", PyIDirectSoundCaptureBuffer::GetFormat, 1 }, // @pymeth SetCooperativeLevel|Description of GetFormat.
{ "GetStatus", PyIDirectSoundCaptureBuffer::GetStatus, 1 }, // @pymeth GetStatus|Description of GetStatus.
{ "Initialize", PyIDirectSoundCaptureBuffer::Initialize, 1 }, // @pymeth Initialize|Description of Initialize.
{ "GetCurrentPosition", PyIDirectSoundCaptureBuffer::GetCurrentPosition, 1 }, // @pymeth GetCurrentPosition|Description of GetCaps.
{ "Start", PyIDirectSoundCaptureBuffer::Start, 1 }, // @pymeth Play|Description of Start.
{ "Stop", PyIDirectSoundCaptureBuffer::Stop, 1 }, // @pymeth Stop|Description of Stop.
{ "Update", PyIDirectSoundCaptureBuffer::Update, 1 }, // @pymeth Unlock|Description of Update.
{ NULL }
};
PyComTypeObject PyIDirectSoundCaptureBuffer::type("PyIDirectSoundCaptureBuffer",
&PyIUnknown::type,
sizeof(PyIDirectSoundCaptureBuffer),
PyIDirectSoundCaptureBuffer_methods,
GET_PYCOM_CTOR(PyIDirectSoundCaptureBuffer));
Index: PyIDirectSound.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/directsound/src/PyIDirectSound.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PyIDirectSound.cpp 6 Dec 2004 20:09:41 -0000 1.2
--- PyIDirectSound.cpp 7 Mar 2005 22:18:45 -0000 1.3
***************
*** 118,130 ****
if ( pIDS == NULL )
return NULL;
! if ( !PyArg_ParseTuple(args, "O|O:CreateSoundBuffer", &obDSBD, &obUnk) )
return NULL;
if (!PyDSBUFFERDESC_Check(obDSBD)) {
! PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type PyDSBUFFERDESC");
return NULL;
}
! if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnkIn, TRUE)) {
return NULL;
}
--- 118,132 ----
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;
}
Index: PyIDirectSoundBuffer.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/directsound/src/PyIDirectSoundBuffer.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** PyIDirectSoundBuffer.cpp 2 Dec 2004 09:48:36 -0000 1.4
--- PyIDirectSoundBuffer.cpp 7 Mar 2005 22:18:45 -0000 1.5
***************
*** 62,66 ****
}
! // @pymethod |PyIDirectSoundBuffer|GetCaps|Description of GetCaps.
PyObject *PyIDirectSoundBuffer::GetCaps(PyObject *self, PyObject *args)
{
--- 62,66 ----
}
! // @pymethod |PyIDirectSoundBuffer|GetCaps|Retrieves the capabilities of the DirectSoundBuffer object as a DSBCAPS object.
PyObject *PyIDirectSoundBuffer::GetCaps(PyObject *self, PyObject *args)
{
***************
*** 90,100 ****
PyObject *PyIDirectSoundBuffer::GetFormat(PyObject *self, PyObject *args)
{
- int level;
- HWND hwnd;
-
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
! if ( !PyArg_ParseTuple(args, ":GetFormat", &hwnd, &level) )
return NULL;
--- 90,97 ----
PyObject *PyIDirectSoundBuffer::GetFormat(PyObject *self, PyObject *args)
{
IDirectSoundBuffer *pIDSB = GetI(self);
if ( pIDSB == NULL )
return NULL;
! if ( !PyArg_ParseTuple(args, ":GetFormat") )
return NULL;
***************
*** 117,121 ****
}
! // @pymethod |PyIDirectSoundBuffer|GetStatus|Description of GetStatus.
PyObject *PyIDirectSoundBuffer::GetStatus(PyObject *self, PyObject *args)
{
--- 114,118 ----
}
! // @pymethod |PyIDirectSoundBuffer|GetStatus|Retrieves the current status of the sound buffer.
PyObject *PyIDirectSoundBuffer::GetStatus(PyObject *self, PyObject *args)
{
***************
*** 141,147 ****
}
! // @pymethod |PyIDirectSoundBuffer|SetFormat|Description of SetFormat.
PyObject *PyIDirectSoundBuffer::SetFormat(PyObject *self, PyObject *args)
{
PyObject *obWfx;
IDirectSoundBuffer *pIDSB = GetI(self);
--- 138,146 ----
}
! // @pymethod |PyIDirectSoundBuffer|SetFormat|Sets the format of the primary sound buffer for the application. Whenever this application has the input focus, DirectSound will set the primary buffer to the specified format.
PyObject *PyIDirectSoundBuffer::SetFormat(PyObject *self, PyObject *args)
{
+ // @pyparm WAVEFORMATEX|format||A WAVEFORMATEX object that describes the new format for the primary sound buffer.
+
PyObject *obWfx;
IDirectSoundBuffer *pIDSB = GetI(self);
***************
*** 152,156 ****
if (!PyWAVEFORMATEX_Check(obWfx)) {
! PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type PyWAVEFORMATEX");
return NULL;
}
--- 151,155 ----
if (!PyWAVEFORMATEX_Check(obWfx)) {
! PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type WAVEFORMATEX");
return NULL;
}
***************
*** 187,191 ****
if (!PyDSBUFFERDESC_Check(obDSBD)) {
! PyErr_SetString(PyExc_TypeError, "Argument 2 must be of type PyDSBUFFERDESC");
return NULL;
}
--- 186,190 ----
if (!PyDSBUFFERDESC_Check(obDSBD)) {
! PyErr_SetString(PyExc_TypeError, "Argument 2 must be of type DSBUFFERDESC");
return NULL;
}
***************
*** 206,210 ****
}
! // @pymethod |PyIDirectSoundBuffer|Restore|Description of Initialize.
PyObject *PyIDirectSoundBuffer::Restore(PyObject *self, PyObject *args)
{
--- 205,209 ----
}
! // @pymethod |PyIDirectSoundBuffer|Restore|Restores the memory allocation for a lost sound buffer for the specified DirectSoundBuffer object.
PyObject *PyIDirectSoundBuffer::Restore(PyObject *self, PyObject *args)
{
--- NEW FILE: PyDSCCAPS.cpp ---
//
// @doc
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "PySoundObjects.h"
#include "structmember.h"
#include "directsound_pch.h"
// @pymethod <o PyDSCCAPS>|pywintypes|DSCCAPS|Creates a new DSCCAPS object
PyObject *PyWinMethod_NewDSCCAPS(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":DSCCAPS"))
return NULL;
return new PyDSCCAPS();
}
PyObject *PyWinObject_FromDSCCAPS(const DSCCAPS &caps)
{
return new PyDSCCAPS(caps);
}
BOOL PyWinObject_AsDSCCAPS(PyObject *ob, DSCCAPS **ppDSCCAPS, BOOL bNoneOK /*= TRUE*/)
{
if (bNoneOK && ob==Py_None) {
*ppDSCCAPS = NULL;
} else if (!PyDSCCAPS_Check(ob)) {
PyErr_SetString(PyExc_TypeError, "The object is not a PyDSCCAPS object");
return FALSE;
} else {
PyDSCCAPS *pycaps= (PyDSCCAPS *)ob;
*ppDSCCAPS = pycaps->GetCAPS();
}
return TRUE;
}
// @object PyDSCCAPS|A Python object, representing a DSCCAPS structure
static struct PyMethodDef PyDSCCAPS_methods[] = {
{NULL}
};
PyTypeObject PyDSCCAPSType =
{
PyObject_HEAD_INIT(&PyType_Type)
0,
"PyDSCCAPSType",
sizeof(PyDSCCAPSType),
0,
PyDSCCAPS::deallocFunc,
0, // tp_print;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0,
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr,
PyObject_GenericSetAttr,
0, // tp_as_buffer;
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags;
0, // tp_doc; /* Documentation string */
0, // traverseproc tp_traverse;
0, // tp_clear;
0, // tp_richcompare;
0, // tp_weaklistoffset;
0, // tp_iter
0, // iternextfunc tp_iternext
0, // methods
PyDSCCAPS::members,
0, // tp_getset;
0, // tp_base;
0, // tp_dict;
0, // tp_descr_get;
0, // tp_descr_set;
0, // tp_dictoffset;
0, // tp_init;
0, // tp_alloc;
0 // newfunc tp_new;
};
#define OFF(e) offsetof(PyDSCCAPS, e)
/*static*/ struct PyMemberDef PyDSCCAPS::members[] = {
{"dwFlags", T_INT, OFF(m_caps.dwFlags), 0, "Specifies device capabilities. Can be 0 or DSCCAPS_EMULDRIVER (indicates that no DirectSoundCapture device is available and standard wave audio functions are being used)"},
// @prop integer|dwFlags|Specifies device capabilities. Can be 0 or DSCCAPS_EMULDRIVER (indicates that no DirectSound Device is available and standard wave audio functions are being used).
{"dwFormats", T_INT, OFF(m_caps.dwFormats), 0, "Supported WAVE_FORMAT formats."},
// @prop integer|dwFormats|Supported WAVE_FORMAT formats.
{"dwChannels", T_INT, OFF(m_caps.dwChannels), 0, "Number of channels supported by the device."},
// @prop integer|dwChannels|Number of channels supported by the device.
{NULL}
};
PyDSCCAPS::PyDSCCAPS(void)
{
ob_type = &PyDSCCAPSType;
_Py_NewReference(this);
memset(&m_caps, 0, sizeof(m_caps));
}
PyDSCCAPS::PyDSCCAPS(const DSCCAPS &caps)
{
ob_type = &PyDSCCAPSType;
_Py_NewReference(this);
m_caps = caps;
m_caps.dwSize = sizeof(DSCCAPS);
}
PyDSCCAPS::~PyDSCCAPS()
{
}
/*static*/ void PyDSCCAPS::deallocFunc(PyObject *ob)
{
delete (PyDSCCAPS *)ob;
}
--- NEW FILE: PyIDirectSoundCaptureBuffer.h ---
// This file declares the IDirectSoundCaptureBuffer Interface for Python.
// ---------------------------------------------------
//
// Interface Declaration
class PyIDirectSoundCaptureBuffer : public PyIUnknown
{
public:
MAKE_PYCOM_CTOR(PyIDirectSoundCaptureBuffer);
static IDirectSoundCaptureBuffer *GetI(PyObject *self);
static PyComTypeObject type;
static PyObject *QueryInterface(PyObject *self, PyObject *args);
// The Python methods
// Information methods
static PyObject *GetCaps(PyObject *self, PyObject *args);
static PyObject *GetFormat(PyObject *self, PyObject *args);
static PyObject *GetStatus(PyObject *self, PyObject *args);
static PyObject *GetCurrentPosition(PyObject *self, PyObject *args);
// Memory management
static PyObject *Initialize(PyObject *self, PyObject *args);
// Capture management
static PyObject *Start(PyObject *self, PyObject *args);
static PyObject *Stop(PyObject *self, PyObject *args);
static PyObject *Update(PyObject *self, PyObject *args);
PyIDirectSoundCaptureBuffer(IUnknown *pdisp);
~PyIDirectSoundCaptureBuffer();
PyObject *m_DS;
};
Index: directsound.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/directsound/src/directsound.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** directsound.cpp 6 Dec 2004 20:09:41 -0000 1.4
--- directsound.cpp 7 Mar 2005 22:18:45 -0000 1.5
***************
*** 19,23 ****
#include "PyIDirectSoundBuffer.h"
#include "PyIDirectSoundNotify.h"
!
// @pymethod <o PyIUnknown>|directsound|DirectSoundCreate|Creates and initializes a new object that supports the IDirectSound interface.
--- 19,24 ----
#include "PyIDirectSoundBuffer.h"
#include "PyIDirectSoundNotify.h"
! #include "PyIDirectSoundCapture.h"
! #include "PyIDirectSoundCaptureBuffer.h"
// @pymethod <o PyIUnknown>|directsound|DirectSoundCreate|Creates and initializes a new object that supports the IDirectSound interface.
***************
*** 126,133 ****
--- 127,216 ----
if (PyErr_Occurred())
{
+ Py_DECREF(list);
return NULL;
}
if (FAILED(hr)) {
+ Py_DECREF(list);
+ PyCom_BuildPyException(hr);
+ return NULL;
+ }
+
+ return list;
+ }
+
+ // @pymethod <o PyIUnknown>|directsound|DirectSoundCaptureCreate|Creates and initializes a new object that supports the IDirectSoundCapture interface.
+ static PyObject *directsound_DirectSoundCaptureCreate(PyObject *, PyObject *args)
+ {
+ PyObject *ret = NULL;
+ PyObject *obGUID = NULL, *obUnk = NULL;
+ IUnknown *pUnkIn = NULL;
+ GUID guid, *pguid = NULL;
+ LPDIRECTSOUNDCAPTURE dsc;
+ HRESULT hr;
+
+ if (!PyArg_ParseTuple(args, "|OO:DirectSoundCaptureCreate",
+ &obGUID, // @pyparm <o PyIID>|guid|None|Address of the GUID that identifies the sound device. The value of this parameter must be one of the GUIDs returned by DirectSoundCaptureEnumerate, or None for the default device.
+ &obUnk)) // @pyparm <o PyIUknown>|unk|None|The IUnknown for COM aggregation.
+ {
+ return NULL;
+ }
+
+ if (obUnk)
+ {
+ if (!PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnkIn, TRUE))
+ goto done;
+ }
+
+ if (obGUID && obGUID != Py_None)
+ {
+ if (!PyWinObject_AsIID(obGUID, &guid))
+ goto done;
+
+ pguid = &guid;
+ }
+
+ Py_BEGIN_ALLOW_THREADS
+ hr = ::DirectSoundCaptureCreate(pguid, &dsc, pUnkIn);
+ Py_END_ALLOW_THREADS
+ if (FAILED(hr)) {
+ PyCom_BuildPyException(hr);
+ goto done;
+ }
+ ret = new PyIDirectSoundCapture(dsc);
+ done:
+ if (pUnkIn)
+ pUnkIn->Release();
+
+ return ret;
+ }
+
+ // @pymethod <o list>|directsound|DirectSoundCaptureEnumerate|Enumerates DirectSoundCapture drivers installed in the system.
+ static PyObject *directsound_DirectSoundCaptureEnumerate(PyObject *, PyObject *args)
+ {
+ if (!PyArg_ParseTuple(args, ":DirectSoundCaptureEnumerate"))
+ {
+ return NULL;
+ }
+
+ PyObject *list = PyList_New(0);
+ if (!list)
+ {
+ return NULL;
+ }
+
+ HRESULT hr;
+ Py_BEGIN_ALLOW_THREADS
+ hr = ::DirectSoundCaptureEnumerate(dsEnumCallback, list);
+ Py_END_ALLOW_THREADS
+
+ if (PyErr_Occurred())
+ {
+ Py_DECREF(list);
+ return NULL;
+ }
+
+ if (FAILED(hr)) {
+ Py_DECREF(list);
PyCom_BuildPyException(hr);
return NULL;
***************
*** 143,152 ****
{ "DirectSoundCreate", directsound_DirectSoundCreate, 1 }, // @pymeth DirectSoundCreate|Creates and initializes a new object that supports the IDirectSound interface.
{ "DirectSoundEnumerate", directsound_DirectSoundEnumerate, 1 }, // @pymeth DirectSoundEnumerate|The DirectSoundEnumerate function enumerates the DirectSound drivers installed in the system.
!
! // { "DirectSoundCaptureCreate", directsound_DirectSoundCaptureCreate, 1}, // @pymeth DirectSoundCaptureCreate|The DirectSoundCaptureCreate function creates and initializes an object that supports the IDirectSoundCapture interface.
! // { "DirectSoundCaptureEnumerate", directsound_DirectSoundCaptureEnumerate, 1}, // @pymeth DirectSoundCaptureEnumerate|The DirectSoundCaptureEnumerate function enumerates the DirectSoundCapture objects installed in the system.
{"DSCAPS", PyWinMethod_NewDSCAPS, 1 }, // @pymeth DSCAPS|Creates a new <o PyDSCAPS> object.
{"DSBCAPS", PyWinMethod_NewDSBCAPS, 1 }, // @pymeth DSBCAPS|Creates a new <o PyDSBCAPS> object.
{"DSBUFFERDESC", PyWinMethod_NewDSBUFFERDESC, 1 }, // @pymeth DSBUFFERDESC|Creates a new <o PyDSBUFFERDESC> object.
{ NULL, NULL },
};
--- 226,237 ----
{ "DirectSoundCreate", directsound_DirectSoundCreate, 1 }, // @pymeth DirectSoundCreate|Creates and initializes a new object that supports the IDirectSound interface.
{ "DirectSoundEnumerate", directsound_DirectSoundEnumerate, 1 }, // @pymeth DirectSoundEnumerate|The DirectSoundEnumerate function enumerates the DirectSound drivers installed in the system.
! { "DirectSoundCaptureCreate", directsound_DirectSoundCaptureCreate, 1}, // @pymeth DirectSoundCaptureCreate|The DirectSoundCaptureCreate function creates and initializes an object that supports the IDirectSoundCapture interface.
! { "DirectSoundCaptureEnumerate", directsound_DirectSoundCaptureEnumerate, 1}, // @pymeth DirectSoundCaptureEnumerate|The DirectSoundCaptureEnumerate function enumerates the DirectSoundCapture objects installed in the system.
{"DSCAPS", PyWinMethod_NewDSCAPS, 1 }, // @pymeth DSCAPS|Creates a new <o PyDSCAPS> object.
{"DSBCAPS", PyWinMethod_NewDSBCAPS, 1 }, // @pymeth DSBCAPS|Creates a new <o PyDSBCAPS> object.
+ {"DSCCAPS", PyWinMethod_NewDSCCAPS, 1 }, // @pymeth DSCCAPS|Creates a new <o PyDSCCAPS> object.
+ {"DSCBCAPS", PyWinMethod_NewDSCBCAPS, 1 }, // @pymeth DSCBCAPS|Creates a new <o PyDSCBCAPS> object.
{"DSBUFFERDESC", PyWinMethod_NewDSBUFFERDESC, 1 }, // @pymeth DSBUFFERDESC|Creates a new <o PyDSBUFFERDESC> object.
+ {"DSCBUFFERDESC", PyWinMethod_NewDSCBUFFERDESC, 1 }, // @pymeth DSCBUFFERDESC|Creates a new <o PyDSCBUFFERDESC> object.
{ NULL, NULL },
};
***************
*** 171,174 ****
--- 256,261 ----
PYCOM_INTERFACE_CLIENT_ONLY (DirectSoundBuffer),
PYCOM_INTERFACE_CLIENT_ONLY (DirectSoundNotify),
+ PYCOM_INTERFACE_CLIENT_ONLY (DirectSoundCapture),
+ PYCOM_INTERFACE_CLIENT_ONLY (DirectSoundCaptureBuffer),
};
***************
*** 211,227 ****
ADD_CONSTANT(DSCAPS_SECONDARY8BIT);
// @const directsound|DSCAPS_SECONDARY16BIT|The device supports hardware-mixed secondary sound buffers with 16-bit samples.
! ADD_CONSTANT(DSBPLAY_LOOPING); // @const directsound|DSBPLAY_LOOPING|text.
! ADD_CONSTANT(DSBSTATUS_PLAYING);
ADD_CONSTANT(DSBSTATUS_BUFFERLOST);
ADD_CONSTANT(DSBSTATUS_LOOPING);
ADD_CONSTANT(DSBLOCK_FROMWRITECURSOR);
ADD_CONSTANT(DSBLOCK_ENTIREBUFFER);
ADD_CONSTANT(DSSCL_NORMAL);
ADD_CONSTANT(DSSCL_PRIORITY);
ADD_CONSTANT(DSSCL_EXCLUSIVE);
ADD_CONSTANT(DSSCL_WRITEPRIMARY);
ADD_CONSTANT(DS3DMODE_NORMAL);
ADD_CONSTANT(DS3DMODE_HEADRELATIVE);
ADD_CONSTANT(DS3DMODE_DISABLE);
--- 298,328 ----
ADD_CONSTANT(DSCAPS_SECONDARY8BIT);
// @const directsound|DSCAPS_SECONDARY16BIT|The device supports hardware-mixed secondary sound buffers with 16-bit samples.
+ ADD_CONSTANT(DSCAPS_SECONDARY16BIT);
! // @const directsound|DSBPLAY_LOOPING|Once the end of the audio buffer is reached, play restarts at the beginning of the buffer. Play continues until explicitly stopped. This flag must be set when playing primary sound buffers.
! ADD_CONSTANT(DSBPLAY_LOOPING);
! // @const directsound|DSBSTATUS_PLAYING|The buffer is playing. If this value is not set, the buffer is stopped.
! ADD_CONSTANT(DSBSTATUS_PLAYING);
! // @const directsound|DSBSTATUS_BUFFERLOST|The buffer is lost and must be restored before it can be played or locked.
ADD_CONSTANT(DSBSTATUS_BUFFERLOST);
+ // @const directsound|DSBSTATUS_LOOPING|The buffer is being looped. If this value is not set, the buffer will stop when it reaches the end of the sound data. Note that if this value is set, the buffer must also be playing.
ADD_CONSTANT(DSBSTATUS_LOOPING);
+ // @const directsound|DSBLOCK_FROMWRITECURSOR|Locks from the current write cursor, making a call to DirectSoundBuffer.getCurrentPosition unnecessary. If this flag is specified, the start parameter is ignored. This flag is optional.
ADD_CONSTANT(DSBLOCK_FROMWRITECURSOR);
+ // @const directsound|DSBLOCK_ENTIREBUFFER|Unknown.
ADD_CONSTANT(DSBLOCK_ENTIREBUFFER);
+ // @const directsound|DSSCL_NORMAL|Sets the application to a fully cooperative status. Most applications should use this level, because it has the smoothest multitasking and resource-sharing behavior.
ADD_CONSTANT(DSSCL_NORMAL);
+ // @const directsound|DSSCL_PRIORITY|Sets the application to the priority level. Applications with this cooperative level can call the DirectSoundBuffer.setFormat and DirectSound.compact methods.
ADD_CONSTANT(DSSCL_PRIORITY);
+ // @const directsound|DSSCL_EXCLUSIVE|Sets the application to the exclusive level. When it has the input focus, the application will be the only one audible (sounds from applications with the DSBCAPS_GLOBALFOCUS flag set will be muted). With this level, it also has all the privileges of the DSSCL_PRIORITY level. DirectSound will restore the hardware format, as specified by the most recent call to the DirectSoundBuffer.setFormat method, once the application gains the input focus. (Note that DirectSound will always restore the wave format, no matter what priority level is set.)
ADD_CONSTANT(DSSCL_EXCLUSIVE);
+ // @const directsound|DSSCL_WRITEPRIMARY|This is the highest priority level. The application has write access to the primary sound buffers. No secondary sound buffers in any application can be played.
ADD_CONSTANT(DSSCL_WRITEPRIMARY);
+ // @const directsound|DS3DMODE_NORMAL|Normal processing. This is the default mode.
ADD_CONSTANT(DS3DMODE_NORMAL);
+ // @const directsound|DS3DMODE_HEADRELATIVE|Sound parameters (position, velocity, and orientation) are relative to the listener's parameters. In this mode, the absolute parameters of the sound are updated automatically as the listener's parameters change, so that the relative parameters remain constant.
ADD_CONSTANT(DS3DMODE_HEADRELATIVE);
+ // @const directsound|DS3DMODE_DISABLE|Processing of 3D sound is disabled. The sound seems to originate from the center of the listener's head.
ADD_CONSTANT(DS3DMODE_DISABLE);
***************
*** 289,292 ****
--- 390,394 ----
ADD_CONSTANT(DSBSIZE_MIN);
ADD_CONSTANT(DSBSIZE_MAX);
+ // @const directsound|DSCCAPS_EMULDRIVER|The device does not have a DirectSound driver installed, so it is being emulated through the waveform-audio functions. Performance degradation should be expected.
ADD_CONSTANT(DSCCAPS_EMULDRIVER);
ADD_CONSTANT(DSCBLOCK_ENTIREBUFFER);
***************
*** 299,302 ****
--- 401,407 ----
PyDict_SetItemString(dict, "DSBCAPSType", (PyObject *)&PyDSBCAPSType);
PyDict_SetItemString(dict, "DSBUFFERDESCType", (PyObject *)&PyDSBUFFERDESCType);
+ PyDict_SetItemString(dict, "DSCCAPSType", (PyObject *)&PyDSCCAPSType);
+ PyDict_SetItemString(dict, "DSCBCAPSType", (PyObject *)&PyDSCBCAPSType);
+ PyDict_SetItemString(dict, "DSCBUFFERDESCType", (PyObject *)&PyDSCBUFFERDESCType);
}
***************
*** 328,332 ****
# Play a wav file and wait until it's finished
! fname=os.path.join(os.path.dirname(__file__), "01-Intro.wav")
f = open(fname, 'rb')
--- 433,437 ----
# Play a wav file and wait until it's finished
! fname = os.path.join(os.path.dirname(__file__), "01-Intro.wav")
f = open(fname, 'rb')
Index: directsound_pch.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/directsound/src/directsound_pch.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** directsound_pch.h 30 Nov 2004 21:30:28 -0000 1.1
--- directsound_pch.h 7 Mar 2005 22:18:45 -0000 1.2
***************
*** 17,20 ****
--- 17,30 ----
/*
+ ** DSCBUFFERDESC support
+ */
+
+ PyObject *PyWinMethod_NewDSCBUFFERDESC(PyObject *self, PyObject *args);
+ PyObject *PyWinObject_FromWAVEFROMATEX(const DSCBUFFERDESC &dsbd);
+ BOOL PyWinObject_AsDSCBUFFERDESC(PyObject *ob, DSCBUFFERDESC **ppDSCBUFFERDESC, BOOL bNoneOK = TRUE);
+ extern PyTypeObject PyDSCBUFFERDESCType;
+ #define PyDSCBUFFERDESC_Check(ob) ((ob)->ob_type == &PyDSCBUFFERDESCType)
+
+ /*
** DSCAPS support
*/
***************
*** 36,39 ****
--- 46,69 ----
#define PyDSBCAPS_Check(ob) ((ob)->ob_type == &PyDSBCAPSType)
+ /*
+ ** DSCCAPS support
+ */
+
+ PyObject *PyWinMethod_NewDSCCAPS(PyObject *self, PyObject *args);
+ PyObject *PyWinObject_FromDSCCAPS(const DSBUFFERDESC &dsbd);
+ BOOL PyWinObject_AsDSCCAPS(PyObject *ob, DSCCAPS **ppDSCCAPS, BOOL bNoneOK = TRUE);
+ extern PyTypeObject PyDSCCAPSType;
+ #define PyDSCCAPS_Check(ob) ((ob)->ob_type == &PyDSCCAPSType)
+
+ /*
+ ** DSCBCAPS support
+ */
+
+ PyObject *PyWinMethod_NewDSCBCAPS(PyObject *self, PyObject *args);
+ PyObject *PyWinObject_FromDSCBCAPS(const DSBUFFERDESC &dsbd);
+ BOOL PyWinObject_AsDSCBCAPS(PyObject *ob, DSCBCAPS **ppDSCBCAPS, BOOL bNoneOK = TRUE);
+ extern PyTypeObject PyDSCBCAPSType;
+ #define PyDSCBCAPS_Check(ob) ((ob)->ob_type == &PyDSCBCAPSType)
+
class PyDSBUFFERDESC : public PyObject
***************
*** 62,65 ****
--- 92,165 ----
};
+ class PyDSCBUFFERDESC : public PyObject
+ {
+ public:
+
+ PyDSCBUFFERDESC(void);
+ PyDSCBUFFERDESC(const DSCBUFFERDESC &);
+ ~PyDSCBUFFERDESC();
+
+ /* Python support */
+ static void deallocFunc(PyObject *ob);
+
+ static int setattro(PyObject *self, PyObject *obname, PyObject *obvalue);
+
+ PyObject *m_obWFX;
+
+ #ifdef _MSC_VER
+ #pragma warning( disable : 4251 )
+ #endif // _MSC_VER
+ static struct PyMemberDef members[];
+ #ifdef _MSC_VER
+ #pragma warning( default : 4251 )
+ #endif // _MSC_VER
+ DSCBUFFERDESC m_dscbd;
+ };
+
+ class PyDSCCAPS : public PyObject
+ {
+ public:
+
+ DSCCAPS *GetCAPS() {return &m_caps;}
+
+ PyDSCCAPS(void);
+ PyDSCCAPS(const DSCCAPS &);
+ ~PyDSCCAPS();
+
+ /* Python support */
+ static void deallocFunc(PyObject *ob);
+
+ #ifdef _MSC_VER
+ #pragma warning( disable : 4251 )
+ #endif // _MSC_VER
+ static struct PyMemberDef members[];
+ #ifdef _MSC_VER
+ #pragma warning( default : 4251 )
+ #endif // _MSC_VER
+ DSCCAPS m_caps;
+ };
+
+ class PyDSCBCAPS : public PyObject
+ {
+ public:
+
+ DSCBCAPS *GetCAPS() {return &m_caps;}
+
+ PyDSCBCAPS(void);
+ PyDSCBCAPS(const DSCBCAPS &);
+ ~PyDSCBCAPS();
+
+ /* Python support */
+ static void deallocFunc(PyObject *ob);
+
+ #ifdef _MSC_VER
+ #pragma warning( disable : 4251 )
+ #endif // _MSC_VER
+ static struct PyMemberDef members[];
+ #ifdef _MSC_VER
+ #pragma warning( default : 4251 )
+ #endif // _MSC_VER
+ DSCBCAPS m_caps;
+ };
class PyDSCAPS : public PyObject
--- NEW FILE: PyIDirectSoundCapture.cpp ---
// This file implements the IDirectSoundCapture Interface for Python.
#include "directsound_pch.h"
#include "PySoundObjects.h"
#include "PyIDirectSoundCapture.h"
#include "PyIDirectSoundCaptureBuffer.h"
#include "PyIDirectSoundNotify.h"
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
//
// Interface Implementation
PyIDirectSoundCapture::PyIDirectSoundCapture(IUnknown *pdisp):
PyIUnknown(pdisp), m_DS(NULL)
{
ob_type = &type;
}
PyIDirectSoundCapture::~PyIDirectSoundCapture()
{
// Release should be called before IDirectSound::Release, which may be
// triggered below
SafeRelease(this);
// This may trigger IDirectSound::Release
if (m_DS)
Py_DECREF(m_DS);
}
/* static */ IDirectSoundCapture *PyIDirectSoundCapture::GetI(PyObject *self)
{
return (IDirectSoundCapture*)PyIUnknown::GetI(self);
}
/* static */ PyObject *PyIDirectSoundCapture::QueryInterface(PyObject *self, PyObject *args)
{
PyObject *obiid;
PyObject *obUseIID = NULL;
if (!PyArg_ParseTuple(args, "O|O:QueryInterface", &obiid, &obUseIID ))
return NULL;
PyObject *rc = PyIUnknown::QueryInterface(self, args);
// Special treatment for PyIDirectSoundNotify
// This is a workaround for a reference counting bug in IDirectSound:
// If IDirectSound::Release() is called before IDirectSoundCapture::Release()
// or IDirectSoundNotify::Release(), we will get an Access Violation
// We work around this by manipulating the reference count on the Python objects
// that encapsulate them
if (PyIBase::is_object(rc, &PyIDirectSoundNotify::type))
{
PyIDirectSoundNotify *notify = (PyIDirectSoundNotify*)rc;
PyIDirectSoundCapture *me = (PyIDirectSoundCapture*)self;
Py_INCREF(me->m_DS);
notify->m_DS = me->m_DS;
}
return rc;
}
// @pymethod |PyIDirectSoundCapture|Initialize|Not normally called directly. Use DirectSoundCaptureCreate instead.
PyObject *PyIDirectSoundCapture::Initialize(PyObject *self, PyObject *args)
{
PyObject *obGUID;
IDirectSoundCapture *pIDSC = GetI(self);
if ( pIDSC == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "|O:Initialize", &obGUID) )
return NULL;
GUID guid;
LPGUID pguid = NULL;
if (!obGUID && obGUID != Py_None)
{
if (!PyWinObject_AsIID(obGUID, &guid))
return NULL;
pguid = &guid;
}
HRESULT hr;
PY_INTERFACE_PRECALL;
hr = pIDSC->Initialize(pguid);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("Initialize", hr);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
// @pymethod |PyIDirectSoundCapture|CreateCaptureBuffer|The IDirectSoundCapture::CreateSoundBuffer method creates a DirectSoundBuffer object to hold a sequence of audio samples.
PyObject *PyIDirectSoundCapture::CreateCaptureBuffer(PyObject *self, PyObject *args)
{
PyObject *obDSCBD = NULL;
PyObject *obUnk = NULL;
IUnknown *pUnkIn = NULL;
IDirectSoundCapture *pIDSC = GetI(self);
if ( pIDSC == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, "O|O:CreateCaptureBuffer",
&obDSCBD, // @pyparm <o PyDSCBUFFERDESC>|lpDSCBufferDesc||a DSCBUFFERDESC structure containing values for the capture buffer being created.
&obUnk) ) // @pyparm <o PyIUknown>|unk|None|The IUnknown for COM aggregation.
return NULL;
if (!PyDSCBUFFERDESC_Check(obDSCBD)) {
PyErr_SetString(PyExc_TypeError, "Argument 1 must be of type DSCBUFFERDESC");
return NULL;
}
if (obUnk && !PyCom_InterfaceFromPyInstanceOrObject(obUnk, IID_IUnknown, (void **)&pUnkIn, TRUE)) {
return NULL;
}
DSCBUFFERDESC *pdscbd = &((PyDSCBUFFERDESC*)obDSCBD)->m_dscbd;
HRESULT hr;
IDirectSoundCaptureBuffer *buffer;
PY_INTERFACE_PRECALL;
hr = pIDSC->CreateCaptureBuffer(pdscbd, &buffer, pUnkIn);
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("CreateCaptureBuffer", hr);
return NULL;
}
PyIDirectSoundCaptureBuffer *rc = new PyIDirectSoundCaptureBuffer(buffer);
Py_INCREF(self);
rc->m_DS = self;
return rc;
}
// @pymethod |PyIDirectSoundCapture|GetCaps|The GetCaps method retrieves the capabilities of the hardware device that is represented by the DirectSound object. See <l DSCAPS contants>.
PyObject *PyIDirectSoundCapture::GetCaps(PyObject *self, PyObject *args)
{
IDirectSoundCapture *pIDSC = GetI(self);
if ( pIDSC == NULL )
return NULL;
if ( !PyArg_ParseTuple(args, ":GetCaps") )
return NULL;
HRESULT hr;
PyDSCCAPS *caps = new PyDSCCAPS();
PY_INTERFACE_PRECALL;
hr = pIDSC->GetCaps(caps->GetCAPS());
PY_INTERFACE_POSTCALL;
if (FAILED(hr)) {
PyWin_SetAPIError("GetCaps", hr);
return NULL;
}
Py_INCREF(caps);
return caps;
}
// @object PyIDirectSoundCapture|The methods of the IDirectSoundCapture interface are used to create sound capture buffers.
static struct PyMethodDef PyIDirectSoundCapture_methods[] =
{
{ "Initialize", PyIDirectSoundCapture::Initialize, 1 }, // @pymeth Initialize|Description of Initialize.
{ "CreateCaptureBuffer", PyIDirectSoundCapture::CreateCaptureBuffer, 1 }, // @pymeth CreateSoundBuffer|Description of CreateSoundBuffer.
{ "GetCaps", PyIDirectSoundCapture::GetCaps, 1 }, // @pymeth GetCaps|Description of GetCaps.
{ NULL }
};
PyComTypeObject PyIDirectSoundCapture::type("PyIDirectSoundCapture",
&PyIUnknown::type,
sizeof(PyIDirectSoundCapture),
PyIDirectSoundCapture_methods,
GET_PYCOM_CTOR(PyIDirectSoundCapture));
--- NEW FILE: PyDSCBCAPS.cpp ---
//
// @doc
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "PySoundObjects.h"
#include "structmember.h"
#include "directsound_pch.h"
// @pymethod <o PyDSCBCAPS>|pywintypes|DSCBCAPS|Creates a new DSCBCAPS object
PyObject *PyWinMethod_NewDSCBCAPS(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":DSCBCAPS"))
return NULL;
return new PyDSCBCAPS();
}
PyObject *PyWinObject_FromDSCBCAPS(const DSCBCAPS &caps)
{
return new PyDSCBCAPS(caps);
}
BOOL PyWinObject_AsDSCBCAPS(PyObject *ob, DSCBCAPS **ppDSCBCAPS, BOOL bNoneOK /*= TRUE*/)
{
if (bNoneOK && ob==Py_None) {
*ppDSCBCAPS = NULL;
} else if (!PyDSCBCAPS_Check(ob)) {
PyErr_SetString(PyExc_TypeError, "The object is not a PyDSCBCAPS object");
return FALSE;
} else {
PyDSCBCAPS *pycaps= (PyDSCBCAPS *)ob;
*ppDSCBCAPS = pycaps->GetCAPS();
}
return TRUE;
}
// @object PyDSCBCAPS|A Python object, representing a DSCBCAPS structure
static struct PyMethodDef PyDSCBCAPS_methods[] = {
{NULL}
};
PyTypeObject PyDSCBCAPSType =
{
PyObject_HEAD_INIT(&PyType_Type)
0,
"PyDSCBCAPSType",
sizeof(PyDSCBCAPSType),
0,
PyDSCBCAPS::deallocFunc,
0, // tp_print;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0,
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr,
PyObject_GenericSetAttr,
0, // tp_as_buffer;
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags;
0, // tp_doc; /* Documentation string */
0, // traverseproc tp_traverse;
0, // tp_clear;
0, // tp_richcompare;
0, // tp_weaklistoffset;
0, // tp_iter
0, // iternextfunc tp_iternext
0, // methods
PyDSCBCAPS::members,
0, // tp_getset;
0, // tp_base;
0, // tp_dict;
0, // tp_descr_get;
0, // tp_descr_set;
0, // tp_dictoffset;
0, // tp_init;
0, // tp_alloc;
0 // newfunc tp_new;
};
#define OFF(e) offsetof(PyDSCBCAPS, e)
/*static*/ struct PyMemberDef PyDSCBCAPS::members[] = {
{"dwFlags", T_INT, OFF(m_caps.dwFlags), 0, "Specifies device capabilities. Can be 0 or DSCBCAPS_EMULDRIVER (indicates that no DirectSoundCapture device is available and standard wave audio functions are being used)"},
// @prop integer|dwFlags|Specifies device capabilities. Can be 0 or DSCBCAPS_EMULDRIVER (indicates that no DirectSound Device is available and standard wave audio functions are being used).
{"dwBufferBytes", T_INT, OFF(m_caps.dwBufferBytes), 0, "The size, in bytes, of the capture buffer."},
// @prop integer|dwBufferBytes|The size, in bytes, of the capture buffer.
{NULL}
};
PyDSCBCAPS::PyDSCBCAPS(void)
{
ob_type = &PyDSCBCAPSType;
_Py_NewReference(this);
memset(&m_caps, 0, sizeof(m_caps));
}
PyDSCBCAPS::PyDSCBCAPS(const DSCBCAPS &caps)
{
ob_type = &PyDSCBCAPSType;
_Py_NewReference(this);
m_caps = caps;
m_caps.dwSize = sizeof(DSCBCAPS);
}
PyDSCBCAPS::~PyDSCBCAPS()
{
}
/*static*/ void PyDSCBCAPS::deallocFunc(PyObject *ob)
{
delete (PyDSCBCAPS *)ob;
}
--- NEW FILE: PyDSCBUFFERDESC.cpp ---
//
// @doc
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "PySoundObjects.h"
#include "structmember.h"
#include "directsound_pch.h"
// @pymethod <o PyDSCBUFFERDESC>|pywintypes|DSCBUFFERDESC|Creates a new DSCBUFFERDESC object
PyObject *PyWinMethod_NewDSCBUFFERDESC(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":DSCBUFFERDESC"))
return NULL;
return new PyDSCBUFFERDESC();
}
PyObject *PyWinObject_FromDSCBUFFERDESC(const DSCBUFFERDESC &dscbd)
{
return new PyDSCBUFFERDESC(dscbd);
}
BOOL PyWinObject_AsDSCBUFFERDESC(PyObject *ob, DSCBUFFERDESC **ppDSCBUFFERDESC, BOOL bNoneOK /*= TRUE*/)
{
if (bNoneOK && ob==Py_None) {
*ppDSCBUFFERDESC = NULL;
} else if (!PyDSCBUFFERDESC_Check(ob)) {
PyErr_SetString(PyExc_TypeError, "The object is not a PyDSCBUFFERDESC object");
return FALSE;
} else {
PyDSCBUFFERDESC *pydscbd= (PyDSCBUFFERDESC *)ob;
*ppDSCBUFFERDESC = &pydscbd->m_dscbd;
// in case the PyWAVEFORMATEX has been manipulated and points to a different address now
((DSCBUFFERDESC *)*ppDSCBUFFERDESC)->lpwfxFormat =
&((PyWAVEFORMATEX *)pydscbd->m_obWFX)->m_wfx;
}
return TRUE;
}
// @object PyDSCBUFFERDESC|A Python object, representing a DSCBUFFERDESC structure
static struct PyMethodDef PyDSCBUFFERDESC_methods[] = {
{NULL}
};
PyTypeObject PyDSCBUFFERDESCType =
{
PyObject_HEAD_INIT(&PyType_Type)
0,
"PyDSCBUFFERDESC",
sizeof(PyDSCBUFFERDESC),
0,
PyDSCBUFFERDESC::deallocFunc,
0, // tp_print;
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0,
0, /* tp_call */
0, /* tp_str */
PyObject_GenericGetAttr,
PyDSCBUFFERDESC::setattro,
0, // tp_as_buffer;
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, // tp_flags;
0, // tp_doc; /* Documentation string */
0, // traverseproc tp_traverse;
0, // tp_clear;
0, // tp_richcompare;
0, // tp_weaklistoffset;
0, // tp_iter
0, // iternextfunc tp_iternext
0, // methods
PyDSCBUFFERDESC::members,
0, // tp_getset;
0, // tp_base;
0, // tp_dict;
0, // tp_descr_get;
0, // tp_descr_set;
0, // tp_dictoffset;
0, // tp_init;
0, // tp_alloc;
0 // newfunc tp_new;
};
#define OFF(e) offsetof(PyDSCBUFFERDESC, e)
/*static*/ struct PyMemberDef PyDSCBUFFERDESC::members[] = {
{"dwFlags", T_INT, OFF(m_dscbd.dwFlags), 0, "Identifies the capabilities to include when creating a new DirectSoundBuffer object"},
// @prop integer|dwFlags|Identifies the capabilities to include when creating a new DirectSoundBuffer object.
{"dwBufferBytes", T_INT, OFF(m_dscbd.dwBufferBytes), 0, "Size of the new buffer, in bytes. This value must be 0 when creating primary buffers. For secondary buffers, the minimum and maximum sizes allowed are specified by DSBSIZE_MIN and DSBSIZE_MAX"},
// @prop integer|dwBufferBytes|Size of the new buffer, in bytes. This value must be 0 when creating primary buffers. For secondary buffers, the minimum and maximum sizes allowed are specified by DSBSIZE_MIN and DSBSIZE_MAX.
{"lpwfxFormat", T_OBJECT, OFF(m_obWFX), 0, "Structure specifying the waveform format for the buffer. This value must be None for primary buffers. The application can use IDirectSoundCaptureBuffer::SetFormat to set the format of the primary buffer."},
// @prop WAVEFORMATEX|lpwfxFormat|Structure specifying the waveform format for the buffer. This value must be None for primary buffers. The application can use IDirectSoundBuffer::SetFormat to set the format of the primary buffer.
{NULL} /* Sentinel */
};
PyDSCBUFFERDESC::PyDSCBUFFERDESC(void)
{
ob_type = &PyDSCBUFFERDESCType;
_Py_NewReference(this);
memset(&m_dscbd, 0, sizeof(m_dscbd));
m_dscbd.dwSize = sizeof(DSCBUFFERDESC);
Py_INCREF(Py_None);
m_obWFX = Py_None;
}
PyDSCBUFFERDESC::PyDSCBUFFERDESC(const DSCBUFFERDESC &dscbd)
{
m_dscbd.dwSize = sizeof(DSCBUFFERDESC);
ob_type = &PyDSCBUFFERDESCType;
_Py_NewReference(this);
m_dscbd = dscbd;
if (dscbd.lpwfxFormat) {
m_obWFX = new PyWAVEFORMATEX(*dscbd.lpwfxFormat);
m_dscbd.lpwfxFormat = &((PyWAVEFORMATEX*)m_obWFX)->m_wfx;
}
else {
Py_INCREF(Py_None);
m_obWFX = Py_None;
}
}
PyDSCBUFFERDESC::~PyDSCBUFFERDESC()
{
Py_XDECREF( m_obWFX );
}
/*static*/ void PyDSCBUFFERDESC::deallocFunc(PyObject *ob)
{
delete (PyDSCBUFFERDESC *)ob;
}
int PyDSCBUFFERDESC::setattro(PyObject *self, PyObject *obname, PyObject *obvalue)
{
PyDSCBUFFERDESC *obself = (PyDSCBUFFERDESC*)self;
char *name=PyString_AsString(obname);
if (name==NULL)
return -1;
if (strcmp(name,"lpwfxFormat") == 0) {
if (obvalue == Py_None)
{
obself->m_dscbd.lpwfxFormat = NULL;
}
else if (!PyWAVEFORMATEX_Check(obvalue)) {
PyErr_SetString(PyExc_ValueError,"lpwfxFormat must be a WAVEFORMATEX instance");
return -1;
}
else {
obself->m_dscbd.lpwfxFormat = &((PyWAVEFORMATEX*)obvalue)->m_wfx;
}
}
return PyObject_GenericSetAttr(self, obname, obvalue);
}
|