'===========================================================================
' Subject: MAKE A WAV FILE                    Date: 06-21-96 (22:03)       
'  Author: Tony Cave                          Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: SOUND.ABC
'===========================================================================
'This program makes WAV files by using formulas for the data
'Run as is, it will create a wave file called MOCK.WAV, but
'you can change it to make whatever sounds you want.
'You must specify the size of the output file.  If you're not
'sure how long it will be then go ahead and run it, and see
'how big it is then run it with the correct FileSize.  Some
'WAV players can't play it if the FileSize is incorrect.

ID$ = "SOBLA3.BAS (c)1996 by tony cave"
WavFile$ = "mock.wav"
FileSize = 4952                 'in bytes

DIM RiffID           AS STRING * 4
DIM RiffLength       AS LONG
DIM WavID            AS STRING * 4
DIM FmtID            AS STRING * 4
DIM FmtLength        AS LONG
DIM wavformattag     AS INTEGER
DIM Channels         AS INTEGER
DIM SamplesPerSec    AS INTEGER
DIM BytesPerSec      AS INTEGER
DIM BlockAlign       AS INTEGER
DIM FmtSpecific      AS INTEGER
DIM Padding          AS STRING * 4
DIM DataID           AS STRING * 4
DIM DataLength       AS LONG

RiffID = "RIFF"                 'must be "RIFF"
RiffLength = FileSize - 8       'FileSize - 8
WavID = "WAVE"                  'must be "WAVE"
FmtID = "fmt "                  'must be "fmt "
FmtLength = 16
wavformattag = 1                '1=PCM
Channels = 1                    '1=stereo, 2=stereo
SamplesPerSec = 11025           '11025 22050 -21436(44100)
BytesPerSec = 0
BlockAlign = 11025
FmtSpecific = 0
Padding = CHR$(1) + CHR$(0) + CHR$(8) + CHR$(0)
                                'only if FmtLength = 16

DataID = "data"                 'must be "data"
DataLength = FileSize - 44      'FileSize - 44
                                'the header is 44 bytes
OPEN WavFile$ FOR BINARY AS #1
PUT #1, , RiffID
PUT #1, , RiffLength
PUT #1, , WavID
PUT #1, , FmtID
PUT #1, , FmtLength
PUT #1, , wavformattag
PUT #1, , Channels
PUT #1, , SamplesPerSec
PUT #1, , BytesPerSec
PUT #1, , BlockAlign
PUT #1, , FmtSpecific
PUT #1, , Padding
PUT #1, , DataID
PUT #1, , DataLength

'The following is the formula for my wave, but you don't have to
'use SIN(), you can use anything, even random numbers, but random
'numbers probably won't sound very good.  Have fun!

ont$ = CHR$(192)
sf$ = CHR$(64)
a$ = " "
t$ = CHR$(128)

FOR t = 1 TO 60
FOR x = 0 TO 255 STEP t
x$ = CHR$((SIN(x * .0245) + 1) * 64 + 64)
PUT #1, , x$
NEXT
NEXT

FOR t = 1 TO 60
FOR x = 0 TO 255 STEP t
PUT #1, , t$
NEXT
NEXT

FOR t = 1 TO 60
FOR x = 0 TO 255 STEP t
x$ = CHR$((SIN(x * .0245) + 1) * 64 + 64)
PUT #1, , x$
NEXT
NEXT

FOR t = 1 TO 60
FOR x = 0 TO 255 STEP 61 - t
x$ = CHR$((SIN(x * .0245) + 1) * 64 + 64)
PUT #1, , x$
NEXT
NEXT

SYSTEM
