Global ss_channelcount% Global ss_bpsample% Dim wavdata(0,0) Function Writewav(wavdatalen,filename$) samples=wavdatalen ;Function Writewav(nosamples,filename$) ;wavdatalen=(ss_channelcount*nosamples*(bitspersample/8))/4 bitspersample=ss_bpsample fs=WriteFile(filename$) If fs=0 Then Return 0 WriteBinString fs,"RIFF" wavlen=36+((wavdatalen*2)*ss_channelcount) WriteInt fs,wavlen Writebinstring fs,"WAVE" Writebinstring fs,"fmt " WriteInt fs,16 WriteShort fs,1 WriteShort fs,ss_channelcount WriteInt fs,samplerate bitspersample=16 byterate=SampleRate * ss_channelcount * bitspersample/8 WriteInt fs,byterate WriteShort fs,ss_channelcount * bitspersample/8 WriteShort fs,bitspersample Writebinstring fs,"data" WriteInt fs,samples*ss_channelcount * BitsPerSample/8 ;WriteInt fs,wavdatalen*4 For p=1 To wavdatalen If ss_bpsample=8 Then Midr=128 If ss_bpsample=16 Then Midr=Midbit/2.0 If ss_bpsample=32 Then Midr=(Midbit*255)/2.0 For chan=0 To ss_channelcount-1 rval=wavdata(chan,p) rval=rval-Midr If rval<0 Then rval=rval+(Midr*2) If rval<0 Then rval=0 Else If rval>(Midr*2)*2 Then rval=(Midr*2) Plot o,320+rval ;If ss_bpsample>16 Then rval=rval/2.0;WriteShort fs,rval WriteShort fs,wavdata(chan,p);rval Next Next If ss_channelcount=1 Then ster$="Mono" Else ster$="Stereo" debugprint"Created "+filename$+" as "+ss_bpsample+" bit, "+samplerate+"hz, "+ster$+" wave file." CloseFile fs End Function Function Writebigend(filehandle,number) base=number f1=base Mod 256 f2=Int(base/256) Mod 256 f3=Int(base/(256*256)) Mod 256 f4=Int(base/(256*256*256)) Mod 256 If f1<0 Then f1=256+f1 If f2<0 Then f2=256+f2 If f3<0 Then f3=256+f3 If f4<0 Then f4=256+f4 debugprint Hex(f1)+" "+Hex(f2)+" "+Hex(f3)+" "+Hex(f4) WriteByte filehandle,f4 WriteByte filehandle,f3 WriteByte filehandle,f2 WriteByte filehandle,f1 End Function Function readbigend(filehandle) num1=ReadByte(filehandle) num2=ReadByte(filehandle) num3=ReadByte(filehandle) num4=ReadByte(filehandle) base=num1 base=base+num2*256 base=base+num3*(256*256) base=base+num4*(256*256*256) Return base End Function Function WriteBinString(filehandle,dat$) For p=1 To Len(dat$) WriteByte filehandle,Asc(Mid$(dat$,p,1)) Next End Function Function ReadbinString$(filehandle,bytes) Local n,ret$ For n=1 To bytes ret$=ret$+Chr$(ReadByte(filehandle)) Next Return ret$ End Function Function Readwav(name$) fs=ReadFile(name$) If fs=0 Then RuntimeError "Cannot open "+name$ head$=Readbinstring(fs,4) If head$<>"RIFF" Then RuntimeError name$+" is not a valid wave file!" chunksize=ReadInt(fs) debugprint "chunk 1 size:"+chunksize Format$=Readbinstring(fs,4) If Format$<>"WAVE" Then RuntimeError name$+" Is not in the standard PCM format" Format2$=Readbinstring(fs,4) If Format2$<>"fmt " Then RuntimeError name$+" Is not in the standard PCM format" chunksize2=ReadInt(fs) debugprint "Chunk2 size:"+chunksize2 compFormat=ReadShort(fs) If compformat<>1 Then RuntimeError name$+" Is not in PCM format" ss_channelcount=ReadShort(fs) debugprint ss_channelcount+" ss_channelcount" samplerate=ReadInt(fs) debugprint "at "+samplerate/1000.0+" Khz" byterate=ReadInt(fs) blockalign=ReadShort(fs) ss_bpsample=ReadShort(fs) debugprint ss_bpsample+" Bits Per channel" Format3$=Readbinstring(fs,4) If Format3$<>"data" Then RuntimeError "Data Alignment Error" debugprint "Header Valid! extracting data" ;debugprint ( chunksize=chunksize+8 chunksize=chunksize-FilePos(fs) debugprint chunksize+" bytes" samples=(ss_bpsample/8)*ss_channelcount samples=chunksize/samples debugprint "("+samples+" Samples)" ;Redimention Arrays Dim wavdata(1,samples) bread=ss_bpsample/8 If ss_bpsample=8 Then Midr=128 If ss_bpsample=16 Then Midr=Midbit/2.0 If ss_bpsample=32 Then Midr=(Midbit*255)/2.0 For n=1 To samples For o=1 To ss_channelcount If bread=1 Then rval=ReadByte(fs) If bread=2 Then rval=ReadShort(fs) If bread=4 Then rval=ReadInt(fs) ;If KeyDown(1) Then End If rval>Midr Then rval=rval-Midr*2 rval=rval+Midr If o=1 Then wavdata(0,n)=rval:wavdata(1,n)=rval If o=2 Then wavdata(1,n)=rval Next Next debugprint "File Read In Successfully!" End Function Function debugprint(St$) Print st$ End Function
If these work well, let me know :)