Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SFX
#6
(02-20-2024, 06:52 PM)johnno56 Wrote: ... I am not expecting piano tones...
.. What I am expecting is a Synthesizer... 


Just curious with "do re mi" generated by SquareWave function, 
let's try this Pianoman ..... Cool

Code:
'----------------
' INITIALIZATION
'----------------
include "sfx.n7"
set window "Pianoman", 160, 200,false,3

constant DO = 261.63*2
constant RE = 293.66*2
constant MI = 329.63*2
constant FA = 349.23*2
constant SO = 392.00*2
constant LA = 440.00*2
constant TI = 493.88*2
constant b1 = 0.2
constant b2 = 0.4

visible sfx = SFX() 'create an sfx instance

'--------------
' MAIN PROGRAM
'--------------
wln "PIANOMAN"
wln
wln "1 - Play DO"
wln "2 - Play RE"
wln "3 - Play MI"
wln "4 - Play FA"
wln "5 - Play SO"
wln "6 - Play LA"
wln "7 - Play TI"
wln "8 - Play Song"
wln
wln "Esc - Quit"

while not keydown(KEY_ESCAPE)
    if keydown(KEY_1, true) then Piano(b1,DO)
    if keydown(KEY_2, true) then Piano(b1,RE)
    if keydown(KEY_3, true) then Piano(b1,MI)
    if keydown(KEY_4, true) then Piano(b1,FA)
    if keydown(KEY_5, true) then Piano(b1,SO)
    if keydown(KEY_6, true) then Piano(b1,LA)
    if keydown(KEY_7, true) then Piano(b1,TI)
    if keydown(KEY_8, true) then Song()
    wait 1
wend

'-----------
' FUNCTIONS
'-----------
function Piano(b,x)
    'SquareWave(duration,freq,volume)
    mytone = sfx.SquareWave(b,x,0.05)
    play sound mytone
    Pause()
endfunc

function Song()
    Piano(b2,SO);Piano(b1,SO);Piano(b1,SO)
    Piano(b2,SO);Piano(b2,MI)
    Piano(b2,DO*2);Piano(b1,DO*2);Piano(b1,DO*2)
    Piano(b2,TI);Piano(b2,LA)
   
    Piano(b2,SO);Piano(b1,SO);Piano(b1,SO)
    Piano(b2,LA);Piano(b1,SO);Piano(b1,SO)
    Piano(b2,SO); Piano(b1,FA); Piano(b1,MI)
    Piano(b2,RE); Piano(b1,DO); Piano(b1,RE)
   
    Piano(b2,MI); Piano(b1,MI); Piano(b1,MI)
    Piano(b2,RE); Piano(b2,RE)
    Piano(b1,DO); Piano(b1,RE); Piano(b1,MI);Piano(b1,DO)
    Piano(b1,LA/2);Piano(b1,TI/2);Piano(b2,DO)
   
    Piano(b2,SO/2);Piano(b1,DO); Piano(b1,RE)
    Piano(b2,SO); Piano(b1,FA); Piano(b1,MI)
    Piano(b2,RE); Piano(b1,RE); Piano(b1,RE); Piano(b2*2,DO)                                                   
endfunc

function Pause()
    wait 400
endfunc
Reply


Messages In This Thread
SFX - by johnno56 - 02-19-2024, 07:02 PM
RE: SFX - by Marcus - 02-20-2024, 04:44 PM
RE: SFX - by Marcus - 02-20-2024, 05:58 PM
RE: SFX - by johnno56 - 02-20-2024, 06:52 PM
RE: SFX - by 1micha.elok - 02-21-2024, 06:38 AM
RE: SFX - by Marcus - 02-21-2024, 04:07 PM
RE: SFX - by 1micha.elok - 02-22-2024, 05:04 AM
RE: SFX - by Marcus - 02-21-2024, 06:37 AM
RE: SFX - by johnno56 - 02-21-2024, 11:37 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)