home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
coders
/
jËzyki_programowania
/
logo
/
powerlogo
/
examples
/
music
< prev
next >
Wrap
Text File
|
1992-11-10
|
10KB
|
338 lines
; *********************************************************************
; An example music synthisizer
; *********************************************************************
make "preppiano [
procedure [ [ ] [ ]
[ :data :bytes :freq :period :note :octive
:envelopedata :sindata ] ]
if and namep "w1 namep "t1 [ ] [ turtle-fm ]
if namep "piano-list
[ ]
[
make "envelopedata ( system 3 1000 )
prepenvelope 10000000 0.8 100 0.7 0.5
make "piano-list [ ]
make "octive 1
make "freq ( * 0.25 :octive item 24 :scaledata )
make "bytes ( * :freq 64 0.3 )
repeat 4 [
make "data ( system 4 :bytes )
loadnote :data :bytes * :freq 0.3 :octive
make "note 1
repeat 12 [
make "period round item :note :scaledata
make "piano-list lput ( se :data
/ * :bytes
item + 1 :note
:scaledata
item 24 :scaledata
:period
64
1 )
:piano-list
make "note + 2 :note ]
make "octive * 2 :octive ]
( system 5 :envelopedata )
]
make "notelist :piano-list ]
; *********************************************************************
make "preptone [
procedure [ [ ] [ ] [ :i :p :n ] ]
if and namep "w1 namep "t1 [ ] [ turtle-fm ]
if namep "tone-list
[ ]
[
make "data ( system 4 ( + 8 16 32 64 ) )
make "i 0
repeat 64 [
poke 1 ( psum :data :i ) * 126 sin * 5.625 :i
make "i + 1 :i ]
make "i 0
repeat 32 [
poke 1 ( psum :data :i 64 ) * 126 sin * 11.25 :i
make "i + 1 :i ]
make "i 0
repeat 16 [
poke 1 ( psum :data :i 96 ) * 126 sin * 22.5 :i
make "i + 1 :i ]
make "i 0
repeat 8 [
poke 1 ( psum :data :i 112 ) * 126 sin * 45 :i
make "i + 1 :i ]
make "tone-list [ ]
make "i 64
repeat 4 [
make "n 1
repeat 12 [
make "p round item :n :scaledata
make "tone-list lput ( se :data
:i
:p
64
/ 300000
( * :p :i 0.279 ) )
:tone-list
make "n + 2 :n ]
make "i / :i 2 ]
]
make "notelist :tone-list ]
; *********************************************************************
make "playnotelist [
procedure [ [ ] [ ] [ :n ] ]
make "n 1
repeat 48 [
sound [ ] [ ] [ ] item :n :notelist
make "n + 1 :n ] ]
make "randnotes [
procedure [ ]
repeat 48 [
sound item + 1 random 48 :notelist
item + 1 random 48 :notelist
item + 1 random 48 :notelist
item + 1 random 48 :notelist ] ]
make "keyboard [
procedure [ [ ] [ ] [ :k :o ] ]
pr [ Click the Fractal Music window. ]
repeat 1000000 [
make "k ascii rc
if > :k 96
[ make "k - :k 96
make "o 0 ]
[ make "k - :k 64
make "o 24 ]
if and < :k 25 > :k 0 [ sound [ ] [ ] [ ] item + :k :o :notelist ] [ ] ] ]
make "midpoint [
procedure [ [ :range :factor :depth ] ]
make "a + 24 * 48 20
sound item + 1 remainder :a 48 :notelist [ ] [ ] [ ]
midpoint-1 :range :depth :a :a
stop ]
make "midpoint-1 [
procedure [ [ :range :depth :a :b ] [ ] [ :x ] ]
make "depth - :depth 1
if < :depth 1 [
sound item int + 1 remainder :b 48 :notelist [ ] [ ] [ ]
stop ] [ ]
make "x + - random :range random :range / + :a :b 2
make "range * :range :factor
midpoint-1 :range :depth :a :x
midpoint-1 :range :depth :x :b
stop ]
; *********************************************************************
; turtle-fm
; Prepare window, and turtle for turtle fractal music.
make "turtle-fm [
procedure [ ]
recycle
make "w1 ( openwindow @0 3 [ Fractal Music ] 150 0 340 120 )
make "t1 ( openturtle :w1 1 ) ]
make "turtlesound [
procedure [ ]
make "t tpos :t1
sound [ ]
item + remainder + int * :scalefactor
item 2
:t
10000
48
1
:notelist
item + remainder + int * :scalefactor
first :t
10000
48
1
:notelist
[ ] ]
make "scalefactor 0.5
; *********************************************************************
; tree size limit factor angle
; A musical turtle tree.
; tree 50 5 0.5 45
; tree 50 2 0.7 90
; tree 40 3 0.6 15
make "tree [
procedure [ [ :size :limit :f :angle ] ]
if < :size :limit [
fd :size
turtlesound
bk :size
turtlesound
stop ] [ ]
fd :size
turtlesound
rt :angle
tree * :size :f :limit :f :angle
lt + :angle :angle
tree * :size :f :limit :f :angle
rt :angle
bk :size
turtlesound ]
; *********************************************************************
; s-dragon size limit angle
; Musical size limit dragon.
; s-dragon 50 5 45
make "s-dragon [
procedure [ [ :size :size-limit :angle1 ] [ ] [ :leg1 :leg2 :angle2 ] ]
make "angle2 - 90 :angle1
make "leg1 / * 0.5 sin - 180 * 2 :angle1 sin :angle1
make "leg2 / * 0.5 sin - 180 * 2 :angle2 sin :angle2
s-dragon1 :size 1 ]
make "s-dragon1 [
procedure [ [ :size :par ] ]
if > :size-limit :size
[ fd :size
turtlesound
stop ] [ ]
if >0 :par
[ rt :angle1
s-dragon1 * :size :leg1 1
lt 90
s-dragon1 * :size :leg2 -1
rt :angle2 ]
[ lt :angle2
s-dragon1 * :size :leg2 1
rt 90
s-dragon1 * :size :leg1 -1
lt :angle1 ] ]
; Lots of dragons.
make "s-dragons [
procedure [ [ ] [ ] [ :angle :size-limit ] ]
make "size-limit 80
while [ make "size-limit / :size-limit 3 > :size-limit 0.5 ] [
make "angle 0
while [ make "angle + :angle 5 < :angle 90 ] [
clean
home
pu
lt 70
bk 52
lt 20
pd
s-dragon 100 :size-limit :angle ] ] ]
; *********************************************************************
make "scaledata [ ; 16 samples per cycle
253.7693006 880.8
240.0257455 932.3
225.5205576 987.8
214.2251770 1046.5
202.2188712 1108.7
189.5481953 1174.7
180.2317162 1244.5
170.3229483 1318.5
159.8398055 1396.9
150.8369330 1480.0
143.3199104 1568.0
135.3258509 1661.2 ]
make "envelope [
procedure [ [ :x ] [ ] ]
make "x - 1 :x
op ( + * :e1b
sin * 180
/ power :e1a
:x
:e1a
* :e2b
sin * 180
/ power :e2a
:x
:e2a
* :e3
sin * 180
:x ) ]
make "prepenvelope [
procedure [ [ :e1a :e1b :e2a :e2b :e3 ] [ ]
[ :x :y :q :ef ] ]
make "x 0
make "sindata [ ]
repeat 64 [
make "sindata lput * ( + sin * :x 5.625
/ sin * :x 11.25
3
/ sin * :x 22.5
5 )
0.326086957
:sindata
make "x + 1 :x ]
make "ef 0
make "y 0
make "x 0
while [ >= :y :ef ] [
make "ef :y
make "y envelope / :x 1000
make "x + 1 :x ]
make "x 0
repeat 1000 [
make "q / :x 1000
make "y / * envelope :q
253
:ef
poke 1 psum :envelopedata :x :y
make "x + 1 :x ] ]
make "loadnote [
procedure [ [ :data :bytes :cycles :octive ] [ ]
[ :x :y :xx ] ]
make "xx 1
make "x 0
repeat :bytes [
make "y * item :xx :sindata
peek 1 psum :envelopedata * 1000 / :x :bytes
poke 1 psum :data :x :y
make "xx + :octive :xx
if >= :xx 64 [ make "xx 1 ] [ ]
make "x + 1 :x ] ]
; *********************************************************************
pr [ ]
pr [ A LOGO sound example. ]
pr [ ]
pr [ To use these you must first run "preptone" or "preppiano". ]
pr [ "preptone" takes a few seconds. ]
pr [ "preppiano" takes about 16 minutes, but sounds better. ]
pr [ ]
pr [ You may then use these noise makers: ]
pr [ ]
pr [ playnotelist ]
pr [ randnotes ]
pr [ keyboard ]
pr [ midpoint 20 0.6 6 ]
pr [ home clean tree 20 4 0.7 45 ]
pr [ home clean s-dragon 50 5 45 ]
pr [ ]
pr [ Try different numbers. ]
pr [ ]