Way back when it was courageous to remove 3.5mm jacks from phones I got myself a pair of earbuds I liked a lot. They were the Libratone Q Adapt in-ear earbuds. They worked really well for me. I prefer earbuds to the bulkier over-the-ear headphones. They used a USB-C connector so they worked with modern phones and I didn't have to deal with Bluetooth pairing or charging batteries. Best of all, even in such a small package they had active noise cancellation which was especially great when listening on airplanes.

Recently, I've started spending more time using Macs and iPads, while before all my devices were Android, Linux, or Windows. "This will be fine," I thought, "after all, it's just USB audio." And my earbuds did play audio, THEY DID SO AT 100% VOLUME ALL THE TIME! Needless to say, while they technically worked, they weren't usable in practice.

But recently it hit me: I can probably make these work. I was right! My earbuds are now running patched firmware that supports volume control when connected to Apple devices.

Here's how I did it.

The ProblemπŸ”—

USB Audio1 is a very flexible protocol which also means its very complex. When you plug in a device, your computer (or phone, iPad, whatever you plugged the USB thing into) asks the device "What are you" and then the USB device returns a bunch of metadata explaining all the things it can be. Headphones aren't just headphones though. My earbuds had an audio output device2, an audio input device for the built-in microphone, and then buttons for volume up, volume down, and play/pause.

My Apple devices understood all this. I could push the play button and media would play. I could push the volume button and the volume slider would appear on screen. The problem was, the slider was empty.

To figure out the reason, I plugged in an official Apple 3.5mm to USB-C adapter and queried what kind of device it looked like. It had one more device called a functional unit. This is a device inside the adapter that can apply functions to the audio stream before it's sent out to the headphones that are plugged into it--functions like adjusting the volume.

The way Apple devices expect volume control to work is that you press the volume up or down button, which tells the host "I want to adjust the volume." The OS then asks the functional unit to increase or lower the volume accordingly. But since my Libratone earbuds didn't have this functional unit, the empty volume slider popup was basically telling me "you want me to adjust the volume but there's no volume control to change."

So why did my other hosts work? They had a fallback mode for devices that can't adjust their own volume and would instead scale the audio samples before sending them to the headphones. Basically, on-host software volume control. For some reason, Apple OSes lack this fallback.

We have the technologyπŸ”—

I got to thinking, what if we could make the earbuds implement the same protocols Apple devices expect? Given that they are already doing complex signal processing for the noise cancellation feature, surely they had the ability to also adjust the volume. The problem was just that they weren't telling the host that they had the ability to do this. USB is generally just software though, so in theory we could update the on-device software to expose the volume control interfaces that Apple expects.

What are we working with?πŸ”—

The first thing we had to find out was what hardware we had and whether the firmware was updatable. In a perfect world, Libratone would have already published an updated firmware that I could have just flashed. Libratone did not. Instead they went out of business.

Despite this, the Libratone app was still in the Google Play Store. I installed the app, plugged in my earbuds, and saw what I could see. I had to create an account for some reason, but then I could see that my earbuds were running firmware version 72. Presumably that means there are up to 71 other versions and more importantly, the firmware is updateable. Unfortunately, I couldn't find a "check for updates" button.

So I had Claude pull the APK off my phone, decompile it, and work out how firmware updating works.3 Claude confirmed that yes, the firmware is updateable, and that the protocol to do this was pretty simple. In fact, based on the Libratone's vendor ID, it seemed like we were likely dealing with some kind of Atmel microcontroller.

Finding the firmwareπŸ”—

The next step was to grab the firmware my earbuds were running already so we could modify it. The way the Libratone app does firmware updates is it makes an HTTP request to basically say "I have version N, is there anything newer?" and then the server responds with either "you're all up to date" or "here's a URL to download the new firmware from." I had Claude write a small script that would log in with my Libratone account and check for any updates.

And this was the point where Opus 5.5 decided I was being too sketchy so it switched me to Opus 4.8. Oh well, 4.8 is still plenty smart enough to do this.

The Libratone app actually checks an https://audiogum.com URL for updates, which is apparently a company that specializes in writing firmware and such for smart devices. Luckily, they are still in business, so the update check worked. At first we told it we had firmware 72 and it said there was nothing newer. Good to know--it means the easy option of just flashing to an already-fixed version was not an option.

So then we said we had an older version and the server dutifully told us where to download the firmware. We downloaded the firmware and now we could really find out what we were working with.

Understanding the firmwareπŸ”—

At this point I decided we were done with all our sketchy stuff so I had Opus 4.8 write a handoff prompt and we switched back to Opus 5.5. I suspect 4.8 would have been fine but 5.5 is a much more capable model in my experience so why not?

Opus disassembled the firmware and then we were able to get a really clear idea of what hardware we had. The main microcontroller seemed to be some version of a SAMG55, which is a 32-bit Cortex-M microcontroller with a floating point unit. The audio portion was powered by a ADAU1777, which has a DSP, 2 DACs (which let it output stereo audio), and 4 ADCs (which give us four audio inputs). The chip seems very focused on noise cancellation. I'm guessing it used one audio output for each earbud, and then also had one microphone in each earbud (using two of the analog inputs) for noise cancellation as well as a third microphone to use as the microphone input that the host device saw. It sounds like a pretty cool chip!

