
  uses minwin
  uses waves.h
  uses waves.inc
  '
  WaveOut w
  '
  double v
  single a,amp,freq,nfreq,basefreq,phase,phdis,vphase,pphase,pw
  single reverba,nreverba,filt,filtpr,filtba
  single volume
  sys b,bufo,d1,d2,d3
  sys i,p,q,decay,reverbt
  sys k1,k2,pc,opc,pcf
  sys note
  '

  'REVERB SETTINGS

  reverba=.25
  nreverba=.75
  reverbt=0.2*88200 'max buffersize 64k
  '
  volume=1
  amp=000
  basefreq=220
  freq=basefreq
  filtba=1
  '
  w.WavoStart 
  '
  do
    p=w.wavopos
    if p+2000>q then 'ahead ~1/40 sec

  '
  'ENVELOPE
  int i
  for i=1 to 1000

  'ENVELOPE

  if amp>=4000 then decay=1
  '
  if decay then
    amp*=.9999
    'if amp then amp-=.5
  else
    amp+=10
  end if

  '
  v=freq*q*ipuls-phdis
  phase=frac(v)
  pc=v-phase 'wave counter
  if pcf then opc=pc : pcf=0
  '
  'NEW WAVE OR PULSE
  '
  if pc>opc then
    pcf=1
    pphase=frac(.25*ipuls*q)
    vphase=frac(4*ipuls*q)
    'basefreq+=.02
    freq=basefreq
    '
    'VIBRATO (frequency modulation)
    '
    'v=sin(pi2*vphase)*basefreq*.03125
    'freq+=v
    '
    'SYNC PHASE
    '
    phdis=frac(freq*q*ipuls)-phase
    '
  end if
  '
  'GENERAL WAVE FORMS
  '
  'a+=amp*noiseInterp(pc,phase)
  'a+=amp*sawtooth(phase)
  a+=amp*triangle(phase)
  'a+=amp*square(phase)
  'a+=amp*square(phase*1.5)
  'a+=amp*sin(pi2*phase) 'sine wave
  'a+=amp*sin(pi2*phase*1.25) 'harmonic
  'a+=amp*sin(pi2*phase*1.5) 'harmonic
  'a+=amp*sin(pi2*phase*3) 'harmonic

  'PULSE WIDTH MODULATION
  '
  'pw=(1+sin(pi2*pphase))*.20
  'pw=(1+triangle(pphase))*.23
  'pw=.49-(1+sawtooth(pphase))*.245
  '
  '-FOR STRINGS
  '
  'pw=(1+sawtooth(pphase))*.245
  'pw=.45*amp/4000
  'pw=.45-.45*amp/4000
  '
  'a+=amp*pulsewidth(phase,pw) 'ph: max 0 to min <.5
  '
  'FILTER
  '
  filtpr=.1
  filt=filt*(1-filtpr)+a*filtpr
  single lp=filt       'low pass
  single hp=a-filt     'high pass
  a=lp*filtba + hp*(1-filtba) 'moving filter mix
  'a=lp*2 'boosted
  '
  'TREMOLO (amplitude modulation)
  '
  'a=a*(0+(1+sin(pi2*vphase)))*.5
  '
  'POST WITH REVERB
  '
  a*=volume
  SendToBuffer 'macro
  a=0
  '
  next


  if ++d1=10 then
    d1=0
    '
    'INCR PITCH
    '
    'basefreq*=1.0375
    basefreq*=1.25
    decay=0
    amp=0
    '
    'FADE OUT
    '
    if basefreq>2000 then volume*=.90
    '
    'EXIT
    '
    if GetAsyncKeyState 27 then exit do
    if basefreq>22050 then exit do
    if volume<.01 then exit do
    '
    if ++d2=8 then
      d2=0
      '
      'SCALE BASE CHANGE
      '
      note+=1
      basefreq=220*pow(2,note/12) 'SEMITONES
      '
      'filtba-=.1
      'if filtba<=0 then exit do
    end if
  end if

  end if

  sleep 5
  enddo
  '
  w.WavoEnd

   
