
Using a Raspberry Pi to Add MIDI to a CV Synthesizer - qrv3w
https://schollz.com/raspberrypi/monotron/
======
daneel_w
And here's a MIDI-to-CV controller built with a $3 microcontroller instead of
a $40 computer:
[https://github.com/elkayem/midi2cv](https://github.com/elkayem/midi2cv)

~~~
XMPPwocky
An Arduino Nano? What a waste... Just use a PIC or an ATTiny. Spending even $1
for something so simple is unnecessary.

For personal projects, it's not often the case that you need to get BOM cost
as low as possible and disregard other factors (like debuggability, or having
enough DSP available to run the FFT for tuning calibration (though I suspect
they'd be better off with autocorrelation...), or room for future expansion
(adding multiple channels, adding a sequencer, adding control over the filter,
implementing envelopes, running the Pi's audio output through the filter
too...)

Plus, they might have had the Pi before, and still have it afterwards. That's
the nice thing about general-purpose computers- you can put a whole bunch of
different software on them, and then switching between uses just involves
moving the board itself and plugging cables in.

~~~
ssalazar
One functional advantage of a microcontroller over a single-board computer is
lower latency due to not having the overhead of an operating system. Also, the
Pi's built-in audio output is basically unusable, but easily replaced.

However if you dont have floating point arithmetic like many microcontrollers,
fixed-point DSP for FFT or autocorrelation presents its own set of challenges,
which can be either a good thing or a bad thing.

------
munificent
This is super cool! Using an FFT to detect pitch is a natural approach, but my
understanding is that most pitch detectors work in the time domain using some
form of auto-correlation. See:

[https://en.wikipedia.org/wiki/Pitch_detection_algorithm](https://en.wikipedia.org/wiki/Pitch_detection_algorithm)

~~~
qrv3w
Thanks for that link, wasn't aware.

For this I used the simplest approach I could think of - using sox [1] with
its builtin power spectrum analyzer. It works pretty well as the resulting
tuning is fantastic. It would be nice to a faster pitch detector - could speed
up tuning from ~15 seconds to maybe just a few seconds.

[1] [https://linux.die.net/man/1/sox](https://linux.die.net/man/1/sox)

------
mxmilkb
Kinda related; software CV done with JACK and LV2:
[https://linuxmusicians.com/viewtopic.php?f=1&t=20701](https://linuxmusicians.com/viewtopic.php?f=1&t=20701)

------
iainctduncan
Nice. :-) Having done somewhat similar stuff before, I'm curious if you were
able to measure what the latency result of using linux and python was vs doing
it with an MCU like a teensy or arduino and using C? I can see advantages to
both approaches, and am genuinely curious. There must be some latency and
unpredictability added, but maybe it's small enough to totally not matter. Off
course whether this matters depends too on the controller keyboard and your
playing level, I know what is ok to me differs from what what my Real Pianist
friends tolerate!

~~~
qrv3w
Thanks :)

I play piano and I don't find the latency a problem, which means its probably
< 100 ms. The midi stuff is actually just bindings to rtmidi (in C++).

The most annoying thing is "jitter" which I calculated to be 15-20 ms, which
is fine, but sometimes there are spikes of 50 -150 ms which are annoying.

~~~
iainctduncan
hmm, have you figured out what the jitter is from? is that from Python maybe?

~~~
qrv3w
When I measured jitter I found that it was higher in cheaper instruments [1],
so I think it might be dependent on the hardware that is listening to the MIDI
output.

[1]:
[https://github.com/schollz/miti/issues/4](https://github.com/schollz/miti/issues/4)

------
turdnagel
Wow! Great little demo. It sounds like there are multiple synths though --
isn't the monotron monophonic?

~~~
XMPPwocky
They are (besides the Monotron Duo, which has a second oscillator (but no way
to play it paraphonically without hardware hacking, you can just tune it
differently)), but this is the Monotron Delay, which has, well, you can
probably figure that out.

~~~
kennywinker
What I'd love to see is if they could use the same tuning system they used
here to tune the delay time and make the monotron delay do some kind of
karplus strong synthesis! That's assuming there are patch points for the delay
time, I guess...

~~~
meatsock
you can accomplish this by automating VR6A on pin 6 of the pt2399. one
oldschool method to add CV control of a potentiometer is to control the
resistance with a vactrol.

------
n-gauge
I created a midi piano in the browser for a Roland EP7 IIe that sent midi note
off in a weird way - causing double notes , it would send the same note but
with just the velocity information changed to 0, which most midi software
didn't like.

[https://htmlgames.github.io/htmlgames.github.io/htmlgames/PF...](https://htmlgames.github.io/htmlgames.github.io/htmlgames/PF_MIDI_PIANO/midi-
js_Basic.html)

So I just held the notes in an array and used that for note on/off information
instead.

~~~
ssalazar
Sending a noteOn with 0 velocity instead of noteOff is surprisingly common
among MIDI keyboard implementations, so Im surprised that a lot of software
wasn't handling it well.

~~~
PaulDavisThe1st
It's not just common, it is part of the MIDI specification and deliberately
done that way to allow running status, an optimization that was important in
the days of (true) serial MIDI.

------
elric
This is great. And miti is exactly what I was looking for. Started working on
something similar in bash and perl on top of gbevin's sendmidi [1] a while
ago, but this looks like it'll save me much effort. Thanks!

[1] [https://github.com/gbevin/SendMIDI/](https://github.com/gbevin/SendMIDI/)

~~~
qrv3w
Thanks! That's a neat solution! If I had seen that before, I may not have made
miti :)

I found there's other few programming-friendly simple MIDI sequencers [1] but
generally none of them were simple enough for me. I'm pretty happy with the
simplicity and power behind miti and use it quite a bit for my own purposes.
Feel free to ping me if you have issues with it or ideas to improve it!

[1]: [https://github.com/schollz/miti/#other-similar-
work](https://github.com/schollz/miti/#other-similar-work)

------
jacquesm
Brilliant trick to self calibrate, these are probably each different enough
that if you hooked up another one to the same PI it would come out all out of
tune.

~~~
qrv3w
I would love to hook up multiple - the polymonotron...

