-
Notifications
You must be signed in to change notification settings - Fork 931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tuning param to hz_to_note() #1806
Comments
Yes, it would be good to have this for better flexibility. Thanks @stefan-balke for the nice motivating example. Side remark to @stefan-balke: is the dynamic range really 4 dB between highest and lowest point in the power spectrum? Shouldn't it be 40 dB or something like that? 🤔 |
Thanks for noting, I just added the "10" in front of the 10*log(...) :-) |
I understand where this idea is coming from, but i think we should be a little careful here. The convention in place now is that notes are defined using scientific pitch notation, which has an explicit tuning definition baked in. My worry is that if we allow implicit tuning deviation, notes become ambiguous, and the user needs to remember to track tuning definition across forward and reverse conversion calls. Maybe that's ok, but it is worth thinking through the api and usage implications. |
Thanks for the response. Didn't know that A4=440 is actually somewhere defined in relation to pitch, always thought of it as a scale to some reference frequency, e.g. 440 Hz. |
Of course, but if we're converting between frequency and pitch, we need to establish a common reference point, and SPN defines A as 440 Hz.
Right, that's the difficulty though. In your example code, you put the conversion in hz_to_midi, but I think this is incorrect. MIDI note numbers do correspond to specific frequencies (not pitches), and this also is defined with respect to A440. Would you then want to put tuning deviation in the midi-to-note converter instead? |
Good pointer to SPN (https://en.wikipedia.org/wiki/Scientific_pitch_notation). |
There is precedent for that kind of thing, eg with the Indian notations and FJS conversion. (Aside: is it possible that FJS would be a better fit for your application, looking at harmonics?) But I think to handle the case that you're describing, it would be more useful to think of it from the perspective of to/from |
Why do you think that? Maybe I cannot follow your string of thought here. I "measure" frequencies and all I want to know is what notes in these relate to, given a tuning which is in this case built in the instruments and not changeable (well, with a saw but only in one direction :-)). BTW: I was adapting As a trumpet player I rarely play at 440 Hz, most modern wind instruments are more 442/443 ish. Xylophone etc. you buy are also 442. How could we reflect that or make documentation that clear that people do not get "trapped" like me? As I recall correctly, in the filter banks like Disclaimer: I only play and analyse modern music, of course there are orchestras which play in the authentic tuning. |
I don't think that's quite right. Notes are assumed to be SPN, and midi numbers are midi numbers. The conversion is implemented by way of midi because it's expedient and minimizes redundancy, but we could have gone directly between hz and spn if we wanted to.
This is a fair point, and I would like to support an option for making tuning configurable. Please don't take my nitpicking as contrarianism - I just want to make sure we've thought through the implications all the way before committing to anything.
Yes, in many places we support a tuning parameter defined in cents deviation from 440. (Explicit setting of an A440 parameter was deprecated a while back.) This is primarily used in the opposite direction from what you're looking for though: in cqt for example, we use C1 to define |
Totally fine, I try to follow your thoughts and your opinion on this is always highly appreciated. What is confusing for me at the moment is the nomenclature. SPN, notes, midi, FJS... As a summary (mainly for me, I guess...):
I see three directions here:
Please correct me :-) |
It's a bit more than that actually. Here's the regexp we use for SPN parsing: librosa/librosa/core/notation.py Lines 132 to 137 in 8dae20c
Specifically, we have the pitch class (note + accidental), octave number (optional), and tuning deviation (optional). The definition of SPN is relative to A440, and this makes the conversion between hz and pitch relatively unambiguous. The two remaining points of ambiguity are cent quantization (obviously) and note spelling dependent on the key or mode (since SPN also assumes equal temperament). Now, we also have note spelling in the functional just system (FJS) notation, as described in excruciating detail here #1402 . (You didn't really ask about this, but you mentioned it, so I'll explain the differences here.) There is some overlap between valid strings in SPN or FJS, but they are fundamentally pretty different:
Outside of western notation, we also have svara conversion (Hindustani or Carnatic), which have some commonalities to both FJS (explicit dependence on a unison (Sa) frequency) and SPN (key / thaat / mela dependence). The strings are of course totally different, but hopefully you get the point that we already have some precedent for tuning-dependent conversion here.
This is probably the right thing to do, but it will require a pretty careful audit of downstream functions and documentation to make sure that tuning is passed through in all places. (I'm thinking of things like display, cqt/chroma, etc.)
This would probably just be confusing.
Not sure I understand this one entirely, but it sounds like a recipe for confusion to me in that it could render the conversion somewhat implicit when looking at the code. |
#977 😂 |
Was analysing recordings of chimes the other day and were interested in the tuning of the harmonics.
Basically ended up calling something like this in my script:
However, instrument itself is supposed to be tuned to A4=442.0.
In
hz_to_midi()
440.0 Hz is hard coded.The feature request is to make tuning an optional parameter, like:
So nothing critical at all, just a small addition to make it more flexible.
The text was updated successfully, but these errors were encountered: