I used that thing that creates sound with no media that was posted a while ago to make a random music maker program. It has a bass line and a melody. I'm working on making it so you can save the final sound.
randomize timer()
Print "Loading..."
sync
`Every pitch is multiplied by this to obtain a pitch one half step above it.
`Trust me, I did alot of math to figure this number out.
halfstep# = 1.0594630943592952645618252949461
dim note#(24)
dim name$(12)
`This value is the pitch for middle C
`Trust me, I tuned it to my guitar.
note#(1) = 29.2
`Make a list of note names
`These are pointless except to name each .WAV file
name$(1) = "c"
name$(2) = "c#"
name$(3) = "d"
name$(4) = "d#"
name$(5) = "e"
name$(6) = "f"
name$(7) = "f#"
name$(8) = "g"
name$(9) = "g#"
name$(10) = "a"
name$(11) = "a#"
name$(12) = "b"
print "Creating bass notes..."
sync
`Create Bass Progression
for x = 1 to 12
if x > 1 then note#(x) = note#(x - 1) * halfstep#
createsound(name$(x),x,1000,note#(x)/2)
next x
`1,3,5,6,8,10,12
`Create a 4-Chord progression in C Major
for b = 1 to 3
a = rnd(6)
if a = 0 then bl$ = bl$ + "C"
if a = 1 then bl$ = bl$ + "D"
if a = 2 then bl$ = bl$ + "E"
if a = 3 then bl$ = bl$ + "F"
if a = 4 then bl$ = bl$ + "G"
if a = 5 then bl$ = bl$ + "A"
if a = 6 then bl$ = bl$ + "B"
next b
bl$ = bl$ + "C"
`Note that the last chord in a C Major progression must be C, otherwise it will sound bad.
`Create a bassline, which is just the 4 chords repeated over and over and over and over...
for b = 1 to 10
bassline$ = bassline$ + bl$
next b
savebass$ = bassline$
print "Creating melody notes..."
sync
`Create Trebble Notes
for x = 1 to 12
createsound(name$(x)+ "2",x+12,250,note#(x)*2)
next x
set text font "arial"
set text size 16
chrd = 0
btmr = 0
ttmr = 0
cls
print "Creating Sequence"
sync
note = 13
`Generate a completely random list of notes
for x = 1 to 20
a = rnd(6)
if a = 0 then list2$ = list2$ + "C"
if a = 1 then list2$ = list2$ + "D"
if a = 2 then list2$ = list2$ + "E"
if a = 3 then list2$ = list2$ + "F"
if a = 4 then list2$ = list2$ + "G"
if a = 5 then list2$ = list2$ + "A"
if a = 6 then list2$ = list2$ + "B"
next x
`Replace each note with a pattern
while len(list2$) > 1
n$ = left$(list2$,1)
list2$ = right$(list2$,len(list2$) - 1)
a = rnd(1)
if a = 0
if n$ = "C" then list$ = list$ + "CDEFGABC"
if n$ = "D" then list$ = list$ + "DEFDCDDA"
if n$ = "E" then list$ = list$ + "CGCGEFGF"
if n$ = "F" then list$ = list$ + "GFEDCDEF"
if n$ = "G" then list$ = list$ + "CDCEAFCG"
if n$ = "A" then list$ = list$ + "CCGCCGCE"
if n$ = "B" then list$ = list$ + "DEBGFDEC"
endif
if a = 1
if n$ = "C" then list$ = list$ + "GGFFEEDD"
if n$ = "D" then list$ = list$ + "BAGABAGA"
if n$ = "E" then list$ = list$ + "FEDCCDEF"
if n$ = "F" then list$ = list$ + "CEGCEGCC"
if n$ = "G" then list$ = list$ + "GECGECGE"
if n$ = "A" then list$ = list$ + "FEDCBACD"
if n$ = "B" then list$ = list$ + "GFEDGFED"
endif
endwhile
saveseq$ = list$
do
cls
tmr = timer()
print bassline$
print list$
print b$ + ", " + n$
Print "Press <SPACE> to restart / replay song."
if spacekey() = 1
list$ = saveseq$
bassline$ = savebass$
btmr = 0
ttmr = 0
endif
btmr = btmr + 1
ttmr = ttmr + 1
if btmr = 4
b$ = left$(bassline$,1)
if b$ = "C" then play sound 1
if b$ = "D" then play sound 3
if b$ = "E" then play sound 5
if b$ = "F" then play sound 6
if b$ = "G" then play sound 8
if b$ = "A" then play sound 10
if b$ = "B" then play sound 12
bassline$ = right$(bassline$,len(bassline$) - 1)
btmr = 0
endif
if ttmr = 1
n$ = left$(list$,1)
if n$ = "C" then play sound 13
if n$ = "D" then play sound 15
if n$ = "E" then play sound 17
if n$ = "F" then play sound 18
if n$ = "G" then play sound 20
if n$ = "A" then play sound 22
if n$ = "B" then play sound 24
list$ = right$(list$,len(list$) - 1)
ttmr = 0
endif
while timer() - tmr < 300
endwhile
loop
function createsound(name$,soundnumber,length#,pitch#)
if file exist(name$+".wav")=1 then delete file name$+".wav"
open to write 1,name$+".wav"
chunk=int(((length#/1000)*44100*16)/8) `sample size (no of samples * bitrate * channels / 8)
samples=int((length#/1000)*44100) `length *44100
restore
for x=1 to 40
read byte2
write byte 1, byte2
next x
write long 1,chunk
rem generate and write wave
thing# = 0
for x=1 to samples
inc thing#,pitch#
if thing#>10000 then thing#=0
output#=thing#
write word 1,output#
next x
close file 1
load sound name$+".wav",soundnumber
data 82:data 73:data 70:data 70:data 208:data 59:data 1:data 0:data 87
data 65:data 86:data 69:data 102:data 109:data 116:data 32:data 16
data 0:data 0:data 0:data 1:data 0:data 2:data 0:data 34:data 86:data 0
data 0:data 136:data 88:data 1:data 0:data 4:data 0:data 16:data 0
data 100:data 97:data 116:data 97
endfunction
I guess it's not that useful yet, but still kinda fun to listen to.
[EDIT]
****The Newest Version****
`********Random Music Maker**********
randomize timer()
input "Would you like to load an old song?", q$
if q$ = "y" or q$ = "Y" or q$ = "yes" or q$ = "Yes" or q$ = "YES" then gosub loadsong
`Every pitch is multiplied by this to obtain a pitch one half step above it.
`Trust me, I did alot of math to figure this number out.
halfstep# = 1.0594630943592952645618252949461
dim note#(24)
dim name$(12)
`Make a list of note names
`These are pointless except to name each .WAV file
name$(1) = "c"
name$(2) = "c#"
name$(3) = "d"
name$(4) = "d#"
name$(5) = "e"
name$(6) = "f"
name$(7) = "f#"
name$(8) = "g"
name$(9) = "g#"
name$(10) = "a"
name$(11) = "a#"
name$(12) = "b"
beginningofcode:
cls
Print "Loading..."
sync
if loadsong = 0
a = rnd(4)
if a = 0 then tempo# = 1
if a = 1 then tempo# = .9
if a = 2 then tempo# = .8
if a = 3 then tempo# = .7
if a = 4 then tempo# = .6
endif
for x = 1 to 36
if sound exist(x) = 1
delete sound x
set cursor 0,15
print "Removing earlier sounds..."
sync
endif
next x
`This value is the pitch for middle C
`Trust me, I tuned it to my guitar.
note#(1) = 29.7
`Set the key signature by moving C up/down a random amount of halfsteps
if loadsong = 0 then keychange = rnd(12) - 6
note#(1) = note#(1) *(halfstep#^keychange)
print "Creating bass notes..."
sync
`Create Bass Notes
for x = 1 to 12
l = int(1000*tempo#)
if x > 1 then note#(x) = note#(x - 1) * halfstep#
createsound(name$(x),x,l,note#(x)*.5)
print str$(x) + " / " + "12":sync
next x
if loadsong = 0
bl$ = ""
`Create a 4-Chord progression using only notes in C Major
`The first note can be anything
a = rnd(6)
if a = 0 then bl$ = bl$ + "C"
if a = 1 then bl$ = bl$ + "D"
if a = 2 then bl$ = bl$ + "E"
if a = 3 then bl$ = bl$ + "F"
if a = 4 then bl$ = bl$ + "G"
if a = 5 then bl$ = bl$ + "A"
if a = 6 then bl$ = bl$ + "B"
`The second and third notes follow these rules:
for b = 2 to 3
if right$(bl$,1) = "C" or right$(bl$,1) = "G"
`C or G can be followed by anything
a = rnd(6)
if a = 0 then bl$ = bl$ + "C"
if a = 1 then bl$ = bl$ + "D"
if a = 2 then bl$ = bl$ + "E"
if a = 3 then bl$ = bl$ + "F"
if a = 4 then bl$ = bl$ + "G"
if a = 5 then bl$ = bl$ + "A"
if a = 6 then bl$ = bl$ + "B"
goto nextnote
endif
if right$(bl$,1) = "D"
`D must be followed by G
bl$ = bl$ + "G"
goto nextnote
endif
if right$(bl$,1) = "E"
`E must be followed by F, G, or A
a = rnd(2)
if a = 0 then bl$ = bl$ + "F"
if a = 1 then bl$ = bl$ + "G"
if a = 2 then bl$ = bl$ + "A"
goto nextnote
endif
if right$(bl$,1) = "F"
`E must be followed by F, G, or A
a = rnd(2)
if a = 0 then bl$ = bl$ + "F"
if a = 1 then bl$ = bl$ + "G"
if a = 2 then bl$ = bl$ + "A"
goto nextnote
endif
if right$(bl$,1) = "A"
`A must be followed by F, G, or D
a = rnd(2)
if a = 0 then bl$ = bl$ + "F"
if a = 1 then bl$ = bl$ + "G"
if a = 2 then bl$ = bl$ + "D"
goto nextnote
endif
if right$(bl$,1) = "B"
`B must be followed by G
bl$ = bl$ + "G"
endif
nextnote:
next b
r = rnd(1)
bl$ = bl$ + "C"
`The last chord in a C Major progression must be C, otherwise it will sound bad.
`Well... This isn't totally true, but for these purposes, I will pretend it is.
`Create a bassline, which is just the 4 chords repeated over and over and over and over...
bassline$ = ""
for b = 1 to 10
bassline$ = bassline$ + bl$
next b
savebass$ = bassline$
endif
print "Creating melody notes..."
sync
`Create Treble Notes
for x = 1 to 12
l = int(500*tempo#)
createsound(name$(x)+"2",x+12,l,note#(x)*2)`quarter notes
l = int(1000*tempo#)
createsound(name$(x)+"3",x+24,l,note#(x)*2)`eight notes
print str$(x) + " / " + "12":sync
next x
set text font "arial"
set text size 16
chrd = 0
btmr = 0
ttmr = 0
cls
if loadsong = 0
print "Creating Sequence"
sync
note = 13
`Generate a completely random list of notes
list2$ = ""
for x = 1 to 21
a = rnd(6)
if a = 0 then list2$ = list2$ + "C"
if a = 1 then list2$ = list2$ + "D"
if a = 2 then list2$ = list2$ + "E"
if a = 3 then list2$ = list2$ + "F"
if a = 4 then list2$ = list2$ + "G"
if a = 5 then list2$ = list2$ + "A"
if a = 6 then list2$ = list2$ + "B"
next x
`Replace each note with a pattern
`Every other pattern must end in C.
`Otherwise, it will still sound random.
`Each note is followed by a number.
`This number has to do with rhytm:
`1 = Eigth note, 2 = Quarter note
`Each sequence add's up to a length of 8
endnote = 0
list$ = ""
while len(list2$) > 1
endnote = endnote + 1
n$ = left$(list2$,1)
list2$ = right$(list2$,len(list2$) - 1)
if endnote = 1
if n$ = "C" then list$ = list$ + "C1D1E1F1G1A1B1C1"
if n$ = "D" then list$ = list$ + "C2C1D1E2D1C1"
if n$ = "E" then list$ = list$ + "D2D2G1F1E1D1"
if n$ = "F" then list$ = list$ + "C1D2E1F2G1A1"
if n$ = "G" then list$ = list$ + "C2G2C2G2"
if n$ = "A" then list$ = list$ + "F1G1F1E1D2G2"
if n$ = "B" then list$ = list$ + "C1C1G2C1C1G2"
endif
if endnote = 2
if n$ = "C" then list$ = list$ + "G1G1F2E1E1D1C1"
if n$ = "D" then list$ = list$ + "G1A1B1G1F1E1D1C1"
if n$ = "E" then list$ = list$ + "F1E1D1C1E1D1C2"
if n$ = "F" then list$ = list$ + "C1E1G1C1E1G1C2"
if n$ = "G" then list$ = list$ + "C1C2C2C1C2"
if n$ = "A" then list$ = list$ + "F1E2C1B1A1C2"
if n$ = "B" then list$ = list$ + "G1C1D1C1D1C1C2"
endnote = 0
endif
endwhile
saveseq$ = list$
endif
loadsong = 0
do
cls
tmr = timer()
btmr = btmr + 1
ttmr# = ttmr# + .5
if btmr = 4
b$ = left$(bassline$,1)
if b$ = "C" then play sound 1
if b$ = "D" then play sound 3
if b$ = "E" then play sound 5
if b$ = "F" then play sound 6
if b$ = "G" then play sound 8
if b$ = "A" then play sound 10
if b$ = "B" then play sound 12
bassline$ = right$(bassline$,len(bassline$) - 1)
btmr = 0
endif
if ttmr# = .5
ttmr# = 0
n$ = left$(list$,2)
if n$ = "C1" then play sound 13
if n$ = "D1" then play sound 15
if n$ = "E1" then play sound 17
if n$ = "F1" then play sound 18
if n$ = "G1" then play sound 20
if n$ = "A1" then play sound 22
if n$ = "B1" then play sound 24
if n$ = "C2" then play sound 25:ttmr# = -.5
if n$ = "D2" then play sound 27:ttmr# = -.5
if n$ = "E2" then play sound 29:ttmr# = -.5
if n$ = "F2" then play sound 30:ttmr# = -.5
if n$ = "G2" then play sound 32:ttmr# = -.5
if n$ = "A2" then play sound 34:ttmr# = -.5
if n$ = "B2" then play sound 36:ttmr# = -.5
list$ = right$(list$,len(list$) - 2)
endif
Print "Press <SPACE> to restart / replay song."
print "Press <SHIFT> to make a new song."
print "Press S to save your song."
print "Press L to load a song."
while timer() - tmr < 300* tempo#
if spacekey() = 1
list$ = saveseq$
bassline$ = savebass$
btmr = 0
ttmr# = 0
endif
if shiftkey() = 1 then goto beginningofcode
if keystate(31) = 1 then gosub savesong
if keystate(38) = 1 then gosub loadsong:goto beginningofcode
endwhile
loop
savesong:
clear entry buffer
input "What is the name of this song?", name$
filename$ = name$ + ".sng"
if file exist(filename$) = 1
`input "This song already exists, do you want to replace it?", del$
`if del$ = "Y" or del$ = "y" or del$ = "yes" or del$ = "Yes" or del$ = "YES"
delete file filename$
`endif
endif
`if del$ <> "Y" and del$ <> "y" and del$ <> "yes" and del$ <> "Yes" and del$ <> "YES"
open to write 1, filename$
write float 1, tempo#
write long 1, keychange
write string 1, savebass$
write string 1, saveseq$
close file 1
`endif
return
loadsong:
clear entry buffer
input "What is the name of the song you want to load?", name$
filename$ = name$ + ".sng"
if file exist(filename$) = 1
open to read 1, filename$
read float 1, tempo#
read long 1, keychange
read string 1, savebass$
read string 1, saveseq$
close file 1
bassline$ = savebass$
list$ = saveseq$
loadsong = 1
print bassline$
print list$
else
endif
return
function createsound(name$,soundnumber,length#,pitch#)
if file exist(name$+".wav")=1 then delete file name$+".wav"
open to write 1,name$+".wav"
chunk=int(((length#/1000)*44100*16)/8) `sample size (no of samples * bitrate * channels / 8)
samples=int((length#/1000)*44100) `length *44100
restore
for x=1 to 40
read byte2
write byte 1, byte2
next x
write long 1,chunk
rem generate and write wave
thing# = 0
for x=1 to samples
inc thing#,pitch#*1
if thing#>10000 then thing#=0
output#=thing#
write word 1,output#
next x
close file 1
load sound name$+".wav",soundnumber
data 82:data 73:data 70:data 70:data 208:data 59:data 1:data 0:data 87
data 65:data 86:data 69:data 102:data 109:data 116:data 32:data 16
data 0:data 0:data 0:data 1:data 0:data 2:data 0:data 34:data 86:data 0
data 0:data 136:data 88:data 1:data 0:data 4:data 0:data 16:data 0
data 100:data 97:data 116:data 97
endfunction