-
Notifications
You must be signed in to change notification settings - Fork 536
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 essentiamath #1417
Add essentiamath #1417
Conversation
src/essentia/essentiamath.h
Outdated
inline Real cents2hz(Real frequencyB, Real cents) { | ||
return frequencyB * powf(2.0, cents / 1200.0); | ||
} | ||
|
||
inline Real hz2cents(Real frequencyA, Real frequencyB) { | ||
return 1200 * log2(frequencyA / frequencyB); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frequencyA
vs frequencyB
can be unclear to users. Maybe we could use a different naming for frequencyB
like referenceFrequency
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, that makes sense. I doubted with tuningFrequency
but referenceFrequency
works better. Thanks.
src/essentia/essentiamath.h
Outdated
int noteIdx = floor((octave - (CIdx + 1)) * nNotes); | ||
int idx = 0; | ||
for (int i = 0; i < nNotes; i++) { | ||
if (ALL_NOTES[i] == root) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break out of the loop once the matching note is found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L796 is doing it by index. However it can be replaced by a break
to make it more explicit. Thanks again to point it out.
src/python/globalfuncs.cpp
Outdated
@@ -1001,6 +1162,18 @@ static PyMethodDef Essentia__Methods[] = { | |||
{ "hz2bark", hzToBark, METH_O, "Converts a frequency in Hz to a bark band" }, | |||
{ "mel2hz", melToHz, METH_O, "Converts a mel band to frequency in Hz" }, | |||
{ "hz2mel", hzToMel, METH_O, "Converts a frequency in Hz to a mel band" }, | |||
{ "midi2hz", midiToHz, METH_VARARGS, "Converts a midi note number to frequency in Hz" }, | |||
{ "hz2midi", hzToMidi, METH_VARARGS, "Converts a frequency in Hz to a midi note number" }, | |||
{ "hz2cents", hzToCents, METH_VARARGS, "Returns the cents distance between two frequencies in Hz" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we use the referenceFrequency
(see my comment about), we should updates this description too.
src/python/globalfuncs.cpp
Outdated
vector<PyObject*> argsV = unpack(args); | ||
|
||
if (argsV.size() != 2 || !PyFloat_Check(argsV[0]) || !PyFloat_Check(argsV[1])) { | ||
PyErr_SetString(PyExc_TypeError, (char*)"expecting arguments (Real frequencyA, Real frequencyB)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
src/python/globalfuncs.cpp
Outdated
vector<PyObject*> argsV = unpack(args); | ||
|
||
if (argsV.size() != 2 || !PyFloat_Check(argsV[0]) || !PyFloat_Check(argsV[1])) { | ||
PyErr_SetString(PyExc_TypeError, (char*)"expecting arguments (Real frequencyB, Real cents)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
Thanks for the corrections and comments 🚀 |
Add some hertz, midi note number and note conversions: