Changes in / [7be77bb:7af37df]
- Location:
- python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/lib/aubio/midiconv.py
r7be77bb r7af37df 2 2 """ utilities to convert midi note number to and from note names """ 3 3 4 __all__ = ['note2midi', 'midi2note', 'freq2note' , 'note2freq']4 __all__ = ['note2midi', 'midi2note', 'freq2note'] 5 5 6 6 import sys 7 from ._aubio import freqtomidi , miditofreq7 from ._aubio import freqtomidi 8 8 9 9 py3 = sys.version_info[0] == 3 … … 76 76 nearest_note = int(freqtomidi(freq) + .5) 77 77 return midi2note(nearest_note) 78 79 def note2freq(note):80 """Convert note name to corresponding frequency, in Hz.81 82 Parameters83 ----------84 note : str85 input note name86 87 Returns88 -------89 freq : float [0, 23000[90 frequency, in Hz91 92 Example93 -------94 >>> aubio.note2freq('A4')95 44096 >>> aubio.note2freq('A3')97 220.198 """99 midi = note2midi(note)100 return miditofreq(midi) -
python/tests/test_note2midi.py
r7be77bb r7af37df 4 4 from __future__ import unicode_literals 5 5 6 from aubio import note2midi, freq2note , note2freq6 from aubio import note2midi, freq2note 7 7 from nose2.tools import params 8 8 import unittest … … 120 120 self.assertEqual("A4", freq2note(439)) 121 121 122 class 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 132 122 if __name__ == '__main__': 133 123 import nose2
Note: See TracChangeset
for help on using the changeset viewer.