7

I am confused because there are a lot of programms. But i am looking something like this. I will type a melody like "a4 c3 h3 a2" etc. and then i want to hear this. Does anybody know what i am looking for? thanks in advance

4
  • "h3"? Apart from the h3, your notation resembles the notation used by lilypond. Look for a lilypond-to-audio or lilypond-to-midi app.
    – Ewan Todd
    Dec 27, 2009 at 21:24
  • 3
    Ah, Location: Berlin. As I suspected. @Ewan: in German music notation, it's "cdefgah". "h" instead of (english/international) "b". Dec 27, 2009 at 21:47
  • 1
    Nitpick: as I understand it, "H" is actually we we call B flat - B (natural) is still just B. The composer Bach was able to use this to encode his name in notes into one of his pieces. Dec 27, 2009 at 22:40
  • Close, Daniel. German B equals U.S. B flat (Bb), and H equals B.
    – gnud
    Dec 28, 2009 at 10:44

4 Answers 4

8

computing frequencies from note name is easy. each half-note is 2^(1/12) away from the preceding note, 440 Hz is A4.

if by any chance you are on windows, you may try this piece of code, which plays a song through the PC speaker:

import math
import winsound
import time

labels = ['a','a#','b','c','c#','d','d#','e','f','f#','g','g#']
# name is the complete name of a note (label + octave). the parameter
# n is the number of half-tone from A4 (e.g. D#1 is -42, A3 is -12, A5 is 12)
name   = lambda n: labels[n%len(labels)] + str(int((n+(9+4*12))/12))
# the frequency of a note. the parameter n is the number of half-tones
# from a4, which has a frequency of 440Hz, and is our reference note.
freq   = lambda n: int(440*(math.pow(2,1/12)**n))

# a dictionnary associating note frequencies to note names
notes  = {name(n): freq(n) for n in range(-42,60)}

# the period expressed in second, computed from a tempo in bpm
period = lambda tempo: 1/(tempo/60)

# play each note in sequence through the PC speaker at the given tempo
def play(song, tempo):
    for note in song.lower().split():
        if note in notes.keys():
            winsound.Beep(notes[note], int(period(tempo)*1000))
        else:
            time.sleep(period(tempo))

# "au clair de la lune"!! 'r' is a rest
play( 'c4 c4 C4 d4 e4 r d4 r c4 e4 d4 d4 c4 r r r '
      'c4 C4 c4 d4 e4 r d4 r c4 e4 d4 d4 c4 r r r '
      'd4 d4 d4 d4 A3 r a3 r d4 c4 B3 a3 g3 r r r '
      'c4 c4 c4 d4 e4 r d4 r c4 e4 d4 d4 c4 r r r ', 180 )

(please note that i am using python 3.x, you may need to adapt some part of the code in order to use it on python 2.x.)

ho, by the way, i used abcdefg as a scale, but you will surely find the way to use h instead of b.

2
  • NameError: global name 'names' is not defined
    – kame
    Dec 28, 2009 at 10:20
  • 1
    ooops, sorry. that's what happen when you don't clear your python session before testing. corrected now ! Dec 28, 2009 at 10:38
3

One outside option is JFugue as shown here (with Groovy). Note that you would use Jython instead of Python, which hopefully is within bounds as an answer.

2

you could use any library that produces MIDI output, in case of .net I'd recommend the one created by Stephen Toub from Microsoft(can't find from where i got it, but google for it.)

1

Check this out: http://www.algorithm.co.il/blogs/index.php/pytuner/ It's a very similar projet and looks like a very decent reference.

1
  • i have trouble with installing pymedia :(
    – kame
    Dec 27, 2009 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.