Skip to main content


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.

This entry was edited (1 year ago)

reshared this

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.

This entry was edited (1 year ago)

Hector Martin reshared this.

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.

This entry was edited (1 year ago)
in reply to Hector Martin

It's a great reminder that a few people hammering away at this stuff can make really good products, for lack of a better word.
in reply to Hector Martin

For those curious about how I figured out exactly what the bug was:

https://social.treehouse.systems/@marcan/111160552044972689


The train of thought was:
  • The aliasing is every 375 Hz
  • 48000 / 375 = 128 so this is some fourier thing with a block size 128???
  • Wait no, this could be time domain, aliasing like that is what you get when you upsample without lowpassing
  • Specifically, when you upsample with zero-sample padding (standard), that is, when one sample out of 128 has the low frequency content.
  • So this is like taking the average of a 128-sample block and adding it to just one sample?
  • Wait, isn't that almost equivalent to zeroing out one sample?

numpy time

fs, signal = wavfile.read("sweep.wav")<br>signal[::128] = 0<br>wavfile.write("lol.wav", fs, signal)<br><br>

And the rest is history.

in reply to Hector Martin

I sent this post to Doug Wyatt of the audio team at Apple. Hopefully something can be done
in reply to Sei Kay

@seiKay Thanks for reaching out. I wrote a bug report (116320900).
in reply to Doug Wyatt

@dougsonos @seiKay Thank you! And please don't take it personally, I'm just very confused as to how this managed to slip through. Apple is still the only laptop manufacturer that cares about audio at all, that's why I hold y'all to a higher standard ;)
in reply to Hector Martin

@dougsonos @seiKay I believe dell and Microsoft also have somewhat decent audio. Correct me if I am wrong though. I know almost nothing about this
in reply to Hector Martin

@dougsonos @seiKay

“don’t take it personally” yeah but we all saw that first post

in reply to Hector Martin

for us without a mba m2, what does the bug sound like when playing music? more "reverb" / echo-y? since it's off by one?
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).

in reply to Hector Martin

thank you for the explaination 🙏🏻 let's hope apples audio engineers are on mastodon, reads your toots and fixes the issue ☺️
in reply to Hector Martin

this feels like sth that just happened at work... iterating on a new DSP pipeline everything gets validated extensively until it's perfect; in successive releases focus shifts to minor improvements, which get a less extensive/more local validation; some algo written for some parm values is shipped in a way different config. A year later it turns out that some inexplicably bad machine behavior is due to these gradual changes, that turned the output of many configs from great to awful.
in reply to Matteꙮ Italia

@cvtsi2sd Yeeeah, that kind of thing tracks. I actually suspect this is broken across the board, but the specific EQ/loudness/compressor/etc profiles for the other machines don't trigger the badness in the bass module for most inputs. Then when they made the M2 Air configs they never ran end-to-end validation, and this happened.
in reply to Hector Martin

Apple sure if lucky to have you working for them and doing some of this QA works!
in reply to Hector Martin

taking bets for how long it will take for this to be suddenly fixed in the next update
in reply to Hector Martin

what does it sound like when you listen to music rather than pure tones?
in reply to noarn chornsky

@beka_valentine Depends on the kind of music. The bug is in a range the speakers don't reproduce very well anyway, so complex full-range music (pop/etc) will mask it. But trying some stuff like bassoon solos, I definitely hear some weirdness that shouldn't be there.
in reply to Hector Martin

sounds like it'd be pretty hard to stumble across unless you're very attuned to things like this
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.

in reply to Hector Martin

Cool find! I noticed that the attack of the sound is longer on M2 too.
in reply to encore / undone

@encore I suspect that might be the different browser or something like that, probably not relevant.
in reply to Hector Martin

okay i heard it now, that's bad.... it sounds like a horn that was beaten up and dented. you're right, it is really weird how this was not noticed and still not fixed 😲
in reply to Hector Martin

Some prople are complaining about the sound in iphone 15. I wonder if there is a similar issue with it https://twitter.com/milesabovetech/status/1708622986981347444
in reply to Hector Martin

Interestingly, iPhone 12 Pro vs. 15 Pro does sound pretty different as well...
I won't try to make any judgements here, as my ears are too bad for that.
in reply to Hector Martin

out of curiosity what library did you use to generate those plots?
in reply to Hector Martin

why not 2 images instead of a video switching back and forth between 2 images?
in reply to jackson :ms_agender_flag:

Because then it's much harder to see how perfectly they overlap.
This entry was edited (1 year ago)
in reply to Hector Martin

Is this something only on M2 chips or are earlier models i.E. M1, M1 Pro, etc. also affected?
in reply to Alexeyan

Cannot repro on M1 MBA or M1 Max MBP 16". This might be an M2 MBA 13" specific problem (maybe the 15" too, need to ask @chadmed about that one since I don't have it).
This entry was edited (1 year ago)
in reply to Hector Martin

fwiw I can't repro on a 16" M2 MBP
thank god
This entry was edited (1 year ago)
in reply to sean_ae

Yeah I expect those to use ~identical processing to 16" M1. 15" MBA I'm curious about, it could go either way.
This entry was edited (1 year ago)
in reply to Hector Martin

@Alexeyan @chadmed I should add though, my adhoc measurement setup was terrible (an iphone running spectrogram pro) so ymmv ;)
in reply to sean_ae

@sean_ae @Alexeyan @chadmed I mean it is ridiculously obvious to the ear, you really don't need tools for this one :)
in reply to Hector Martin

@sean_ae Edited a video into here: https://social.treehouse.systems/@marcan/111160509734332411


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.


in reply to sean_ae

@sean_ae Right? I’m an amateur music producer, and I hear people complain about stuff like this in VSTs all the time, but it’s never anything THIS bad. This is absolutely atrocious.
in reply to Ferrichrome

@Ferrichrome @sean_ae I swear I cannot believe how nobody caught this before me. I guess most people don't have machines to compare side by side and just... assumed it was supposed to sound like that? But what about Apple's entire audio team? WTF?
in reply to Hector Martin

@Ferrichrome yeah it’s pretty weird no one’s noticed but apple not testing dsp code for speaker enhancement *by measuring*? Mindboggling
Unknown parent

Hector Martin
@seiKay I have no idea, this is an older version. I'll check Sonoma. But I somehow feel I'm the first to notice this...
in reply to Hector Martin

HTH did you figure out that was the reason for the distortion?
in reply to penguin42

The train of thought was:

  • The aliasing is every 375 Hz
  • 48000 / 375 = 128 so this is some fourier thing with a block size 128???
  • Wait no, this could be time domain, aliasing like that is what you get when you upsample without lowpassing
  • Specifically, when you upsample with zero-sample padding (standard), that is, when one sample out of 128 has the low frequency content.
  • So this is like taking the average of a 128-sample block and adding it to just one sample?
  • Wait, isn't that almost equivalent to zeroing out one sample?

numpy time

fs, signal = wavfile.read("sweep.wav")<br>signal[::128] = 0<br>wavfile.write("lol.wav", fs, signal)<br><br>

And the rest is history.
This entry was edited (1 year ago)
in reply to Hector Martin

@penguin42 do you think this bug will affect also external audio interfaces?
in reply to Hector Martin

Thanks for the explanation ! Now we just need to find someone at apple who cares enough to pass this one to whoever is responsible for this bug and have it fixed !
in reply to Sobex

How would apple stuff rate with this bug fixed ?
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.

in reply to Sobex

@Sobex The first step would be filing a bug report via Feedback Assistant. Has anyone done that?
in reply to Hector Martin

Maybe this tells you something about the relative importance of the bass response of the onboard speakers of a laptop to the vast majority of laptop customers. I mean, considering the number of enormous security issues that allow full compromise of pretty much any macOS (and Linux) releases, I’m not sure this is really an ALL CAPS kind of issue. 🫤
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).

in reply to Hector Martin

Yes.

I mean the two lines around the first harmonic that are parallel to it.

in reply to Peter Bindels

Look to be 50Hz above and below the frequency. Interference from mains?
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.

This entry was edited (1 year ago)
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…

Unknown parent

Hector Martin
@skye Sadly they only pay for security bugs. But hey, @lina found one of those and got $150k for it 😉​
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

in reply to Chairmander

https://social.treehouse.systems/@marcan/111160509734332411

It's so obvious a smartphone mic is more than enough.


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.


This entry was edited (1 year ago)
in reply to Hector Martin

@l_prod wow, I really thought like, yeah audio people will get this, but that it is this obviouse that something is wrong is crazy. Sound like the speaker is vibrating loosely in the case. That must have triggered someone in QA.
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.

in reply to Hector Martin

I'm currently only on tinny *phone* speakers but it's noticeable.
That is... wow. I don't know what to say.
in reply to Hector Martin

can someone put the first little paragraph in layman’s terms please? I have no idea what this means; I’m not a coder or audio person ❤️
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.

in reply to Hector Martin

Please tell Apple, so they can fix this for everyone! :-) Hope you will get a big bounty for it like Lina did!
Unknown parent

Hector Martin
@breiter PipeWire only here, sorry. We're not even going to support PulseAudio on these machines if you want the DSP to work.
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 :ablobcatknitsweats:

in reply to Hector Martin

This is why you unit test. Easy code mistake to make, easy code mistake to catch.
in reply to Hector Martin

Amazing catch! For Apple‘s sake, I hope that some of their engineers are following you and run this internally to the right team. This is definitely something that would die silently in a Feedback.
in reply to Hector Martin

Apple quality assurance kinda dwindled away some time ago in exchange for shininess and gluing everything together so it isn't repairable.
in reply to Hector Martin

Only a year before anyone noticed? I once reported a bug in YACC - an off-by-one error resulting in a stack overflow - and nobody had noticed it for a good 10 years! The bug was in the generated code, apparently part of a template, and I only found it because I was testing a parser by throwing unusual cases at it.
Unknown parent

Hector Martin

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.

This entry was edited (1 year ago)
Unknown parent

stilescrisis
@sboger The M2 has a distinct harsh buzz. It shouldn't be hard to discern.
Unknown parent

Hector Martin

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).

This entry was edited (1 year ago)
Unknown parent

Hector Martin

@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.

in reply to Hector Martin

They have been advertising Audio QA positions in Munich forever. They may just not have enough people for their release cadence.
in reply to Hector Martin

lol guaranteed this bug becomes part of some EDM producer's workflow and machines that can reproduce it skyrocket in value
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.

This entry was edited (1 year ago)