I like the idea of making a DIY midi saxophone. Just a very basic one to make some noise

I'm guessing the hard part is measuring the breath. You could measure pressure, but if you're simulating a real sax it would have air passing straight through. I'm not sure the pressure would change much?

I added a basic breath sensor to the pastry saxophone. It kinda works! The response of the breath sensor is quite slow - I think I need to use something stretchier than a nitrile glove. It doesn't feel sensitive enough to do staccato notes or anything yet.

I didn't get dynamics working with the USB MIDI yet, but on/off breath control works well

The breath sensor works like this guy's video: youtube.com/watch?v=es92GqYBge

The black tape all over it is to block out light - I found it was making a big difference to the readings.

Some quick sketches for a 3D-printed version of the mouthpiece. I can sandwich a membrane between two halves and make the whole thing a lot smaller.

The volume of air inside is smaller, and I'm hoping that means that the response to changes in pressure will be faster, enabling me to do quick staccato stuff.

Here's a first draft of the mouthpiece half - this should work ok. The other half with the sensor should be quite simple and can wait until tomorrow.

I've started printing the mouthpiece and designed the sensor half of the breath sensor. This uses a TCRT5000 IR reflectivity sensor, which shines at a diaphragm clamped between the two halves.

When you blow into the mouthpiece, the diaphragm expands towards the sensor, increasing the amount of IR that's reflected back into it.

Aaaand version 1 of the electro-sax mouthpiece is sort of assembled! It seems like it'll work but I won't be able to test it until the actual sensor arrives at the end of the week.

Electro-sax is just a way cooler name than midi sax

Dynamics now work! I'm using the breath velocity value from the cardboard breath sensor to set the MIDI breath controller value, and mapping that to volume in the synth. I'm sure there's a much more complex and nice-sounding config that can be done, but this is cool!

It needs to be a bit more linear, but that just means making some sort of calibration curve for the sensor. That can wait until I've got the 3D printed one working.

I've put the code up on gitlab.com/gbrnt/electro-sax

There's currently a latency problem - I need to check whether it's on the Arduino end or on the computer end. The breath sensor has some extra latency - I think that comes from the current prototype but I'm not entirely sure.

The end-to-end latency of the electro-sax is definitely too high right now. It's recommended to get it below 10ms (if you can) and here it is at 160ms.

That's enough that when you're doing something like a run of short notes you do one too many because the sound hasn't caught up yet.

Let's see how much I can improve this just by changing Jack settings. Not sure how Pipewire comes into this.

I got a MIDI app on my phone and connected the electro-sax with a USB OTG cable - the latency is much lower! It's definitely low enough to be fun to play now.

So that means I have to delve into linux audio again. I might just revert from Pipewire back to Pulseaudio just to see what effect it has.

So far in my attempts to improve the sensitivity of my breath sensor, I've managed to make it worse.

The first cardboard prototype had a range of 0.38V, or 77 counts in an Arduino's 10-bit ADC. Ideally it'd be more than 127 for a completely step-free MIDI reading.

The 3D printed prototype got me 18 with the nitrile glove membrane, or 31 with a white balloon. Not great. Hopefully the sensor I designed it for will arrive tomorrow and I'll be able to try it out.

I also got a BMP280 pressure sensor, which should be able to be polled fast enough to get useful readings. That might be an avenue worth pursuing as it can be in quite a small chamber!

Hmm, not doing great with the BMP280 pressure sensor. It works really nicely for detecting a change in pressure, but it doesn't seem to be very good at going back to its original zero point.

So in the screenshot you can see the lows are at different points each time I stop blowing. I assume it's doing something clever, but whatever it is it makes it less useful to me.

The best breath sensor I've built is still the original LDR-based one, with a difference between "not blowing" and "blowing hard" of 77 counts.

I could tell that its response was slow, though. So now I've measured it!

Going from LED off to on, the response time is 30ms. From on to off it's 100ms. Luckily that's the ok way round, and normally it won't be varying by so much.

I'd like it to be faster but it's probably an ok solution for now.

Time for a slightly more scientific test of the TCRT5000 based solution. This is the reflective IR sensor with an IR LED and phototransistor.

So far it looks like I can make this good enough by correctly setting the distance between balloon and sensor, and the LED brightness.

I might also test the effect of changing the (current limiting?) resistor next to the transistor, because I've never really got my head round transistors.

It looks like I found the sweet spot for this sensor. With this setup it's 14-16mm from the membrane. My measurement of the distance is bad so I'll still need some adjustability.

I found it was best to set the current-limiting resistor for the LED so that the "non-blowing" voltage was about 4V - maximising the sensitivity.

