Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ae8298bf
Commit
ae8298bf
authored
Sep 05, 2016
by
Zachary Ware
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #11620: Fix support for SND_MEMORY in winsound.PlaySound.
Based on a patch by Tim Lesher.
parent
0e76e672
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
17 deletions
+64
-17
Doc/library/winsound.rst
Doc/library/winsound.rst
+3
-2
Lib/test/test_winsound.py
Lib/test/test_winsound.py
+16
-0
Misc/NEWS
Misc/NEWS
+3
-0
PC/clinic/winsound.c.h
PC/clinic/winsound.c.h
+4
-4
PC/winsound.c
PC/winsound.c
+38
-11
No files found.
Doc/library/winsound.rst
View file @
ae8298bf
...
@@ -25,7 +25,8 @@ provided by Windows platforms. It includes functions and several constants.
...
@@ -25,7 +25,8 @@ provided by Windows platforms. It includes functions and several constants.
.. function:: PlaySound(sound, flags)
.. function:: PlaySound(sound, flags)
Call the underlying :c:func:`PlaySound` function from the Platform API. The
Call the underlying :c:func:`PlaySound` function from the Platform API. The
*sound* parameter may be a filename, audio data as a string, or ``None``. Its
*sound* parameter may be a filename, a system sound alias, audio data as a
:term:`bytes-like object`, or ``None``. Its
interpretation depends on the value of *flags*, which can be a bitwise ORed
interpretation depends on the value of *flags*, which can be a bitwise ORed
combination of the constants described below. If the *sound* parameter is
combination of the constants described below. If the *sound* parameter is
``None``, any currently playing waveform sound is stopped. If the system
``None``, any currently playing waveform sound is stopped. If the system
...
@@ -92,7 +93,7 @@ provided by Windows platforms. It includes functions and several constants.
...
@@ -92,7 +93,7 @@ provided by Windows platforms. It includes functions and several constants.
.. data:: SND_MEMORY
.. data:: SND_MEMORY
The *sound* parameter to :func:`PlaySound` is a memory image of a WAV file, as a
The *sound* parameter to :func:`PlaySound` is a memory image of a WAV file, as a
string
.
:term:`bytes-like object`
.
.. note::
.. note::
...
...
Lib/test/test_winsound.py
View file @
ae8298bf
...
@@ -87,6 +87,22 @@ class PlaySoundTest(unittest.TestCase):
...
@@ -87,6 +87,22 @@ class PlaySoundTest(unittest.TestCase):
winsound
.
PlaySound
,
winsound
.
PlaySound
,
"none"
,
winsound
.
SND_ASYNC
|
winsound
.
SND_MEMORY
"none"
,
winsound
.
SND_ASYNC
|
winsound
.
SND_MEMORY
)
)
self
.
assertRaises
(
TypeError
,
winsound
.
PlaySound
,
b"bad"
,
0
)
self
.
assertRaises
(
TypeError
,
winsound
.
PlaySound
,
"bad"
,
winsound
.
SND_MEMORY
)
self
.
assertRaises
(
TypeError
,
winsound
.
PlaySound
,
1
,
0
)
def
test_snd_memory
(
self
):
with
open
(
support
.
findfile
(
'pluck-pcm8.wav'
,
subdir
=
'audiodata'
),
'rb'
)
as
f
:
audio_data
=
f
.
read
()
safe_PlaySound
(
audio_data
,
winsound
.
SND_MEMORY
)
audio_data
=
bytearray
(
audio_data
)
safe_PlaySound
(
audio_data
,
winsound
.
SND_MEMORY
)
def
test_snd_filename
(
self
):
fn
=
support
.
findfile
(
'pluck-pcm8.wav'
,
subdir
=
'audiodata'
)
safe_PlaySound
(
fn
,
winsound
.
SND_FILENAME
|
winsound
.
SND_NODEFAULT
)
def
test_aliases
(
self
):
def
test_aliases
(
self
):
aliases
=
[
aliases
=
[
...
...
Misc/NEWS
View file @
ae8298bf
...
@@ -75,6 +75,9 @@ Core and Builtins
...
@@ -75,6 +75,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #11620: Fix support for SND_MEMORY in winsound.PlaySound. Based on a
patch by Tim Lesher.
- Issue #11734: Add support for IEEE 754 half-precision floats to the
- Issue #11734: Add support for IEEE 754 half-precision floats to the
struct module. Based on a patch by Eli Stevens.
struct module. Based on a patch by Eli Stevens.
...
...
PC/clinic/winsound.c.h
View file @
ae8298bf
...
@@ -17,16 +17,16 @@ PyDoc_STRVAR(winsound_PlaySound__doc__,
...
@@ -17,16 +17,16 @@ PyDoc_STRVAR(winsound_PlaySound__doc__,
{"PlaySound", (PyCFunction)winsound_PlaySound, METH_VARARGS, winsound_PlaySound__doc__},
{"PlaySound", (PyCFunction)winsound_PlaySound, METH_VARARGS, winsound_PlaySound__doc__},
static
PyObject
*
static
PyObject
*
winsound_PlaySound_impl
(
PyObject
*
module
,
Py
_UNICODE
*
sound
,
int
flags
);
winsound_PlaySound_impl
(
PyObject
*
module
,
Py
Object
*
sound
,
int
flags
);
static
PyObject
*
static
PyObject
*
winsound_PlaySound
(
PyObject
*
module
,
PyObject
*
args
)
winsound_PlaySound
(
PyObject
*
module
,
PyObject
*
args
)
{
{
PyObject
*
return_value
=
NULL
;
PyObject
*
return_value
=
NULL
;
Py
_UNICODE
*
sound
;
Py
Object
*
sound
;
int
flags
;
int
flags
;
if
(
!
PyArg_ParseTuple
(
args
,
"
Z
i:PlaySound"
,
if
(
!
PyArg_ParseTuple
(
args
,
"
O
i:PlaySound"
,
&
sound
,
&
flags
))
{
&
sound
,
&
flags
))
{
goto
exit
;
goto
exit
;
}
}
...
@@ -100,4 +100,4 @@ winsound_MessageBeep(PyObject *module, PyObject *args)
...
@@ -100,4 +100,4 @@ winsound_MessageBeep(PyObject *module, PyObject *args)
exit:
exit:
return
return_value
;
return
return_value
;
}
}
/*[clinic end generated code: output=
1044b2adf3c67014
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
b999334e2e444ad2
input=a9049054013a1b77]*/
PC/winsound.c
View file @
ae8298bf
...
@@ -64,7 +64,7 @@ module winsound
...
@@ -64,7 +64,7 @@ module winsound
/*[clinic input]
/*[clinic input]
winsound.PlaySound
winsound.PlaySound
sound:
Py_UNICODE(accept={str, NoneType})
sound:
object
The sound to play; a filename, data, or None.
The sound to play; a filename, data, or None.
flags: int
flags: int
Flag values, ored together. See module documentation.
Flag values, ored together. See module documentation.
...
@@ -74,22 +74,49 @@ A wrapper around the Windows PlaySound API.
...
@@ -74,22 +74,49 @@ A wrapper around the Windows PlaySound API.
[clinic start generated code]*/
[clinic start generated code]*/
static
PyObject
*
static
PyObject
*
winsound_PlaySound_impl
(
PyObject
*
module
,
Py
_UNICODE
*
sound
,
int
flags
)
winsound_PlaySound_impl
(
PyObject
*
module
,
Py
Object
*
sound
,
int
flags
)
/*[clinic end generated code: output=
ec24b3a2b4368378 input=3411b1b7c1f36d93
]*/
/*[clinic end generated code: output=
49a0fd16a372ebeb input=7bdf637f10201d37
]*/
{
{
int
ok
;
int
ok
;
wchar_t
*
wsound
;
if
(
flags
&
SND_ASYNC
&&
flags
&
SND_MEMORY
)
{
Py_buffer
view
=
{
NULL
,
NULL
};
/* Sidestep reference counting headache; unfortunately this also
prevent SND_LOOP from memory. */
if
(
sound
==
Py_None
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
wsound
=
NULL
;
"Cannot play asynchronously from memory"
);
}
else
if
(
flags
&
SND_MEMORY
)
{
return
NULL
;
if
(
flags
&
SND_ASYNC
)
{
/* Sidestep reference counting headache; unfortunately this also
prevent SND_LOOP from memory. */
PyErr_SetString
(
PyExc_RuntimeError
,
"Cannot play asynchronously from memory"
);
return
NULL
;
}
if
(
PyObject_GetBuffer
(
sound
,
&
view
,
PyBUF_SIMPLE
)
<
0
)
{
return
NULL
;
}
wsound
=
(
wchar_t
*
)
view
.
buf
;
}
else
{
if
(
!
PyUnicode_Check
(
sound
))
{
PyErr_Format
(
PyExc_TypeError
,
"'sound' must be str or None, not '%s'"
,
Py_TYPE
(
sound
)
->
tp_name
);
return
NULL
;
}
wsound
=
PyUnicode_AsWideCharString
(
sound
,
NULL
);
if
(
wsound
==
NULL
)
{
return
NULL
;
}
}
}
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
ok
=
PlaySoundW
(
sound
,
NULL
,
flags
);
ok
=
PlaySoundW
(
w
sound
,
NULL
,
flags
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
if
(
view
.
obj
)
{
PyBuffer_Release
(
&
view
);
}
else
if
(
sound
!=
Py_None
)
{
PyMem_Free
(
wsound
);
}
if
(
!
ok
)
{
if
(
!
ok
)
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Failed to play sound"
);
PyErr_SetString
(
PyExc_RuntimeError
,
"Failed to play sound"
);
return
NULL
;
return
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment