Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -4,7 +4,7 @@ · 3 unmodified lines | |||
| 4 | __all__ = ['note2midi', 'midi2note', 'freq2note'] | 4 | __all__ = ['note2midi', 'midi2note', 'freq2note'] |
| 5 | 5 | ||
| 6 | import sys | 6 | import sys |
| 7 | from ._aubio import freqtomidi | 7 | from ._aubio import freqtomidi, miditofreq |
| 8 | 8 | ||
| 9 | py3 = sys.version_info[0] == 3 | 9 | py3 = sys.version_info[0] == 3 |
| 10 | if py3: | 10 | if py3: |
| @@ -75,3 +75,26 @@ def freq2note(freq): · 64 unmodified lines | |||
| 75 | " convert frequency in Hz to nearest note name, e.g. [0, 22050.] -> [C-1, G9] " | 75 | " convert frequency in Hz to nearest note name, e.g. [0, 22050.] -> [C-1, G9] " |
| 76 | nearest_note = int(freqtomidi(freq) + .5) | 76 | nearest_note = int(freqtomidi(freq) + .5) |
| 77 | return midi2note(nearest_note) | 77 | return midi2note(nearest_note) |
| 78 | |||
| 79 | def 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) | ||