Not sure why the distances needed in the datasheet are shorter than mine - they're using a mirror to reflect the beam so I'd expect it to be longer.

I tried changing the resistor on the phototransistor and it didn't have much obvious effect on the max breath sensitivity, so I'll probably leave it at the original 4.7K.

The electro-sax now has transposing! You press a key combination to activate transpose mode, and then play the key you want to transpose to. So if I want to play alto sax music in the right key, I play Eb and then press the octave key to lock it in. It seems to work well!

It needs a few octave keys so it can play in the correct octave, but that's fine for now - an octave off is still better than attempting to tranpose in my head.

The electro-sax sensor distance tester looks pretty cool. This will let me vary the distance between the membrane and sensor in a more controllable and measurable way than my cardboard prototype.

Look mum, I did a science!

This is using the new sensor distance tester. It made it so much easier to do this experiment properly.

It looks like my previous conclusion was about right - 13-15mm between sensor base and membrane is about the right distance.

The good news is that with that distance, I get a range of ~270 ADC counts between "not blowing" and "blowing as hard as possible". That's great - it can easily be mapped into MIDI's 127 breath velocity values.

Here's the new breath sensor design mounted to the electro-sax cardboard prototype. It's a lot nicer to play! I can do staccato notes now!

Latency continues to be a problem on my computer, but at least I can be sure it's not on the Arduino, as it works fine with my phone.

I tried switching back to Pulseaudio (from Pipewire) to see if that would reduce the MIDI/audio latency I'm seeing with the electro-sax. Haven't measured it yet but it doesn't seem like it made much of a difference.

Hopefully that's an indication that it's not on the (complicated) audio side and instead on the (slightly simpler) MIDI side. Better not be something fucky with USB.

Just to compare audio latency, I'm trying out a live USB of Ubuntu Studio. It looks like without doing anything, that cuts my latency from 150ms to 93ms. And changing my headphones to my front panel output instead of my USB DAC cuts it further to 24ms.

That's still not amazing, but it's a world of difference from being unable to play properly.


Switched back to the Arch install and changed headphones to the front panel output instead of the DAC. I got ~60ms latency. Still playable.

So why is the Audioquest Dragonfly's latency so bad?

· · Web · 2 · 0 · 0

Some more progress on the updated breath sensor. It's still quite bulky, but at least with the longer mouthpiece I won't be bumping my nose into it!

Will try this for a while before deciding whether it needs a fake reed - the positioning of the air inlet might be enough to make it feel close enough to a real sax.

The sensor holder is supposed to stay clipped to the body of the sax, while the rest can be unclipped for cleaning.

The actual clips are not very well designed for 3D printing in terms of layer orientation, so we'll have to see how that goes. They may not be very durable.

Ok that didn't last long!

Might just make it screw on instead in the next version because that's easy

There's something weird going on with the new sensor - when blowing gently the reading from the sensor actually goes down!

Here's a graph of the readings as I gradually increase from not blowing to full speed. It dips down at the start. That's not good!

I'm guessing it's because I added a slight "bypass" between inlet and outlet, and the flowing air has a lower pressure that actually pulls the balloon towards it.

For reference, here's the previous sensor. You can see because the air *must* move the balloon to flow from inlet to outlet, there's a significant jump when I start blowing.

I think that's the better way to go!

I spent a bunch of today trying out different combinations of software and hardware to figure out the best latency I can get.

I'm really not sure how to present the info so here's a table. It looks like I can get latency as low on Arch as I can on Ubuntu Studio (without tweaking Jack). The lowest latency synth is Yoshimi, but Qsynth is good. Pulseaudio seems to be lower latency than Pipewire.

I suspect a good chunk of the remaining latency could be on the Arduino side, so I'll have to measure that next.

New electro-sax breath sensor is attached. It looks pretty good but unfortunately it's kinda bad :(

It has the thing where if you start blowing suddenly the note is really quiet. I'm really not sure why. Got to figure out the actual cause.

The feel of the mouthpiece is good, but I need to be able to twist it to an angle for it to feel right. Aligned with the sax means I need to twist my head.

Maybe this is the cause - the response is really non-linear. It jumps very slightly above the 0 point, then sits level as I keep blowing more, then suddenly jumps up before increasing linearly.

The other graph is me playing a piece - it looks alright to be honest, so maybe it's not the non-linearity, it's something in my program?

Taking a break from breath sensing to try out the Teensy. The built in touch sensing is very neat!

I might use this with an analog multiplexer to make a touch-sensitive version of the electro-sax

A bit more playing around with touch sensing on the Teensy. It's a little stripboard keyboard which can only play a C arpeggio! It only uses one touch sensing pin along with a 4067 analog multiplexer to get 16 touch inputs.

