PCM
PCM
Posted Mar 16, 2022 23:03 UTC (Wed) by tialaramex (subscriber, #21167)Parent article: Python finally offloads some batteries
This motivation makes sense, but going via wave (and thus WAV) seems unfortunate.
WAV is *almost* but not quite just a wrapper for PCM data, and PCM data really is a pretty fundamental thing that is likely to be just as important and relevant ten years later than the nine-year old first encounters this, but WAV not so much.
I think, from a glance at wave, that it expects you to think about PCM data the way it would have been stored on a CD in the 1990s, specifically as signed 16-bit integers, but that feels very much like something kids shouldn't need to care about at age nine and is less likely to matter in say 2035 than today. Presenting the same capabilities but with normalisation might work, or, if nine year olds are comfortable with decimals, the convention in modern PCM (in software anyway) is the range -1.0 to +1.0 via 0 at 0dB full scale. I don't think there's value in learning that for some crazy reason -32768 through 32767 is the range used by some hardware (signed 16-bit) and there's a _very destructive_ tendency in software that does reflect -32768 to 32767 to not provide saturating arithmetic. In the actual world, with actual sounds, 20000 + 20000 = 40000 and [that being impossible for our 16-bit hardware] so 32767 is the "correct" answer, this correct behaviour for sound is called clipping, but even in Python with 16-bit integers nearby I think you might easily wind up getting -25535 which is horribly wrong (and sounds awful).
Avoiding 16-bit integer arithmetic makes it more likely kids are learning (via cool noises) about how PCM actually works rather than things that didn't work how you'd expect on a 1980s computer.
(if you've ever heard a space rocket take off, you've heard actual clipping - even with sensors designed not to "clip" themselves sound really does saturate like this eventually, but at a loudness which would permanently deafen humans so you can't experience it directly close up)
Posted Mar 16, 2022 23:15 UTC (Wed)
by milesrout (subscriber, #126894)
[Link] (1 responses)
I'll preface this by saying that personally I found that all the 'real limitations of hardware' stuff was the most interesting thing I learnt about computers. I wish I'd been able to learn about computers back in the 8-bit or 16-bit eras of computing, rather than learning high level languages on a (relatively, but by today's standards obviously not very) modern computer. From a purely personal perspective it was always what interested me the most. Computer programming was relatively uninteresting to me until I got down to that level of detail. I was never really interested in graphical programming environments, or drawing using turtles or whatever. It got interesting when we got into the low level details. That's when it came alive.
BUT I have to agree that if someone _has_ decided to introduce children to computers using a high level language like Python (which clearly suits some children, even it it didn't suit me), then he has clearly chosen the high level route, and the consistent, congruent, sensible thing to do there is to use a relatively high level representation of sound like PCM. If a teacher wished to talk about limited-range hardware integer representations etc. then he probably wouldn't have chosen Python in the first place.
Posted Mar 24, 2022 12:19 UTC (Thu)
by davidgerard (guest, #100304)
[Link]
It's taught in UK schools now. Scratch in primary school, Python in high school.
Posted Mar 17, 2022 9:21 UTC (Thu)
by eru (subscriber, #2753)
[Link] (3 responses)
Posted Mar 17, 2022 11:49 UTC (Thu)
by tialaramex (subscriber, #21167)
[Link] (2 responses)
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".
Posted Mar 17, 2022 12:26 UTC (Thu)
by nix (subscriber, #2304)
[Link]
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...
Posted Mar 17, 2022 19:40 UTC (Thu)
by mbunkus (subscriber, #87248)
[Link]
* sampling frequency (also called sample rate)
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.
PCM
PCM
PCM
PCM
PCM
PCM
* 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.)