Guidance
指路人
g.yi.org
software / rapidq / Examples / Audio & Video / wavefile.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $INCLUDE "rapidq.inc"

     DIM file AS QFILESTREAM

     DECLARE SUB makefile
     DECLARE SUB closeprog
     file.OPEN ("wavefile.wav", fmcreate)

     CREATE form AS QFORM
      height=180
      width=450
      center
      borderstyle=bsdialog

      CREATE wavefilename AS QEDIT
       top=10
       left=10
       width=100
       height=26
      END CREATE
      CREATE playbutton AS QBUTTON
       CAPTION="make"
       top=50
       left=150
       height=22
       onclick=makefile
      END CREATE
      CREATE closebutton AS QBUTTON
       CAPTION="close"
       top=10
       left=150
       height=22
       onclick=closeprog
      END CREATE
      SHOWMODAL
     END CREATE

     SUB makefile
      file.writestr("RIFF",4) ' indicates wave file header chunk
      file.writenum(180,1) ' total length of package to follow, 4 bytes
      file.writenum(1,1) ' ie. total length minus 8
      file.writenum(0,1) ' if value is AABBCCDD write DDCCBBAA
      file.writenum(0,1) ' "little endian" ie. little written first? :p
' seems bloody backwards to me
      file.writestr("WAVE",4)

' begin format chunk
      file.writestr("fmt ",4)
      file.writenum(16,1) ' length of format chunk
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(1,1) ' required
      file.writenum(0,1) ' required
      file.writenum(1,1) ' # of channels 1/mono 2/stereo
      file.writenum(0,1)
      file.writenum(68,1) ' sample rate in Hz
      file.writenum(172,1) ' 44100 = 0000ac44
      file.writenum(0,1) ' ac=172, 44=68...
      file.writenum(0,1)
      file.writenum(136,1) ' bytes per second
      file.writenum(88,1) ' 136,88,1,0=88200,16bit44100
      file.writenum(1,1)
      file.writenum(0,1)
      file.writenum(2,1) ' bytes per sample
      file.writenum(0,1) ' 1=8bit m, 2=8s or 16m, 4=16s
      file.writenum(16,1) ' bits per sample
      file.writenum(0,1)

' begin data chunk
      file.writestr("data",4)
      file.writenum(144,1) ' length of data to follow, 4 bytes
      file.writenum(1,1)
      file.writenum(0,1)
      file.writenum(0,1)

      FOR t=1 TO 100
       file.writenum(255,1) ' data here to end
       file.writenum(127,1)

       file.writenum(0,1)
       file.writenum(128,1) ' this second byte is the larger value,
' as for all data 0-127=positive value.. 128-255=negative value..
' note that 128=max. negative value, whereas 255=minimal negative value,
' ie. just shy of the DC 0 line... geddit?
      NEXT t




      file.CLOSE
      RENAME (DIR$("wavefile.wav",faanyfile),wavefilename.text+".wav")
     END SUB

     SUB closeprog
      form.CLOSE
      END
     END SUB

掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Thu 2024-5-30  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:40:32