88 */
99
1010/* Modified by Guido van Rossum */
11+ /* Beep added by Mark Hammond */
1112
1213/* Example:
1314
@@ -43,6 +44,13 @@ static char sound_playsound_doc[] =
4344"The sound argument can be a filename, data, or None.\n"
4445"For flag values, ored together, see module documentation.\n" ;
4546
47+ static char sound_beep_doc [] =
48+ "Beep(frequency, duration) - a wrapper around the Windows Beep API\n"
49+ "\n"
50+ "The frequency argument specifies frequency, in hertz, of the sound.\n"
51+ "This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).\n"
52+ "The duration argument specifies the number of milli-seconds.\n" ;
53+
4654static char sound_module_doc [] =
4755"PlaySound(sound, flags) - play a sound\n"
4856"SND_FILENAME - sound is a wav file name\n"
@@ -54,7 +62,8 @@ static char sound_module_doc[] =
5462"SND_NODEFAULT - Do not play a default beep if the sound can not be found\n"
5563"SND_NOSTOP - Do not interrupt any sounds currently playing\n" // Raising RuntimeError if needed
5664"SND_NOWAIT - Return immediately if the sound driver is busy\n" // Without any errors
57- ;
65+ "\n"
66+ "Beep(frequency, duration) - Make a beep through the PC speaker.\n" ;
5867
5968PyObject * sound_playsound (PyObject * s , PyObject * args )
6069{
@@ -89,9 +98,30 @@ PyObject *sound_playsound(PyObject *s, PyObject *args)
8998 return Py_None ;
9099}
91100
101+ static PyObject * sound_beep ( PyObject * self , PyObject * args )
102+ {
103+ int freq ;
104+ int dur ;
105+ BOOL ok ;
106+
107+ if (!PyArg_ParseTuple (args , "ii:Beep" , & freq , & dur ))
108+ return NULL ;
109+ Py_BEGIN_ALLOW_THREADS
110+ ok = Beep (freq ,dur );
111+ Py_END_ALLOW_THREADS
112+ if (!ok )
113+ {
114+ PyErr_SetString (PyExc_RuntimeError ,"Failed to beep" );
115+ return NULL ;
116+ }
117+ Py_INCREF (Py_None );
118+ return Py_None ;
119+ }
120+
92121static struct PyMethodDef sound_methods [] =
93122{
94123 {"PlaySound" , sound_playsound , 1 , sound_playsound_doc },
124+ {"Beep" , sound_beep , 1 , sound_beep_doc },
95125 {NULL , NULL }
96126};
97127
0 commit comments