Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6405/win32/src
Modified Files:
PyWinTypes.h PyWinTypesmodule.cpp
Added Files:
PySoundObjects.h PyWAVEFORMATEX.cpp
Log Message:
Added (some) DirectSound support.
The bulk is in com/win32comext/directsound, including a test directory with
a sample soundfile and a unittest-based test script.
Supported are:
- IDirectSound
- IDirectSoundBuffer
- IDirectSoundNotify.
Also added support for:
- WAVEFORMATEX (in PyWinTypes)
- DSBUFFERDESC
- DSBCAPS
- DSCAPS
- various constants used in these structures
Missing is:
- IDirectSoundCapture
- complete documentation
--- NEW FILE: PySoundObjects.h ---
#ifndef __PYSOUNDOBJECTS_H__
#define __PYSOUNDOBJECTS_H__
#include <windows.h>
#include <dsound.h>
class PYWINTYPES_EXPORT PyWAVEFORMATEX : public PyObject
{
public:
PyWAVEFORMATEX(void);
PyWAVEFORMATEX(const WAVEFORMATEX &);
~PyWAVEFORMATEX();
/* 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
WAVEFORMATEX m_wfx;
};
#endif
Index: PyWinTypesmodule.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypesmodule.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** PyWinTypesmodule.cpp 7 Sep 2004 04:27:04 -0000 1.17
--- PyWinTypesmodule.cpp 30 Nov 2004 21:30:29 -0000 1.18
***************
*** 452,455 ****
--- 452,456 ----
{"_GetLockStats", _GetLockStats, 1},
#endif /* TRACE_THREADSTATE */
+ {"WAVEFORMATEX", PyWinMethod_NewWAVEFORMATEX, 1 }, // @pymeth WAVEFORMATEX|Creates a new <o PyWAVEFORMATEX> object.
{NULL, NULL}
};
***************
*** 497,500 ****
--- 498,515 ----
}
+ static int AddConstant(PyObject *dict, const char *key, long value)
+ {
+ PyObject *oval = PyInt_FromLong(value);
+ if (!oval)
+ {
+ return 1;
+ }
+ int rc = PyDict_SetItemString(dict, (char*)key, oval);
+ Py_DECREF(oval);
+ return rc;
+ }
+
+ #define ADD_CONSTANT(tok) AddConstant(dict, #tok, tok)
+
extern "C" __declspec(dllexport)
void initpywintypes(void)
***************
*** 520,523 ****
--- 535,539 ----
PyDict_SetItemString(dict, "TRUE", Py_True);
PyDict_SetItemString(dict, "FALSE", Py_False);
+ ADD_CONSTANT(WAVE_FORMAT_PCM);
// Add a few types.
***************
*** 537,541 ****
PyDict_SetItemString(dict, "OVERLAPPEDType", (PyObject *)&PyHANDLEType);
PyDict_SetItemString(dict, "DEVMODEType", (PyObject *)&PyDEVMODEType);
!
}
--- 553,557 ----
PyDict_SetItemString(dict, "OVERLAPPEDType", (PyObject *)&PyHANDLEType);
PyDict_SetItemString(dict, "DEVMODEType", (PyObject *)&PyDEVMODEType);
! PyDict_SetItemString(dict, "WAVEFORMATEXType", (PyObject *)&PyWAVEFORMATEXType);
}
Index: PyWinTypes.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PyWinTypes.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** PyWinTypes.h 7 Sep 2004 10:04:35 -0000 1.24
--- PyWinTypes.h 30 Nov 2004 21:30:29 -0000 1.25
***************
*** 14,17 ****
--- 14,21 ----
#include "Python.h"
#include "windows.h"
+
+ // Lars: for WAVEFORMATEX
+ #include "mmsystem.h"
+
// Do we want to use the builtin Unicode object?
// If defined, we use the standard builtin type.
***************
*** 312,315 ****
--- 316,330 ----
/*
+ ** WAVEFORMATEX support
+ */
+
+ PYWINTYPES_EXPORT PyObject *PyWinMethod_NewWAVEFORMATEX(PyObject *self, PyObject *args);
+ PYWINTYPES_EXPORT PyObject *PyWinObject_FromWAVEFROMATEX(const WAVEFORMATEX &wfx);
+ PYWINTYPES_EXPORT BOOL PyWinObject_AsWAVEFORMATEX(PyObject *ob, WAVEFORMATEX **ppWAVEFORMATEX, BOOL bNoneOK = TRUE);
+ extern PYWINTYPES_EXPORT PyTypeObject PyWAVEFORMATEXType;
+ #define PyWAVEFORMATEX_Check(ob) ((ob)->ob_type == &PyWAVEFORMATEXType)
+
+
+ /*
** SECURITY_DESCRIPTOR support
*/
--- NEW FILE: PyWAVEFORMATEX.cpp ---
//
// @doc
#include "Python.h"
#include "PyWinTypes.h"
#include "PyWinObjects.h"
#include "PySoundObjects.h"
#include "structmember.h"
// @pymethod <o PyWAVEFORMATEX>|pywintypes|WAVEFORMATEX|Creates a new WAVEFORMATEX object
PyObject *PyWinMethod_NewWAVEFORMATEX(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, ":WAVEFORMATEX"))
return NULL;
return new PyWAVEFORMATEX();
}
PyObject *PyWinObject_FromWAVEFORMATEX(const WAVEFORMATEX &wfx)
{
return new PyWAVEFORMATEX(wfx);
}
BOOL PyWinObject_AsWAVEFORMATEX(PyObject *ob, WAVEFORMATEX **ppWAVEFORMATEX, BOOL bNoneOK /*= TRUE*/)
{
if (bNoneOK && ob==Py_None) {
*ppWAVEFORMATEX = NULL;
} else if (!PyWAVEFORMATEX_Check(ob)) {
PyErr_SetString(PyExc_TypeError, "The object is not a PyWAVEFORMATEX object");
return FALSE;
} else {
PyWAVEFORMATEX *pywfx= (PyWAVEFORMATEX *)ob;
*ppWAVEFORMATEX = &pywfx->m_wfx;
}
return TRUE;
}
// @object PyWAVEFORMATEX|A Python object, representing a WAVEFORMATEX structure
static struct PyMethodDef PyWAVEFORMATEX_methods[] = {
{NULL}
};
PYWINTYPES_EXPORT PyTypeObject PyWAVEFORMATEXType =
{
PyObject_HEAD_INIT(&PyType_Type)
0,
"PyWAVEFORMATEX",
sizeof(PyWAVEFORMATEX),
0,
PyWAVEFORMATEX::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
PyWAVEFORMATEX::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(PyWAVEFORMATEX, e)
/*static*/ struct PyMemberDef PyWAVEFORMATEX::members[] = {
{"wFormatTag", T_SHORT, OFF(m_wfx.wFormatTag), 0, "Format as an integer. WAVE_FORMAT_PCM (1) is very common."}, // @prop integer|wFormatTag|Waveform-audio format type. pywintypes only defines WAVE_FORMAT_PCM as a constant. Other values must be looked up in the mmsystem.h header file.
{"nChannels", T_SHORT, OFF(m_wfx.nChannels), 0, "Number of channels" }, // @prop integer|nChannels|Number of channels. 1 for Mono, 2 for Stereo, anything, but never 5.1.
{"nSamplesPerSec", T_INT, OFF(m_wfx.nSamplesPerSec), 0, "Sample rate in seconds" }, // @prop integer|Sample rate, in samples per second (hertz), that each channel should be played or recorded. If wFormatTag is WAVE_FORMAT_PCM, then common values for nSamplesPerSec are 8000, 11025, 22050, and 44100 Hz
{"nAvgBytesPerSec", T_INT, OFF(m_wfx.nAvgBytesPerSec), 0, "Required average data-transfer rate, in bytes per second, for the format tag. If wFormatTag is WAVE_FORMAT_PCM, nAvgBytesPerSec should be equal to the product of nSamplesPerSec and nBlockAlign." }, // @prop integer|nAvgBytesPerSec|Required average data-transfer rate, in bytes per second, for the format tag. If wFormatTag is WAVE_FORMAT_PCM, nAvgBytesPerSec should be equal to the product of nSamplesPerSec and nBlockAlign.
{"nBlockAlign", T_SHORT, OFF(m_wfx.nBlockAlign), 0, "Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, nBlockAlign should be equal to the product of nChannels and wBitsPerSample divided by 8 (bits per byte)."}, // @prop integer|nBlockAlign|Block alignment, in bytes. The block alignment is the minimum atomic unit of data for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, nBlockAlign should be equal to the product of nChannels and wBitsPerSample divided by 8 (bits per byte). For non-PCM formats, this member must be computed according to the manufacturers specification of the format tag.
{"wBitsPerSample", T_SHORT, OFF(m_wfx.wBitsPerSample), 0, "Bits per sample for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, then wBitsPerSample should be equal to 8 or 16."}, // @prop integer|wBitsPerSample|Bits per sample for the wFormatTag format type. If wFormatTag is WAVE_FORMAT_PCM, then wBitsPerSample should be equal to 8 or 16.
{NULL} /* Sentinel */
};
PyWAVEFORMATEX::PyWAVEFORMATEX(void)
{
ob_type = &PyWAVEFORMATEXType;
_Py_NewReference(this);
memset(&m_wfx, 0, sizeof(m_wfx));
}
PyWAVEFORMATEX::PyWAVEFORMATEX(const WAVEFORMATEX &wfx)
{
ob_type = &PyWAVEFORMATEXType;
_Py_NewReference(this);
m_wfx = wfx;
m_wfx.cbSize = 0;
}
PyWAVEFORMATEX::~PyWAVEFORMATEX()
{
}
/*static*/ void PyWAVEFORMATEX::deallocFunc(PyObject *ob)
{
delete (PyWAVEFORMATEX *)ob;
}
|