shithub: aubio

Download patch

ref: 6f944b5bddfdea3f17e76128fc9f376fe2ce0998
parent: 1f07bdd657ec5113d783d01e5d7a650d8e9412cb
author: Paul Brossier <piem@piem.org>
date: Mon Oct 29 20:22:41 EDT 2018

[py] add note2freq to midiconv.py

--- a/python/lib/aubio/midiconv.py
+++ b/python/lib/aubio/midiconv.py
@@ -4,7 +4,7 @@
 __all__ = ['note2midi', 'midi2note', 'freq2note']
 
 import sys
-from ._aubio import freqtomidi
+from ._aubio import freqtomidi, miditofreq
 
 py3 = sys.version_info[0] == 3
 if py3:
@@ -75,3 +75,26 @@
     " convert frequency in Hz to nearest note name, e.g. [0, 22050.] -> [C-1, G9] "
     nearest_note = int(freqtomidi(freq) + .5)
     return midi2note(nearest_note)
+
+def note2freq(note):
+    """Convert note name to corresponding frequency, in Hz.
+
+    Parameters
+    ----------
+    note : str
+        input note name
+
+    Returns
+    -------
+    freq : float [0, 23000[
+        frequency, in Hz
+
+    Example
+    -------
+    >>> aubio.note2freq('A4')
+    440
+    >>> aubio.note2freq('A3')
+    220.1
+    """
+    midi = note2midi(note)
+    return miditofreq(midi)