FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GH-60729: Add IEEE format wave audio support by mbeijen · Pull Request #145384 · python/cpython · GitHub

Repository navigation

GH-60729: Add IEEE format wave audio support - #145384

Merged
encukou merged 13 commits into
python:mainfrom
mbeijen:GH-60729-add-ieee-wave-audio-support
Mar 13, 2026
Merged

encukou merged 13 commits into
python:mainfrom
mbeijen:GH-60729-add-ieee-wave-audio-support

Conversation

mbeijen commented Mar 1, 2026 •
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Contributor

This is an updated version of #102574, the original PR where @lkoenig added support for IEEE Wave Audio.

As requested by @encukou

I've

  • Renamed the new 'getencoding/setencoding' to 'getformat/setformat' - format is the term used in the specifications
  • Added format to getparams
  • Added FACT chunk to written non-PCM wave files, which is required by the spec (and is what Audacity does)
  • Added documentation!

Closes: #102574


📚 Documentation preview 📚: https://cpython-previews--145384.org.readthedocs.build/

lkoenig and others added 5 commits March 1, 2026 09:54
This adds support for floating point wav files and fix python#60729.
'format' is the term used in the wave audio specification
Per the RIFF/WAVE Rev. 3 documentation, non-PCM formats require a fact chunk, while PCM does not.
This is also what libsdnfile/audacity do

Reference: https://mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html (see the 'fact Chunk' section and linked Rev. 3 RIFF docs).
These methods are public but were previously not documented. This caused
the unit tests to fail when I mentioned changes to getparams() in the
whats new ;-)
…CHTe.rst

Co-authored-by: AN Long <aisk@users.noreply.github.com>
mbeijen requested a review from aisk March 1, 2026 15:49

lkoenig left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for pushing that forward.

encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you for the PR!
I didn't finish reviewing today; sending the comments I have.

Comment thread Doc/library/wave.rst Outdated
Comment thread Doc/library/wave.rst Outdated
Comment on lines +110 to +111
This is one of ``WAVE_FORMAT_PCM``, ``WAVE_FORMAT_IEEE_FLOAT``, or
``WAVE_FORMAT_EXTENSIBLE``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could you document these using .. data::, and link to them using :data:?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

done

Comment thread Doc/library/wave.rst Outdated
Comment on lines +128 to +129
framerate, nframes, comptype, compname, format)``, equivalent to output
of the ``get*()`` methods.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is a backwards-incompatible change: before someone could write:

    nc, sw, fr, nf, ct, cn = wav.getparams()

This could be solved by adding format as a named-only attribute (which, unfortunately, isn't easy with namedtuple), or maybe an argument to getparams.
You might want to leave getparams alone for now & tackle this in a focused follow-up PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure, I reverted those changes now

Comment thread Doc/library/wave.rst
Comment thread Lib/test/test_wave.py Outdated
class MiscTestCase(unittest.TestCase):
def test__all__(self):
not_exported = {'WAVE_FORMAT_PCM', 'WAVE_FORMAT_EXTENSIBLE', 'KSDATAFORMAT_SUBTYPE_PCM'}
not_exported = {'WAVE_FORMAT_PCM', 'WAVE_FORMAT_IEEE_FLOAT', 'WAVE_FORMAT_EXTENSIBLE', 'KSDATAFORMAT_SUBTYPE_PCM'}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please export the WAVE_FORMAT_ ones (add to __all__) instead, and remove them here.
No point in hiding them; they're needed for documented functionality.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(I'd keep KSDATAFORMAT_SUBTYPE_PCM hidden until it's documented; that seems out of scope for this PR.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure, they're exported now

Comment thread Lib/wave.py
Comment on lines +650 to +653
try:
self._fact_sample_count_pos = self._file.tell()
except (AttributeError, OSError):
self._fact_sample_count_pos = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hmm, what's the story about supporting files without tell?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I’m not trying to extend unseekable support in this PR. I’m keeping the existing behavior: if output is seekable, header fields (including fact) are patched as needed; for unseekable outputs, writing works when header values are already final, and mismatches can still fail as before.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
mbeijen requested a review from encukou March 3, 2026 20:06
Comment thread Doc/library/wave.rst

.. data:: WAVE_FORMAT_IEEE_FLOAT

Format code for IEEE floating-point audio.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What is the size of a sample? 32-bit? Or does it accept different sizes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

for IEEE Float it can only be 32-bit or 64-bit. I've amended the documentation and added raising errors in case of setting sampwidth to different values for IEEE or setting format to IEEE if sampwidth is incorrect values

This is also similar to what libsndfile does
mbeijen force-pushed the GH-60729-add-ieee-wave-audio-support branch from eeee8cd to 6d62e66 Compare March 7, 2026 17:04
mbeijen requested a review from vstinner March 7, 2026 19:00

encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good to me, thank you!
Will merge tomorrow if there are no objections.

mbeijen commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

awesome and thanks in advance! While you're at it I'd like to ask you to also consider these (smaller) PRs I made for wave.py that did not get much attention yet:

There's also this but it might warrant some rework after this IEEE PR is merged, I might want to make a new one for that

encukou merged commit 61f2a1a into python:main Mar 13, 2026
51 checks passed

encukou commented Mar 13, 2026

Copy link
Copy Markdown
Member

I put them on my list :)

encukou added a commit to encukou/cpython that referenced this pull request Mar 13, 2026

encukou commented Mar 13, 2026

Copy link
Copy Markdown
Member

Unfortunately, the tests break on big-endian machines.
I'll not be available for the rest of the week, so I'll revert the commit for now and try looking into it next week.

mbeijen commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

That is a shame. So how should I proceed? Since this is merged already, new PR with this code plus fixes? Also why these did not fail before?

I will try to locate my sun 3/60 and run unit tests. Oh no I will get my amiga. Or maybe my Mac PPC? Oh I do not own any of these machines anymore. I will just set up QEMU then

encukou commented Mar 13, 2026

Copy link
Copy Markdown
Member

Yeah, new PR with this plus fixes. It's all squashed anyway.

Also why these did not fail before?

They're not on GitHub Actions; they're slow so they don't run on every commit.

Here's the failure, for the record: https://buildbot.python.org/#/builders/1636/builds/2307/steps/6/logs/stdio

encukou added a commit that referenced this pull request Mar 13, 2026
…-145928)

Revert "GH-60729: Add IEEE format wave audio support (GH-145384)"

This reverts commit 61f2a1a for now;
as tests fail on big-endian machines.
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
…145384)" (pythonGH-145928)

Revert "pythonGH-60729: Add IEEE format wave audio support (pythonGH-145384)"

This reverts commit 61f2a1a for now;
as tests fail on big-endian machines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL