tidalcycles / strudel

Web-based environment for live coding algorithmic patterns, incorporating a faithful port of TidalCycles to JavaScript
https://strudel.cc/
GNU Affero General Public License v3.0
684 stars 120 forks source link

Tonal MIDI is C4-based notation while Tidal is C3 I think. #339

Open dbadb opened 1 year ago

dbadb commented 1 year ago

Reading through Tidal docs, the default base-pitch of a sample is C3 which is also supposed to be middle C (note 60). It appears to me that the Tonal package operates with C4 as 60 and this means that some things are off by one octave.

In the case of the base-pitch example here, the unspecified base-pitch for gtr produces a different result than when specified as 'c3'. My reading of the docs suggests that this is a bug.

If Strudel adopts/adheres-to the C3 convention (which is the more common one imho), then one would need to uniformly add 12 to all note-numbers coming out of Tonal. Perhaps ideally the convention could be a configuration option for Tonal. A quick glance at the webaudio/sampler code shows calls to core/utils.js:toMidi which appears to produce octaves starting at 1. The sampler code corrects for this by subtracting 36 (3 octaves) which seems about right I think.

felixroos commented 1 year ago

yep, it seems the guitar sample is playing at c4 when typing c3... i can do some further digging tomorrow

pd3v commented 1 year ago

I recorded those three samples as guitar middle C. In ableton live it's MIDI C2 (48). If you find interesting to add that to their file names, I can PR.

felixroos commented 1 year ago

Let me bring order to my mind and this issue. These are the different concepts / units at play:

  1. Note names
  2. Frequency in Hz
  3. Midi numbers
  4. "Middle C" position on the piano
  5. Default sample pitch

1-4 are clearly defined in in scientific pitch notation / international pitch notation (IPN) (https://en.wikipedia.org/wiki/Scientific_pitch_notation)

This mapping can be checked in strudel with

So, as suspected, the problem has to do with sample pitch mapping.. Ableton Tuner detects the gtr sample gtr/0001_cleanC.wav as 130Hz = C3 = midi 36

When explicitly declaring that pitch of the sample:

samples(
  { gtr: { c3: 'gtr/0001_cleanC.wav' } },
  'github:tidalcycles/Dirt-Samples/master/'
);
note("c3").s("gtr");

.. it works, as it plays back normally (without repitch). The actual issue occurs only when no pitch is declared:

samples(
  { gtr: 'gtr/0001_cleanC.wav' },
  'github:tidalcycles/Dirt-Samples/master/'
);
note("c2").s("gtr");

this will play the sample as is without repitching.. so basically the default pitch is c2. The sentence If a sample has no pitch set, c3 is the default. is an error in the docs. I'd say let's change that default pitch to use c3 or even c4 (middle c).

Let's now look at how tidal does things:

Things to note:

My opinion:

same for strudel

This confusion could be resolved by not allowing n to control synth pitch.. The docs should also be enhanced at https://strudel.tidalcycles.org/learn/notes/ where n is explained as the general solution for numeral pitch (which it is not for samples + it is not explained that you can use numbers with note as well)

dbadb commented 1 year ago

Hi Felix - I think all of this sounds great. I wasn't aware of the Scientific pitch notation (SPN) and had been relying on other resources to convert note names like C4 to MIDI note numbers. here and here are two discussions of this.

While the second source claims that the C3 convention is the more common, the fact that it's not a reliable standard is a real problem. The Ableton thread implies that they've adopted C3 too. Sadly this lack of standard will likely be the cause of many misunderstandings. The post above from @pd3v supports the idea that Ableton is on the C3 convention. The good news is that MIDI note 60 is unequivocally middle-C, so I'm a bit confused by pd3v's statement that he recorded it on guitar middle C and then describes it as note 48 (C2). Certainly C2 is note 48 in the C3 convention but it's not middle C. Just an example of the confusions to come.

Since both the SPN and Tonal have settled on the C4 convention I agree that it's the right one.

On your other points:

As an aside:

I've been working on integrating Strudel-over-OSC with Fiddle and ChucK... Things are going quite well. Strudel is cool!

pd3v commented 1 year ago

Hey! @dbadb, I guess "guitar middle C" is guitar's lowest C (48). Just "middle c" (60) has to do with concert pitch; it is the C (60) in the octave of concert pitch A (69).

dbadb commented 1 year ago

@pd3v - indeed the middle in middle c on a guitar appears ill-defined in common parlance. That said this link shows how to find the middle-c frequency on a guitar fretboard in a standard tuning. More of a FWIW than a useful piece of information, I imagine. The important point is that the guitar is a transposing instrument, so on a treble stave the middle-C is really a request for one octave lower (ie 48, C3 in the C4 system). So it "looks" like a middle-c on the treble clef when notated for guitar. (I wasn't aware of this until now, lol)

felixroos commented 1 year ago

just did another experiment, and somehow tidal is now using c5 as the default sample pitch:

d1 $ s "jvbass" # note "c5" === d1 $ s "jvbass"

so either it changed, or I was drunk when I "found out" it's c4

felixroos commented 1 year ago

btw I was kind of reluctant to touch this issue, because it will break / repitch every single pattern that uses pitched samples ... not sure if it now just is what it is or if there should be just a big breaking change at some point

daslyfe commented 1 month ago

Middle C = C4 = 261.626 Hz = sampler speed of 1 might make the most sense because that is what middle C is on the piano and the piano is the closest thing the world has to a standard expectation