

  $ FileName "t.exe"
  'uses rtl32
  uses minwin

  'http://www.tactilemedia.com/info/MCI_Control_Info.html

  type WaveFormat 
    word  wFormatTag; 
    word  nChannels; 
    dword nSamplesPerSec; 
    dword nAvgBytesPerSec; 
    word  nBlockAlign; 
    word  wBitsPerSample; 
  end type

'16 bytes



  type WaveFileHeader
    dword   RiffLabel
    dword   FileSize
    dword   WaveLabel
    dword   fmtLabel
    dword   WaveFormatSize
    WaveFormat
    dword   DataLabel
    dword   DataSize
  end type '44 bytes

'44 bytes

  '#recordof WaveFileHeader

  string wav
  string fi
  fi="beep.wav"
  sys le=10000
  sys j        'wavelength counter
  short v=2000 'amplitude (max range -32768 to +32767)
  short *d     '16 bit stereo wave data
  wav=nuls(le+44)
  @d=*wav+44
  '
  'CREATE SQUARE WAVES
  '
  int i
  for i=1 to <10000 step 4
    d<=v,v 'LEFT AND RIGHT STEREO VALUES
    @d+=4
    j++ : if j>=50 then v=-v : j=0 '441 Hz (middle A=440Hz)
  next
  '
  dword DataSize=le
  dword FileSize=DataSize+SizeOf WaveFileHeader
  WaveFileHeader *wf
  @wf=*wav
  dword lbriff=0x46464952,lbwave=0x45564157,lbfmt=0x20746d66,lbdata=0x61746164
  wf<= lbriff,fileSize,lbwave,lbfmt,16,1,2,44100,176400,4,16,lbdata,DataSize
  SetLastError 0
  putfile fi,wav 'about 10 megs per minute!
  int a=GetLastError
  if a=6 then print "Error 6: saving '" fi "'. Is it being used by another program?"


