mirror of https://github.com/python/cpython
Mark Hammond writes:
Attached is a context diff to winsound.c that adds a Beep() function to play a sound through the PC speaker. Seems to make sense to have this added, so I just went and did it!
This commit is contained in:
parent
91cae85c32
commit
99eb7a1255
|
@ -8,6 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Modified by Guido van Rossum */
|
/* Modified by Guido van Rossum */
|
||||||
|
/* Beep added by Mark Hammond */
|
||||||
|
|
||||||
/* Example:
|
/* Example:
|
||||||
|
|
||||||
|
@ -43,6 +44,13 @@ static char sound_playsound_doc[] =
|
||||||
"The sound argument can be a filename, data, or None.\n"
|
"The sound argument can be a filename, data, or None.\n"
|
||||||
"For flag values, ored together, see module documentation.\n";
|
"For flag values, ored together, see module documentation.\n";
|
||||||
|
|
||||||
|
static char sound_beep_doc[] =
|
||||||
|
"Beep(frequency, duration) - a wrapper around the Windows Beep API\n"
|
||||||
|
"\n"
|
||||||
|
"The frequency argument specifies frequency, in hertz, of the sound.\n"
|
||||||
|
"This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).\n"
|
||||||
|
"The duration argument specifies the number of milli-seconds.\n";
|
||||||
|
|
||||||
static char sound_module_doc[] =
|
static char sound_module_doc[] =
|
||||||
"PlaySound(sound, flags) - play a sound\n"
|
"PlaySound(sound, flags) - play a sound\n"
|
||||||
"SND_FILENAME - sound is a wav file name\n"
|
"SND_FILENAME - sound is a wav file name\n"
|
||||||
|
@ -54,7 +62,8 @@ static char sound_module_doc[] =
|
||||||
"SND_NODEFAULT - Do not play a default beep if the sound can not be found\n"
|
"SND_NODEFAULT - Do not play a default beep if the sound can not be found\n"
|
||||||
"SND_NOSTOP - Do not interrupt any sounds currently playing\n" // Raising RuntimeError if needed
|
"SND_NOSTOP - Do not interrupt any sounds currently playing\n" // Raising RuntimeError if needed
|
||||||
"SND_NOWAIT - Return immediately if the sound driver is busy\n" // Without any errors
|
"SND_NOWAIT - Return immediately if the sound driver is busy\n" // Without any errors
|
||||||
;
|
"\n"
|
||||||
|
"Beep(frequency, duration) - Make a beep through the PC speaker.\n";
|
||||||
|
|
||||||
PyObject *sound_playsound(PyObject *s, PyObject *args)
|
PyObject *sound_playsound(PyObject *s, PyObject *args)
|
||||||
{
|
{
|
||||||
|
@ -89,9 +98,30 @@ PyObject *sound_playsound(PyObject *s, PyObject *args)
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *sound_beep( PyObject *self, PyObject *args )
|
||||||
|
{
|
||||||
|
int freq;
|
||||||
|
int dur;
|
||||||
|
BOOL ok;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "ii:Beep", &freq, &dur))
|
||||||
|
return NULL;
|
||||||
|
Py_BEGIN_ALLOW_THREADS
|
||||||
|
ok = Beep(freq,dur);
|
||||||
|
Py_END_ALLOW_THREADS
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_RuntimeError,"Failed to beep");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
Py_INCREF(Py_None);
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
|
|
||||||
static struct PyMethodDef sound_methods[] =
|
static struct PyMethodDef sound_methods[] =
|
||||||
{
|
{
|
||||||
{"PlaySound", sound_playsound, 1, sound_playsound_doc},
|
{"PlaySound", sound_playsound, 1, sound_playsound_doc},
|
||||||
|
{"Beep", sound_beep, 1, sound_beep_doc},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue