OH MY FUCKING GOD.
Pictured: Apple's M2 MacBook Air 13" speaker response (measured with a mic), and the response you get when you zero out every 128th sample of a sine sweep.
They have a stupid off-by-one bug in the middle of their bass enhancer AND NOBODY NOTICED NOR FIXED IT IN OVER A YEAR.
So instead of this (for a 128-sample block size):
for (int sample = 0; sample <= 127; sample++)<br> // process sample<br>
They did this:
for (int sample = 0; sample < 127; sample++)<br> // process sample<br>
Legendary audio engineering there Apple.
We can now, very confidently say the audio quality of Asahi Linux will be better than Apple's. Because we don't have blatant, in your face off-by-one bugs in our DSP and we actually check the output to make sure it's good 😂
FFS, and people praise them for audio quality. I get it, the bar is so low it's buried underground for just about every other laptop, but come on...
Edit: replaced gif with video because Mastodon is choking on the animation duration...
Edit 2: Update below; I can repro this across a large range of versions on this machine but none of the other models I've tried so far. It is definitely a bug, very very obvious to the ear, and seems unique to this machine model.
Edit 3: Still there in Sonoma, this is a current bug.
reshared this
Hector Martin
in reply to Hector Martin • • •Hector Martin
in reply to Hector Martin • • •Tested 12.4 and 13.5 on M2 MBA, sounds just as bad, so this has been going on for a *long* time now.
M1 MBA does not have this problem, nor does M1 MBP 16". This might be an M2 MBA specific problem. It is very, *very* obvious if you just play a 300Hz sine with any random frequency generator website and crank the volume up.
Upgrading to Sonoma now, but I doubt they fixed it... it seems this has *always* been broken on at least the M2 13" MBA.
Edit: Still there in Sonoma.
Hector Martin reshared this.
Hector Martin
in reply to Hector Martin • • •The thing about this bug is that it makes me confident that we can do better, not just in terms of not making this mistake.
When you're doing DIY DSP like this, it's always hard to objectively be confident that you can do a decent job vs. a company with many more employees and resources (e.g. to run high quality tests, user studies, etc.); after all, we're not psychoacoustics experts here, there could be some real "magic sauce" to Apple's DSP that we can't reproduce.
Anyone can make this kind of mistake while writing DSP code, but the fact that nobody caught this before launch, never mind in over a year in the wild, makes it evident that Apple's audio engineering team is, at least on some level, incompetent (or incompetently run; I'm not blaming the employees here, but rather the organization). This is both obvious to the ear side by side with other machines, and obvious in a sine sweep frequency response test, which is the most basic test you can run end-to-end on a completed audio system to ensure it is performing properly. So they didn't even run that. Or they ran it, and didn't notice this. Which is nuts.
So now I feel a lot more confident that the less over-the-top DSP we're aiming for in Asahi is going to be competitive, because clearly Apple's audio team aren't audio geniuses with dark knowledge we don't have. At least on some level they're flailing around with open-coded time domain DSP and aren't running any serious analysis on the result, because anything would've caught this, especially in contrast to it not happening on other machines.
gudenau
in reply to Hector Martin • • •Hector Martin
in reply to Hector Martin • • •For those curious about how I figured out exactly what the bug was:
https://social.treehouse.systems/@marcan/111160552044972689
Hector Martin
2023-10-01 15:50:15
Gabe Salkin
in reply to Hector Martin • • •Sei Kay
in reply to Hector Martin • • •Doug Wyatt
in reply to Sei Kay • • •Hector Martin
in reply to Doug Wyatt • • •quickexplained
in reply to Hector Martin • • •Alan Zeino
in reply to Hector Martin • • •@dougsonos @seiKay
“don’t take it personally” yeah but we all saw that first post
Torstein
in reply to Hector Martin • • •Hector Martin
in reply to Torstein • • •@torsteinv It's harder to notice with complex music, since it only affects frequencies the speakers can't reproduce very well anyway, so a lot of content in higher frequencies will mask it (e.g. you won't notice with pop/rock and things like that). But I looked for stuff like bassoon solos and I'm pretty sure I can hear a weird dissonance that shouldn't be there, caused by this.
See the previous reply for a demo with a pure tone. With that it's so blatant it sounds like old telephone DTMF dial tones (which are designed to sound dissonant).
Torstein
in reply to Hector Martin • • •Matteꙮ Italia
in reply to Hector Martin • • •Hector Martin
in reply to Matteꙮ Italia • • •Hugo 雨果
in reply to Hector Martin • • •Timon 🛠
in reply to Hector Martin • • •noarn chornsky
in reply to Hector Martin • • •Hector Martin
in reply to noarn chornsky • • •noarn chornsky
in reply to Hector Martin • • •Gen X-Wing
in reply to Hector Martin • • •I love how it sounds like some kind of airhorn (boat?). It’s kinda funny in that way.
But it has to be a real bummer for anyone owning an M2 laptop.
encore / undone
in reply to Hector Martin • • •Hector Martin
in reply to encore / undone • • •Torstein
in reply to Hector Martin • • •Kuter Dinel
in reply to Hector Martin • • •Manawyrm | Sarah
in reply to Hector Martin • • •I won't try to make any judgements here, as my ears are too bad for that.
Ogi
in reply to Hector Martin • • •Visne :verified:
in reply to Ogi • • •Hector Martin
in reply to Visne :verified: • • •jackson :ms_agender_flag:
in reply to Hector Martin • • •Hector Martin
in reply to jackson :ms_agender_flag: • • •Alexeyan
in reply to Hector Martin • • •Hector Martin
in reply to Alexeyan • • •sean_ae
in reply to Hector Martin • • •thank god
Hector Martin
in reply to sean_ae • • •sean_ae
in reply to Hector Martin • • •Hector Martin
in reply to sean_ae • • •Hector Martin
in reply to Hector Martin • • •@sean_ae Edited a video into here: https://social.treehouse.systems/@marcan/111160509734332411
Hector Martin
2023-10-01 15:39:30
sean_ae
in reply to Hector Martin • • •Ferrichrome
in reply to sean_ae • • •isithran likes this.
Hector Martin
in reply to Ferrichrome • • •sean_ae
in reply to Hector Martin • • •Hector Martin
Unknown parent • • •penguin42
in reply to Hector Martin • • •Hector Martin
in reply to penguin42 • • •The train of thought was:
numpy time
And the rest is history.
penguin42
in reply to Hector Martin • • •Rickyx
in reply to Hector Martin • • •Hector Martin
in reply to Rickyx • • •Rickyx
in reply to Hector Martin • • •Sobex
in reply to Hector Martin • • •Sobex
in reply to Sobex • • •Hector Martin
in reply to Sobex • • •@Sobex You mean in terms of speaker audio quality? It's still much better than the vast majority of the competition, though as @chadmed said a few times, their DSP is too tryhard (this bug aside).
The drivers are decent, their EQ is reasonably good, the equal-loudness processing is a good idea (we're doing that too), and the speaker safety modeling stuff lets them safely crank them pretty loud. Those things alone are already more than most laptops do by far. Whether the rest of Apple's DSP helps or sounds good/bad is debatable, but those basics already make them stand out.
smfr
in reply to Sobex • • •slyborg
in reply to Hector Martin • • •Peter Bindels
in reply to Hector Martin • • •Peter Bindels
in reply to Peter Bindels • • •Hector Martin
in reply to Peter Bindels • • •@dascandy42 It is aliasing at intervals of 1/128th of the sampling frequency, which is what happens with this kind of bug due to the mathematics involved. Basically you can think of it as downsampling (folding and truncating the spectrum) to 1/128th the sampling frequency (375Hz in this case, which gives you 187.5Hz worth of spectrum), and then copying and pasting and mirroring the resulting spectrum 128 times to fill in the entire original frequency range.
The increasingly angled lines in the real spectrum are the intended result of the filter (harmonics).
Peter Bindels
in reply to Hector Martin • • •Yes.
I mean the two lines around the first harmonic that are parallel to it.
Peter Bindels
in reply to Peter Bindels • • •Hector Martin
in reply to Peter Bindels • • •Ah yes, that's another aliasing-type artifact (and possibly a more audible one). I don't have a simple explanation for that one, but it might be related to the 1/128 bug in some way (maybe a larger block size is involved?).
It's not mains intermodulation, that would affect everything.
RealGene ☣️
in reply to Hector Martin • • •I was taught:
for(int sample = 0; sample < 128; sample++) {}
…because the actual number of iterations is right there in the test…
Hector Martin
Unknown parent • • •Chris Lilley 🏴
in reply to Hector Martin • • •Accurately counting to 128 is advanced stuff, now?
Chairmander
in reply to Hector Martin • • •Since you seem to have a great setup with a reference mic already - mind recording how this off-by-one actually sounds like? As in, how it distorts the ~300Hz range. Spectra are great but I'd love to hear it (mostly to figure out whether I'd have noticed it or not)
If it takes too long, I guess I can call this an excuse to learn more about audio processing and try to replicate this myself
Hector Martin
in reply to Chairmander • • •https://social.treehouse.systems/@marcan/111160509734332411
It's so obvious a smartphone mic is more than enough.
Hector Martin
2023-10-01 15:39:30
de_maulwurf87
in reply to Hector Martin • • •Hector Martin
in reply to de_maulwurf87 • • •@de_maulwurf87 @l_prod No see that's the thing, this is *inharmonic* (out of tune), and that can't happen with a physical process like rattling. I was actually looking *for* rattling/resonances when I noticed this, which is a different (and much more inevitable) problem.
This kind of artifact can only happen with bad/broken DSP.
Chairmander
in reply to Hector Martin • • •That is... wow. I don't know what to say.
justpeachy
in reply to Hector Martin • • •Ian Ollmann
in reply to Hector Martin • • •<Bored Marvin the depressed robot voice>
File a bug report. Complaining on social media doesn’t work.
</Bored Marvin>
…or as we cynically used to say inside Apple:
Radar # or it didn’t happen.
detlev
in reply to Hector Martin • • •Hector Martin
in reply to detlev • • •Hector Martin
Unknown parent • • •Jacobo Tarrio
in reply to Hector Martin • • •Adam Beer
in reply to Hector Martin • • •I don't understand those images or your explanation of the bug (other than the fact that it's an off-by-one error), but that audio demo is about as subtle as being run over by a goddamn freight train.
Jesus Christ
Robert Cassidy
in reply to Hector Martin • • •Marius Kießling
in reply to Hector Martin • • •StarkRG
in reply to Hector Martin • • •Bill Zaumen
in reply to Hector Martin • • •Hector Martin
Unknown parent • • •Yeah pretty much. This DSP needs to be implemented somewhere and PipeWire ended up being the best option. And it does supersede most other frameworks/use cases (PA, JACK, etc.) so there's very little reason not to use it.
Though we switched our users over earlier last year anyway, because PA was broken with headphone jack hotplug and PW worked fine, and it wasn't worth spending time debugging that when we already planned to require PW for the upcoming speaker support.
The speaker safety stuff, though, will be a stand-alone daemon working together with the kernel driver. So if you really want to use PA or anything else, it'll sound (very) bad, but you won't blow up your speakers. If the safety daemon dies or is not present, the kernel will fall back to a very low but safe volume cap.
The Turtle
in reply to Hector Martin • • •...really?
Get real speakers.
Jeez.
stilescrisis
Unknown parent • • •Hector Martin
Unknown parent • • •It doesn't sound like "higher volume", though, it's a very distinct, harsh, dissonant buzz.
What you're describing as "higher volume" is saturation/distortion. Distortion is always harmonic, so although it can sound harsh, it is not fundamentally changing the pitch of the sound.
Here are three tones. The first one is pure, the second one is clipped (distorted), and the third one is what happens with this weird kind of artifact (the actual M2 Air output is actually more broken than this, it's not just this bug, but it's part of it). The third one has a distinct "buzz" that sounds out of tune, like interference from another tone. That's what you get on the Mac. It's a very unnatural, unmusical kind of artifact that sounds very harsh because it cannot be produced through physical processes in real life (no instrument sounds like that).
Hector Martin
Unknown parent • • •@argv_minus_one You can use PA/JACK/ALSA/etc without PW, we just aren't building the DSP processing tooling for those. So if you want your speakers to sound good with something that isn't PW, you're on your own. I actually considered doing the DSP as an ALSA plug-in to make it more universal at one point, but it turned out to be a bad idea for various reasons.
PipeWire provides PulseAudio, JACK, and ALSA compatible interfaces, so apps that use any of those will work with PipeWire and can use our DSP. But you need to actually run PipeWire.
vurpo 🏳️⚧️
in reply to Hector Martin • • •Anton 🏳️🌈 🇬🇷Pappas (he/him)
in reply to Hector Martin • • •Andy
in reply to Hector Martin • • •Michael / マイケル
in reply to Hector Martin • • •eWe
in reply to Hector Martin • • •edit:
Not fine broken too!
I first used 300 HZ like in your text.
If I use the 270 Hz like you did in the video it’s very noticeable distorted too.
plays fine on my M2 MacBook Air 13“ with Sonoma 14.0
Found the very same website tone generator you used.
MBAir plays the same like iPad and not as distorted like in your video - maybe it is an “not all Models” Problem if some hw parts?
Edit:#2
Use 270 HZ not 300 Hz to test.