Skip to content

Commit 7a1fce1

Browse files
committed
wave: add documentation on IEEE support, format API
1 parent 0ad941f commit 7a1fce1

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

Doc/library/wave.rst

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
--------------
1010

1111
The :mod:`!wave` module provides a convenient interface to the Waveform Audio
12-
"WAVE" (or "WAV") file format. Only uncompressed PCM encoded wave files are
13-
supported.
12+
"WAVE" (or "WAV") file format.
13+
14+
The module supports uncompressed PCM and IEEE floating-point WAV formats.
1415

1516
.. versionchanged:: 3.12
1617

1718
Support for ``WAVE_FORMAT_EXTENSIBLE`` headers was added, provided that the
1819
extended format is ``KSDATAFORMAT_SUBTYPE_PCM``.
1920

21+
.. versionchanged:: 3.15
22+
23+
Support for reading and writing ``WAVE_FORMAT_IEEE_FLOAT`` files was added.
24+
2025
The :mod:`!wave` module defines the following function and exception:
2126

2227

@@ -98,6 +103,14 @@ Wave_read Objects
98103
Returns number of audio frames.
99104

100105

106+
.. method:: getformat()
107+
108+
Returns the frame format code.
109+
110+
This is one of ``WAVE_FORMAT_PCM``, ``WAVE_FORMAT_IEEE_FLOAT``, or
111+
``WAVE_FORMAT_EXTENSIBLE``.
112+
113+
101114
.. method:: getcomptype()
102115

103116
Returns compression type (``'NONE'`` is the only supported type).
@@ -112,8 +125,8 @@ Wave_read Objects
112125
.. method:: getparams()
113126

114127
Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth,
115-
framerate, nframes, comptype, compname)``, equivalent to output of the
116-
``get*()`` methods.
128+
framerate, nframes, comptype, compname, format)``, equivalent to output
129+
of the ``get*()`` methods.
117130

118131

119132
.. method:: readframes(n)
@@ -208,11 +221,27 @@ Wave_write Objects
208221
``NONE`` is supported, meaning no compression.
209222

210223

224+
.. method:: setformat(format)
225+
226+
Set the frame format code.
227+
228+
Supported values are ``WAVE_FORMAT_PCM`` and
229+
``WAVE_FORMAT_IEEE_FLOAT``.
230+
231+
232+
.. method:: getformat()
233+
234+
Return the current frame format code.
235+
236+
211237
.. method:: setparams(tuple)
212238

213-
The *tuple* should be ``(nchannels, sampwidth, framerate, nframes, comptype,
214-
compname)``, with values valid for the ``set*()`` methods. Sets all
215-
parameters.
239+
The *tuple* should be
240+
``(nchannels, sampwidth, framerate, nframes, comptype, compname, format)``,
241+
with values valid for the ``set*()`` methods. Sets all parameters.
242+
243+
For backwards compatibility, a 6-item tuple without *format* is also
244+
accepted and defaults to ``WAVE_FORMAT_PCM``.
216245

217246

218247
.. method:: tell()
@@ -242,3 +271,6 @@ Wave_write Objects
242271
Note that it is invalid to set any parameters after calling :meth:`writeframes`
243272
or :meth:`writeframesraw`, and any attempt to do so will raise
244273
:exc:`wave.Error`.
274+
275+
For ``WAVE_FORMAT_IEEE_FLOAT`` output, a ``fact`` chunk is written as
276+
required by the WAVE specification for non-PCM formats.

Doc/whatsnew/3.15.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,23 @@ typing
14931493
wave
14941494
----
14951495

1496+
* Added support for IEEE floating-point WAVE audio
1497+
(``WAVE_FORMAT_IEEE_FLOAT``) in :mod:`wave`.
1498+
1499+
* Added :meth:`wave.Wave_read.getformat`, :meth:`wave.Wave_write.getformat`,
1500+
and :meth:`wave.Wave_write.setformat` for explicit frame format handling.
1501+
1502+
* :meth:`wave.Wave_read.getparams` and :meth:`wave.Wave_write.getparams` now
1503+
include ``format`` as the seventh field in the returned named tuple.
1504+
:meth:`wave.Wave_write.setparams` accepts both 7-item tuples including
1505+
``format`` and 6-item tuples for backwards compatibility (defaulting to
1506+
``WAVE_FORMAT_PCM``).
1507+
1508+
* ``WAVE_FORMAT_IEEE_FLOAT`` output now includes a ``fact`` chunk,
1509+
as required for non-PCM WAVE formats.
1510+
1511+
(Contributed by Lionel Koenig and Michiel W. Beijen in :gh:`60729`.)
1512+
14961513
* Removed the ``getmark()``, ``setmark()`` and ``getmarkers()`` methods
14971514
of the :class:`~wave.Wave_read` and :class:`~wave.Wave_write` classes,
14981515
which were deprecated since Python 3.13.

0 commit comments

Comments
 (0)