Patching the firmareπŸ”—

While it was tempting to rewrite it in Rustℒ️, Claude suggested a more prudent path. The idea was to leave the firmware almost as unchanged as possible and add a small routine that did the volume stuff (which we wrote in Rust, of course).

The idea is to keep everything working as close to stock as possible. In particular, noise cancellation sounds complex and I didn't want to mess with that. Instead, we added a few patches to the existing firmware that would jump to our code to let us intercept the new things we care about. For example, when it handles the device enumeration request, we patched that routine from the original firmware to jump to a version we wrote that extends to existing USB tables with the new functional unit. Handling the requests to change the volume worked similarly.

The thing that was interesting to me is the way we actually applied the volume changes. I assumed we'd talk with the ADAU1777 chip and adjust its gain. That probably would have been fine but Claude suggested an even simpler version: when we receive audio samples from the host, go ahead and apply the volume scaling there.

This had a few neat properties. First, it's simple--basically just a simple multiplication. Second, it came early in the chain which meant we didn't have to think about how it'd interact with noise cancellation--it effectively looked the same to the rest of the signal processing chain as if the host device had applied the volume scaling before sending it to the earbuds. Third, we actually in theory get a bit more resolution because the first thing the firmware did when receiving a 16-bit audio sample was scale it to 32-bit, so we applied the volume adjustment on a 32-bit sample instead.

Safely flashingπŸ”—

With all this done, Claude was able to generate a patched firmware. The next question was how to manage risk in flashing it. It was low, but since Libratone is no longer in business I couldn't exactly go out and buy a replacement if I bricked the earbuds.

Claude was particularly worried that the bootloader might refuse to boot if it the firmware wasn't signed. I pointed out that we'd seen nothing in the update protocol about sending a signature and there was nothing in the disassembled firmware that looked like a signature. We had no evidence of there being a signature at all to check so this didn't seem like a thing we needed to worry about.

To manage the risk, we settled on a scheme where we'd have a flag that disables all our new functionality until you flip it. This meant when we flashed the firmware everything would be have the same until we sent a special command to enable our new control. This let us isolate some of the things taht could go wrong.

The other thing it let us do is add some code to dump the bootloader. See, the microcontroller starts by booting to the address 0x004000000 but firmware gets flashed to 0x00408000. This difference means there was 32 KiB of space for code between where the microcontroller starts and where our firwmare kicks in. Claude inferred that this was where the bootloader and flashing code lives so after we successfully flashed our first modified firmware, it also added some code to let us dump that range which was not in our firmware file.

This meant we could verify the flashing behavior for sure, like whether there is a signature check, whether it has built in roll back capabilities, etc. This bootloader also meant it was unlikely we'd flash something that broke the device so bad would wouldn't be able to restore the original firmware because all the flashing code runs before the custom firmware starts.

Everything worked well so then we flashed the final modified version which made the on-device volume control enabled unconditionally. I plugged the earbuds into my iPad and low and behold I could control the volume on them!

ReflectionsπŸ”—

This in a lot of ways feels like overkill to fix what is in a lot of ways a minor problem. Of course, it was also a problem that made the earbuds basically unusable in my current lifestyle. I could have bought some other earbuds but unfortunately ones with exactly this feature set seem quite hard to find.4 Still, it was a fun excuse to do some hacking and learn some things.

It's also a chance to reflect on how LLMs are changing my world.

I don't think this project is one I would have attempted if I had to code it manually. It would have been hours or days of messing with toolchains, reading USB documentation, datasheets, etc. With LLMs, the whole project was about two hours end-to-end5 and it only used about half of my five hour usage window on the $20/month Claude Code plan.

There's a question of whether I learned anything. I feel like I did. I wrote this post without the assistence of LLMs, or even spell check (other than reading over my thread transcript in Delta to recall some of the details here and there) so you can judge for yourself how much understanding I showed. I think it's correct at a high level but my explanation about functional units is imprecise at best.

One thing that struck me was how many of the key decisions were suggested by Claude. I had enough understanding to be able to evaluate them and I did push back on the signature paranoia, for example. Still, the solution we ended up with I think is better than what I would have come up with on my own.

The other thing that struck me about this experience is how far LLMs have come. About two years ago I was doing some work with Rust on a Raspberry Pi Pico 2. At the time, LLMs were able to help me find the right documents to read about USB and such but they were somewhere between useless and actually detrimental when it came to writing embedded Rust. On the other hand, this Libratone project seemed much harder. We had to reverse engineer a device with very little documentation and make a change to it without source code. Despite this added difficulty, it didn't feel like Opus broke a sweat at all on it.


1

USB Everything Else too.↩

2

Two channels, in fact, so you can do stereo audio.↩

3

Full disclosure, Claude had been helping me out through most of the other steps in this post too.↩

4

I'm sure some helpful person on the Internet will gladly point out sixteen different options and one of them might actually meet all my requirements.↩

5

Honestly, I've probably spent more than that on this write-up, but I'm not a fast writer.↩