How To Make a Synthesizer

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
deeverd
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 165
Joined: Mon Jul 16, 2007 11:58 pm

How To Make a Synthesizer

Post by deeverd » Fri Aug 03, 2007 10:20 pm

I once read a mention that a program/recipe/formula used to exist for scripting a MIDI Synthesizer, and that it used to be on this forum or be part of a sample script. Unfortunatley, I can't find it.

I've played around with this idea on and off over the past few weeks, and finally figured out how to turn the "beep" command into all 66 notes of the keys of a piano. In fact, just in case anyone else needs to know how to do the same, I've listed the frequencies for each of the 66 keys in the code box that follows this request for information.

In the meantime, what I've been trying to figure out is how to affect the duration of the "beep" so that it makes one steady note for as long as I press any of the 66 keys (buttons) for my homemade synthesizer. Granted, I can program the beep duration to last as long as I like ahead of time for one particular note of a piece of music, but the problem is how to allow it to play the correct duration of time for any number of varying times, so that the duration is different every time I press a key, depending on how long I hold it down. That part I haven't figured out yet.

Code: Select all

PIANO KEY FREQUENCIES
Key 66: D6 = 1174.66
Key 65:  C♯6/D♭6 = 1108.73
Key 64: C6 (Soprano C) = 1046.50
Key 63: B5 = 987.767
Key 62: A♯5/B♭5 = 932.328
Key 61: A5 = 880.000
Key 60: G♯5/A♭5 = 830.609
Key 59: G5 = 783.991
Key 58: F♯5/G♭5 = 739.989
Key 57: F5 = 698.456
Key 56: E5 = 659.255
Key 55: D♯5/E♭5 = 622.254
Key 54: D5 = 587.330
Key 53: C♯5/D♭5 = 554.365
Key 52: C5 (Tenor C) = 523.251
Key 51: B4 = 493.883
Key 50: A♯4/B♭4 = 466.164
Key 49: A4 (A440) = 440.000
Key 48: G♯4/A♭4 = 415.305
Key 47: G4 = 391.995
Key 46: F♯4/G♭4 = 369.994
Key 45: F4 = 349.228
Key 44: E4 = 329.628
Key 43: D♯4/E♭4 = 311.127
Key 42: D4 = 293.665
Key 41: C♯4/D♭4 = 277.183
Key 40: C4 (Middle C) = 261.626
Key 39: B3 = 246.942
Key 38: A♯3/B♭3 = 233.082
Key 37: A3 = 220.000
Key 36: G♯3/A♭3 = 207.652
Key 35: G3 = 195.998
Key 34: F♯3/G♭3 = 184.997
Key 33: F3 = 174.614
Key 32: E3 = 164.814
Key 31: D♯3/E♭3 = 155.563
Key 30: D3 = 146.832
Key 29: C♯3/D♭3 = 138.591
Key 28: C3 (Low C) = 130.813
Key 27: B2 = 123.471
Key 26: A♯2/B♭2 = 116.541
Key 25: A2 = 110.000
Key 24: G♯2/A♭2 = 103.826
Key 23: G2 = 97.9989
Key 22: F♯2/G♭2 = 92.4986
Key 21: F2 = 87.3071
Key 20: E2 = 82.4069
Key 19: D♯2/E♭2 = 77.7817
Key 18: D2 = 73.4162
Key 17: C♯2/D♭2 = 69.2957
Key 16: C2 (Deep C) = 65.4064
Key 15: B1 = 61.7354
Key 14: A♯1/B♭1 = 58.2705
Key 13: A1 = 55.0000
Key 12: G♯1/A♭1 = 51.9130
Key 11: G1 = 48.9995
Key 10: F♯1/G♭1 = 46.2493
Key 9: F1 = 43.6536
Key 8: E1 = 41.2035
Key 7: D♯1/E♭1 = 38.8909
Key 6: D1 = 36.7081
Key 5: C♯1/D♭1 = 34.6479
Key 4: C1 = 32.7032
Key 3: B0 = 30.8677
Key 2: A♯0/B♭0 = 29.1353
Key 1: A0 = 27.5000
Cheers, deeverd

mkm07
Posts: 1
Joined: Thu Aug 09, 2007 3:40 pm

MIDI synth

Post by mkm07 » Fri Aug 10, 2007 8:23 pm

Thank you for posting your code. I am new to Revolution, so this might come off as a dumb question, but how do you get Revolution to trigger the MIDI sounds/notes? I am also wondering if it is possible for Revolution to play notes triggered from an external controller.

BTW, you mentioned trying to find an example MIDI synth in Revolution. I'm not sure if this is what you were referring to, but I came across an example application on the Runtime Revolution site. Go to the Resources & Support page. On the side navigation bar, there is a link to Unsupported Resources.

deeverd
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 165
Joined: Mon Jul 16, 2007 11:58 pm

beepPitch for Synthesizer

Post by deeverd » Sun Aug 12, 2007 5:13 pm

Hell mkm07,

That's not a dumb question at all. In fact, asking about anything someone hasn't done before in programming could never be dumb (at least I hope not, since I ask a lot of questions like that!) What might be dumb, however, was when I didn't mention the script in the first place when I posted the piano key information.

Actually, it's pretty simple:

Code: Select all

set the beepPitch to 880
In the example above, I put in the numbers "880," so to answer your question, all you have to do is to put in the number that is associated with any of the 66 keys I posted, and you will have a beep that matches that note. BTW, I think the default setting for the beep is 440.

A couple other commands that might be useful to you are the "beepDuration" and "beepLoudness." To see some good example scripts for those commands, simply type in either of those words in your Revolution script editor, then right click on the word to bring up the help screen with examples.

At first glance, you might think that the beepDuration would solve the problem of what I'm looking for but when you set the beepDuration, ALL the notes have the same duration. My quest is trying to find out how to make a note last as long or as short as the time that I press the key.

Anyway, I'll definitely check out the part of the website you mentioned. Thanks for telling me about it.

Cheers, deeverd

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Aug 12, 2007 6:53 pm

Hi Deeverd,

Did you actually get the beep sound to play at different pitches? Which OS are you on?

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Aug 12, 2007 8:59 pm

Hi all,

I have tried the midi stack. It is a wonderful toy and has great potential. I really don't understand that this didn't come up earlier.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

deeverd
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 165
Joined: Mon Jul 16, 2007 11:58 pm

Post by deeverd » Thu Aug 16, 2007 8:16 pm

Hi Mark,

I'm on the Windows XP operating system, and the beep pitch and beep duration works fine on it, although I am aware that the documentation says otherwise. I believe it's the same situation with the loudness where the documentation says it doesn't work on Windows, but it definitely works perfect on my Windows XP system.

I haven't had a chance to try the midi program yet, but I have downloaded the "unsupported" package. Sounds great. Cheers, deeverd

Post Reply