How can I create a melody? Is there a sound module?

I am confused because there are many programs. But I look something like this. I will dial the tune "a4 c3 h3 a2", etc., And then I want to hear it. Does anyone know what I'm looking for? thanks in advance

+7
python audio
source share
4 answers

Calculating frequencies from the title of notes is easy. each half of the note is equal to 2 ^ (1/12) from the previous note, 440 Hz - A4.

If you happen to be on the windows, you can try this piece of code that plays the 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 (eg 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 rrr ' 'c4 C4 c4 d4 e4 r d4 r c4 e4 d4 d4 c4 rrr ' 'd4 d4 d4 d4 A3 r a3 r d4 c4 B3 a3 g3 rrr ' 'c4 c4 c4 d4 e4 r d4 r c4 e4 d4 d4 c4 rrr ', 180 ) 

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

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

+7
source share

One external JFugue parameter as shown here (with Groovy). Note that instead of Python, you would use Jython , which I hope is within the bounds.

+3
source share

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

+2
source share

Check this out: http://www.algorithm.co.il/blogs/index.php/pytuner/ This is a very similar project and looks very decent.

+1
source share

All Articles