Email or username:

Password:

Forgot your password?
Hector Martin

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++)
// process sample

They did this:

for (int sample = 0; sample < 127; sample++)
// process sample

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.

97 comments
jackson

@marcan why not 2 images instead of a video switching back and forth between 2 images?

Hector Martin

@jacksonchen666 Because then it's much harder to see how perfectly they overlap.

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.

ivabus

@marcan It is present on Sonoma, I'm hearing it right now

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.

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.

gudenau

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

Gabe Salkin

@marcan can you submit a bug fix to Apple? Raise a feedback?

mort

@gabesalkin @marcan Nobody can submit a fix to Apple, this stuff isn't open source. Best one can do is submit a bug report and hope it reaches someone who can do something about it.

gregorni

@marcan I feel like this happens frequently in Asahi Linux, that the solution you few people come up with is better than the one by the trillion-dollar company, or that you catch mistakes that they don't.

Seriously impressive!

palenque laser codes

@marcan what does it sound like when you listen to music rather than pure tones?

Hector Martin

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

palenque laser codes

@marcan sounds like it'd be pretty hard to stumble across unless you're very attuned to things like this

Diego Elio Pettenò

@beka_valentine @marcan you or me might find it unlikely to stumble across, but you'd think those who are developing the DSP it would at least be running this kind of tests.

(Although who knows? They may just have bought this firmware from a contractor.)

Gen X-Wing

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

Manic Pixie Dream Grandpa

@marcan To be fair, as a person not into music, one just sounds louder than the other. But I understand you are saying Apple sound pros should have caught this. (listening on a macbook air m2)

Ogi

@marcan out of curiosity what library did you use to generate those plots?

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

Sei Kay

@marcan If so I have contacts at Apple I can forward this too

Alexeyan

@marcan Is this something only on M2 chips or are earlier models i.E. M1, M1 Pro, etc. also affected?

Hector Martin

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

sean_ae

@marcan @Alexeyan @chadmed fwiw I can't repro on a 16" M2 MBP
thank god

Hector Martin

@sean_ae @Alexeyan @chadmed Yeah I expect those to use ~identical processing to 16" M1. 15" MBA I'm curious about, it could go either way.

sean_ae

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

Hector Martin

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

sean_ae

@marcan oh my, that's so fking embarrassing 😆

Ferrichrome

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

Hector Martin

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

sean_ae replied to Hector

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

penguin42

@marcan HTH did you figure out that was the reason for the distortion?

Hector Martin

@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")
signal[::128] = 0
wavfile.write("lol.wav", fs, signal)

And the rest is history.

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

Sobex

@marcan 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 !

Sobex

@marcan How would apple stuff rate with this bug fixed ?

Hector Martin

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

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

syn

@Sobex @marcan I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I love nonfree software I lov

Man2Dev :idle:

@Sobex @marcan the only way somthing like this would ever get fixed is if bunch of people made big deal out of it in x (twitter) and some how I doubt that will happen.

smfr

@Sobex @marcan The first step would be filing a bug report via Feedback Assistant. Has anyone done that?

slyborg

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

officeplant

@slyborg @marcan yeah but this is part of the work of them making sure we can safely use the onboard speakers in Asahi.

Peter Bindels

@marcan What causes the parallel lines to the main frequency?

Hector Martin

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

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

Peter Bindels

@marcan Yes.

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

Peter Bindels

@marcan Look to be 50Hz above and below the frequency. Interference from mains?

Hector Martin

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

chaos ΘΔ& (it/he)

@marcan i've implemented the exact same bug before in audio processing code
this is why i hate for loops when i cant .iter() and make sure i cover all samples/items, so easy to accidentally do this

RealGene ☣️

@marcan
I was taught:

for(int sample = 0; sample < 128; sample++) {}

…because the actual number of iterations is right there in the test…

skye 🏳️‍⚧️ he/him

@marcan hahaha i hope they give you money for discovering and diagnosing this

Hector Martin

@skye Sadly they only pay for security bugs. But hey, @lina found one of those and got $150k for it 😉​

Chris Lilley

@marcan *laughs in Web Audio*
Accurately counting to 128 is advanced stuff, now?

gregorni

@marcan
> the bar is so low it's buried underground for just about every other laptop

What a line! 😆

Sadly, it's so true though…

bipolaron

@marcan wow, that's some incredible deduction, amazing work!

Chairmander

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

de_maulwurf87

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

Hector Martin

@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

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

justpeachy

@marcan 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 ❤️

Ian Ollmann

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

Pauliehedron ✅ :donor:

@iollmann @marcan


A trillion credit company can walk and test their own products, and not rely on the general public.

Please do not waste my time.

detlev

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

Hector Martin

@detlev They don't pay bounties for non-security bugs.

Brian Reiter

@marcan people who live in the house of Pulse Audio should not throw stones.

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.

iquanyin

@marcan iphone, ipad, and mac os: all riddled with bugs,
some going back ten years. not obscure stuff either. mail, imessage, safari, reminders, autocarrot, weather, lock screen, and on and on and on. “it just works” is apples “don’t be evil.”

Jacobo Tarrio

@marcan (Apple Pencil scribbling sounds increase.)

DELETED

@marcan QA by experts in the domain is considered old school. This is a result.

Adam Beer

@marcan 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:

Robert Cassidy

@marcan This is why you unit test. Easy code mistake to make, easy code mistake to catch.

Marius Kießling

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

DELETED

@marcan
The most mysterious post I ever read.

In vain.

keyshooter :revblobfoxgooglymlem: :bocchi_anxious:
@marcan in all fareness.... i once inverted the if condition when i shouldn't 💀 making the wrong condition is more likely than you think, also, since you are an audio expert ofc you will notice this one out hehe
StarkRG

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

Bill Zaumen

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

argv minus one

@marcan Another fine reason to Rewrite It In #Rust ™: iterators prevent a lot of off-by-one bugs.

Go Up