Wav files

BlitzPlus Forums/BlitzPlus Programming/Wav files

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

The wav-header writer was written by someone else I think, doesn't look like my style,
well here it is, set up like a function. Play around with it and see what you get:

Function WriteWavHeader(File%, Channels%, Frequency%, Bits%, Samples%)

	Local SampleSize% = Channels% * (Bits% / 8)
	Local WavSize%    = (Samples% * SampleSize%) + 52 ; Size of the wave file - include room for headers
	
	; "RIFF" header text
	WriteByte File%, 82
	WriteByte File%, 73
	WriteByte File%, 70
	WriteByte File%, 70
	
	; Size of the wav file not including the "RIFF" header and this 4-byte file size
	WriteInt File%, WavSize% - 8
	
	; "WAVE" header text
	WriteByte File%, 87
	WriteByte File%, 65
	WriteByte File%, 86
	WriteByte File%, 69
	
	; "fmt " header text
	WriteByte File%, 102
	WriteByte File%, 109
	WriteByte File%, 116
	WriteByte File%, 32
	
	 ; Size of the "fmt " section
	WriteInt File%, 18
	
	; Format - PCM
	WriteByte File%, $01
	WriteByte File%, $00
	
	; Channels
	WriteByte File%,  Channels% And $FF
	WriteByte File%, (Channels% And $FF00) Shr 8
	
	; Samples per second
	WriteInt File%, Frequency%
	
	; Average bytes per second
	WriteInt File%, Frequency% * SampleSize%
	
	; Block align
	WriteByte File%,  SampleSize% And $FF
	WriteByte File%, (SampleSize% And $FF00) Shr 8
	
	; Bits per sample
	WriteByte File%,  Bits% And $FF
	WriteByte File%, (Bits% And $FF00) Shr 8
	
	; Amount of extra information bytes
	WriteByte File%, $00
	WriteByte File%, $00
	
	; "data" header text
	WriteByte File%, 100
	WriteByte File%, 97
	WriteByte File%, 116
	WriteByte File%, 97
	
	; Size of the data section
	WriteInt File%, WavSize% - 52

End Function


After you written the wav-header just fill inn the wav-data.
Use some sine-curves to get you started.