Tuning synths in Sonic Pi according to notes

For some time I have tried to make instrumental covers of some of my favourite songs. I tried to produce the notes but could not get the desired results. I think there is some problem with the tuning. Can we tune a synth in sonic pi? Can we even use sonic pi to get the same results as of a normal piano or other instruments?

If You use MIDI note numbers or ’ ABC ’ notation to write your scripts ,
the tuning will be equally tempered chromatic referenced to A 440 Hz .
This closely matches most popular music .
BUT
If the group You are trying to match uses non-standard tuning …
I.E. Ethnic or Just influenced , ( Or has a flat piano :smile: )
You may need to adjust your scales .

#For example ( for Pythagoran tuning ) .......
for frequency in 1..1000
midinote[frequency] = hz_to_midi(frequency)
1 Like

There are some helpers in Sonic Pi to adjust the tuning, so you should be able to get it to work.

If the music is using nonstandard tuning, you can use for example use_tuning :pythagorean, :c to use pythagorean tuning with a fundamental note of middle C (replace with :just or :meantone to use other tuning systems).

If it’s just that the Sonic Pi is slightly sharp or flat relative to the music, you can adjust that with use_cent_tuning N to adjust the tuning by N cents (increments of one hundredth of a semitone) - so 50 will shift it up half a semitone, or -25 would shift it down a quarter of a semitone.

2 Likes

I’m tracking through the archives for tuning options with Sonic Pi and this bit of code caught my eye. I’m eager to explore floating point frequencies with as many decimal places as my computer will cough up. :face_with_hand_over_mouth:

I’ve been typing hz_to_midi a lot in my quest and my fingers want a shortcut.

Does this code set Sonic pi to automatically take raw frequency inputs (between 1-1000Hz) and convert them to midi notes? Is there a way to set it up globally to take frequency inputs?

ie.

play 256
rather than play hz_to_midi(256)

I’m going to keep typing regardless, but if there’s a work around, I’d love to learn it.

Related: Is there a way to get the logs to print hertz rather than cents?

Hi @onesinglecircle,

there’s no global mode for this, but that shouldn’t stop you from extending the language by writing your own function. For example:

define :play_hz do |freq, *args|
  play hz_to_midi(freq), *args
end

play_hz 300, release: 0.1
2 Likes

Wow. Thank you Sam. It’s hard to write a sentence when you don’t know what words are. I will dig in on these and learn a lot. Onwards and forward.