Changeset 7be77bb


Ignore:
Timestamp:
Oct 30, 2018, 1:04:07 AM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
cefa29d
Parents:
7af37df (diff), 476cb41 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'feature/note2freq'

Location:
python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/midiconv.py

    r7af37df r7be77bb  
    22""" utilities to convert midi note number to and from note names """
    33
    4 __all__ = ['note2midi', 'midi2note', 'freq2note']
     4__all__ = ['note2midi', 'midi2note', 'freq2note', 'note2freq']
    55
    66import sys
    7 from ._aubio import freqtomidi
     7from ._aubio import freqtomidi, miditofreq
    88
    99py3 = sys.version_info[0] == 3
     
    7676    nearest_note = int(freqtomidi(freq) + .5)
    7777    return midi2note(nearest_note)
     78
     79def note2freq(note):
     80    """Convert note name to corresponding frequency, in Hz.
     81
     82    Parameters
     83    ----------
     84    note : str
     85        input note name
     86
     87    Returns
     88    -------
     89    freq : float [0, 23000[
     90        frequency, in Hz
     91
     92    Example
     93    -------
     94    >>> aubio.note2freq('A4')
     95    440
     96    >>> aubio.note2freq('A3')
     97    220.1
     98    """
     99    midi = note2midi(note)
     100    return miditofreq(midi)
  • python/tests/test_note2midi.py

    r7af37df r7be77bb  
    44from __future__ import unicode_literals
    55
    6 from aubio import note2midi, freq2note
     6from aubio import note2midi, freq2note, note2freq
    77from nose2.tools import params
    88import unittest
     
    120120        self.assertEqual("A4", freq2note(439))
    121121
     122class note2freq_simple_test(unittest.TestCase):
     123
     124    def test_note2freq(self):
     125        " make sure note2freq('A3') == 220"
     126        self.assertEqual(220, note2freq("A3"))
     127
     128    def test_note2freq_under(self):
     129        " make sure note2freq(A4) == 440"
     130        self.assertEqual(440, note2freq("A4"))
     131
    122132if __name__ == '__main__':
    123133    import nose2
Note: See TracChangeset for help on using the changeset viewer.