The J script d:\withj\02\withj02.ijs
NB. Script withj02.ijs for creating wave files from notes.
NB. Sample fractal music "smoke puffs" is created  fractal music
NB. Associated with "With J: Musical Smoke Puffs", APL Quote Quad
NB. Cliff Reiter, Last Modified 1998; 12-15
NB. 
NB. Running the script creates 'sp.wav' which may be listened to using sound recorder.
NB. 

requires 'files'

ic=: 3!:4
j2l=:2&ic
j2i=: 1&ic

waveheader=:3 : 0   NB. y. is input data size
1 22050 22050 1 8 waveheader y.
:
'chan sampr Bpsec Bpsamp bpchan'=.x.
'RIFF',(j2l 36+y.),'WAVEfmt ',(16 0 0 0 1 0{a.),(j2i chan),(j2l sampr,Bpsec),(j2i Bpsamp,bpchan),'data',j2l y.
)

note=:3 : 0 "0  NB. x. is duration, y. is freq
1r8 note y.
:
<a.{~<.127.999*>:1 o. (2p1*<.0.5+y.*x.)*(i.%])<.0.5+22050*x.
)

nstereo=:;@:(,@|:@,:&.>/"1)@:note        NB. stero
wwavestereo=:(2 22050 44100 1 8&waveheader@#,])@[ fwrite ]

cile=: $@] $ ((/:@/:@] <.@:* (% #)),)
f19cile=:{&(110*2^1r6*i.19)@(19&cile)

sin=:1&o.
cos=:2&o.
four=:1: ,. cos ,. cos@+: ,. sin ,. sin@+:
x=:+/ . *
CMM=:1 : '2p1&|@(+({.x m."_ x{:)@:four) f.'
dat=:_0.62 0.33 0.93 _0.59 0.05 _0.48
ind=:0 1 4;1 1 3;2 1 4;3 0 1;4 0 0;4 0 2
spp=:dat ind}5 2 5$0
f=:spp CMM
f^:(i.4) 0.3 0.4
fsp=:f19cile f^:(1000+i.200) 0.3 0.4

s=:1r6 nstereo fsp        NB. create stereo notes
s wwavestereo 'sp.wav'    NB. write sound to wave file

NB. wd' winexec "C:\WINNT\system32\mplay32.exe sp.wav";'
NB. Sample syntax for starting a media window to play the wave file from J