Skip to content
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

Merged
merged 23 commits into from
May 29, 2024
Merged

Add essentiamath #1417

merged 23 commits into from
May 29, 2024

Conversation

xaviliz
Copy link
Contributor

@xaviliz xaviliz commented May 24, 2024

Add some hertz, midi note number and note conversions:

  • hz2midi
  • midi2hz
  • hz2cents
  • cents2hz
  • midi2note
  • note2midi
  • note2hz
  • hz2note
  • db2velocity
  • velocity2db

Comment on lines 741 to 746
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);
Copy link
Member

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?

Copy link
Contributor Author

@xaviliz xaviliz May 28, 2024

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.

int noteIdx = floor((octave - (CIdx + 1)) * nNotes);
int idx = 0;
for (int i = 0; i < nNotes; i++) {
if (ALL_NOTES[i] == root) {
Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -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" },
Copy link
Member

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.

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)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here

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)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@xaviliz xaviliz marked this pull request as ready for review May 29, 2024 10:45
@dbogdanov dbogdanov merged commit a94e021 into MTG:master May 29, 2024
7 checks passed
@xaviliz
Copy link
Contributor Author

xaviliz commented May 29, 2024

Thanks for the corrections and comments 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants