Hi,
I asked about wave-files not long ago and wrote the following test-program, but the created file cannot be played with the mediaplayer.
Why not? Can anyone help me?
CreateFile(0,"wavtest.wav")
WriteString("RIFF")
WriteLong(932)
WriteString("WAVEfmt ")
WriteLong(16)
WriteWord(1)
WriteWord(2)
WriteLong(22050)
WriteLong(44100)
WriteWord(4)
WriteWord(16)
WriteString("data")
WriteLong(880)
For a = 0 To 10
WriteLong(0)
Next
For a = 0 To 100
WriteLong(65536)
WriteLong(-65536)
Next
For a = 0 To 10
WriteLong(0)
Next
;- 04.09.03 by Froggerprogger
;- 04.09.03 by Froggerprogger
;-
;- Tip: You can replace the byte-text-output with the following:
;-
;- WriteLong($46464952) = "RIFF"
;- WriteLong($45564157) = "WAVE"
;- WriteLong($20746D66) = "fmt "
;-
;- You can even use WriteString("RIFF") and WriteString("WAVEfmt "), because PB doesn't write a
;- terminating 0 - but I don't like this way, perhaps it's too easy ;-)
;-
;- For further information on the WAV-format look at: http://www.sonicspot.com/guide/wavefiles.html
#pi = 3.141593 ; pi
#fq = 220 ; frequenz in Hz for sinustone
#samplerate = 44100 ; samplerate
#bitrate = 16 ; Bits per sample, #bitrate Mod 8 must be 0 !
#channels = 2 ; number of channels
#secs = 4 ; time for the sinustone in seconds
#soundfilename.s = "wavtest.wav" ; filename fr the soundfile
avBytesPerSec.l = #channels*#bitrate/8*#samplerate ; calculate the average bytes per second
CreateFile(0, #soundfilename)
WriteByte(Asc("R")) ; here you can use WriteLong($46464952) instead - see the tip on top
WriteByte(Asc("I"))
WriteByte(Asc("F"))
WriteByte(Asc("F"))
WriteLong(36+avBytesPerSec*#secs) ; normally filesize - 8 Bytes, here a bit tricky, fmt-chunk + data-chunk
WriteByte(Asc("W"))
WriteByte(Asc("A"))
WriteByte(Asc("V"))
WriteByte(Asc("E"))
WriteByte(Asc("f"))
WriteByte(Asc("m"))
WriteByte(Asc("t"))
WriteByte(Asc(" "))
WriteLong(16) ; chunk data size
WriteWord(1) ; compression code
WriteWord(#channels) ; number of channels
WriteLong(#samplerate) ; samplerate
WriteLong(avBytesPerSec) ; average bytes per second, here 2(channels)*2(block align)*44100(samplerate)
WriteWord(#bitrate/8*#channels) ; Block Align ('bytes per sample')
WriteWord(#bitrate) ; Bits per sample
WriteByte(Asc("d"))
WriteByte(Asc("a"))
WriteByte(Asc("t"))
WriteByte(Asc("a"))
WriteLong(avBytesPerSec*#secs) ; data chunk size in byes
Global actsamplevalue.w ; for signed RAW data
For acttime = 1 To #samplerate * #secs
For actchannel = 1 To #channels
actsamplevalue = 32767 * Sin(2 * #pi * #fq * acttime / #samplerate)
WriteWord(actsamplevalue)
Next
Next
CloseFile(0)
@freak
Thanks for this! I haven't known, but the 'xxx' is a very cool compiler-feature !
@Dreglor
For example here you'll find information on the possible wav-chunks. The data-chunk is the one storing the uncompressed RAW-data. http://www.sonicspot.com/guide/wavefiles.html
@freak
Thanks for this! I haven't known, but the 'xxx' is a very cool compiler-feature !
Freak, would you write a little extension for the manual about this feature, please ?
debug 'A'
debug 'a'
debug 'HA'
debug 'HALL'
'xxxx' is the same like
string.s="xxxx"
debug peekl(@string)
'xx'
string.s="xx"
debug peekw(@string)
'x'
string.s="x"
debug peekb(@string)
debug asc(string)
;'HALL' is the same like PeekL("LLAH")
Debug 'HALL'
string.s="LLAH"
Debug PeekL(@string)
;'HAL' is the same like PeekL("LAH")
Debug 'HAL'
string.s="LAH"
Debug PeekL(@string)
;'HA' is the same like PeekL("AH")
Debug 'HA'
string.s="AH"
Debug PeekL(@string)
Debug PeekW(@string)
;'H' is (of course) the same like PeekL("H")
Debug 'H'
string.s="H"
Debug PeekL(@string)
Debug PeekW(@string)
Debug PeekB(@string)
Debug Asc(string)