That's enough for all the keys currently on the electro-sax, plus two more octave keys and... I dunno, two more to do something.

It didn't take long to build a touch-sensitive version of the electro-sax! This is definitely nicer to build than soldering a key matrix with diodes, but the analog sensors aren't quite as nice to deal with on the code side.

The key thing is that it works! I'm not actually sure whether I prefer the buttons or the capacitive sensors. I need to tweak the sensor calibration a bit before I'll be able to tell.

On this one I added a second octave key so there's now both "octave up" and "octave down". So it has a way of getting to the lowest notes that would typically use pinky keys. It's still missing the high end that's normally done with your left palm, so maybe it needs a third octave key.

I'm not convinced by the touch buttons on the electro-sax, and I had a few microswitches laying around, so what about using those for the keys?

I 3D printed some little button assemblies and a frame to hold 4 of them in place. I didn't try a print-in-place pivot on the buttons - instead there's a hole to insert a small bit of filament.

The action of the switches is quite smooth, and maybe low enough pressure to be usable. It's worth a try.

Deleting and redrafting lost the images the first time >:(

I'd post the switch assembly design from FreeCAD, but it won't start properly since the last update.

Recompiling FreeCAD got it working again. Here's a cross-section of the button holder design. The pink and green parts are printed in one go, the grey part is the microswitch.

There are a few issues with this design. It's a little scratchy where the layer lines of the two parts rub together, and it varies from print to print.

The microswitch is mounted to stripboard glued to the bottom, which is not great because the glue is all that stops it falling off. Ideally it would be held by some plastic.

Show newer

@gbrnt USB protocol overhead vs. built-in being right on the PCI bus?

@ieure 100ms difference is a lot though! I bet it's something you can configure some things to minimise but it's way over my head

@gbrnt Looks like you made a snap on that part, correct?

@gudenau Yeah, it was supposed to snap *on* and instead it just snapped.

@gbrnt It does look like you put the force for that against the layer lines instead of with. But with that shape you can't really do it with. Layers are often the weakest parts of prints because of the inter-layer adhesion.

Happy hacking!

@gudenau Yeah, I was aware of that when I designed it but didn't want to put more effort into it to make that a separate part with the layers in the correct direction. For now I'll just put a rubber band around it to replace the clips!

@fortifieduniverse Yeah, tbh I can't tell much difference between 23 and 50. Apparently a good drummer can detect latency around 5ms! Luckily I'm not a good musician ;)

@gbrnt What were you using for physical switches?

Keeping in mind I'm not a musician (one of the skills I've always wanted but could never quite wrap my head around), but I'm imagining having your fingers on the buttons then pushing them in would be a more intuitive experience than hovering your fingers over the buttons and tapping.

@sj_zero I was using some leftover Gateron Brown switches from building keyboards. Their travel is a bit long for this use-case, but the feel is pretty good.

You're right on the hovering being a bit weird, but it looks like it's not uncommon to use capacitive buttons for this and people do get used to it. I guess it makes it operate a bit more like a recorder.

I'm thinking it would be good to find some switches with quite a short throw and low activation weight.

@gbrnt Random trivia, one of my early 3d printer projects was trying to replace the home switches with cherry switches.

I was successful, but what I learned is that while cherry switches are very nice keyboard switches, they make terrible limit switches so I returned to standard limit switches.

I know it sounds sort of crazy, like "why would anyone even try that?" but my first printer wasn't very good and playing with it trying to improve the prints was a lot of fun

@sj_zero Haha I guess it was worth a try! Limit switches are definitely something I'm considering - it might just be a bit hard to nicely attach buttons on top. The light force needed to activate them would be pretty nice!

Show newer

@fortifieduniverse Thanks! It's not a clear upgrade so I might go back to switches, but it could just be a matter of getting used to it.

@gbrnt Indeed. Love watching you iterate, though. Cool stuff.

Thinking about building my own keyboard controller someday... like mill all the keys from hardwood and build my own keybed and such. We'll see. Have a lot of stuff I need to build before that.

@fortifieduniverse This little macro-pad's wooden keys are quite neat! hackaday.io/project/179512-cus

Looks like they used laser cut layers and sanded them to shape. Routing would probably be an improvement.

Show newer

@gbrnt I haven't been following your story that well, but how are you sensing the breath? I have a couple of IST MEMS thermal gas flow sensors, if you want to give one of them a try I could mail one.

@uglyhack They sound pretty cool! I think what I have works well enough and is very cheap, but thanks for the offer!

Essentially your breath inflates a rubber membrane. An IR LED shines at the membrane and is reflected to a phototransistor. When you blow harder the rubber gets closer to the LED and so the reflection detected by the phototransistor is higher intensity.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!