|
|
Log in / Subscribe / Register

PCM

PCM

Posted Mar 17, 2022 9:21 UTC (Thu) by eru (subscriber, #2753)
In reply to: PCM by tialaramex
Parent article: Python finally offloads some batteries

WAV is commonly used as a lossless audio format, for example when ripping CD:s, and as a lowest common denominator when moving audio data between different programs. So keeping it is well justified.


to post comments

PCM

Posted Mar 17, 2022 11:49 UTC (Thu) by tialaramex (subscriber, #21167) [Link] (2 responses)

All WAV is doing in these scenarios is providing a few header bytes on some raw PCM data. If you have software to just treat some data as 16-bit unsigned PCM data and play it as a sound, you'll find your WAV file is exactly that sound, except there's a brief fraction of a second glitch at the start because the first few bytes are a header.

The actual Microsoft WAV format technically does lots more than this, but scarcely anybody bothers implementing any of that stuff, and I think that includes Python's wave. So we should admit that we don't want WAV we just wanted to store PCM data.

If you've ever run into files (or downloads) named .xls but they were actually CSV files, it's a little similar to that. Do you want an XLS reader? Well, that's pretty complicated, I worked on one (for Gnumeric) and it's quite a ride. But if all you need is to read the CSV file you didn't actually want a XLS reader and it's probably misleading to name your CSV parser "xls".

PCM

Posted Mar 17, 2022 12:26 UTC (Thu) by nix (subscriber, #2304) [Link]

> The actual Microsoft WAV format technically does lots more than this, but scarcely anybody bothers implementing any of that stuff, and I think that includes Python's wave. So we should admit that we don't want WAV we just wanted to store PCM data.

Yes, but... huge amounts of software accepts and produces WAV files. Much less accepts or produces PCM. It's an interchange format in that respect, like it or not...

PCM

Posted Mar 17, 2022 19:40 UTC (Thu) by mbunkus (subscriber, #87248) [Link]

It actually isn't that easy as not all PCM data is equal. There are several parameters that a decoder must know in order to play that sound back properly, including:

* sampling frequency (also called sample rate)
* number of channels
* order of channels
* number of bits per sample (also called bit depth)
* signed or unsigned
* Endianess if bits per sample > 8
* PCM format (e.g. a-law, ยต-law, linear, etc.)

PCM used on CDs isn't the same as PCM used on Blu-rays, for example.

Not one of those parameters is really optional. Sure, you can specify all of them manually when decoding (or when using tools such as sox to convert from raw PCM data to one of the containerized variants), but the container's whole purpose is to relief us humans of the need to keep that extra information around somehow. That's what the WAV container does. As do other container formats, but WAV one of the simplest one to use (within certain limits), making it especially suitable for people new to programming or new to audio processing.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds