'sinus waveform create and play + save output as 16 bit mono WAV file:
SoundLenght = 10 '10 seconds
SoundRate
= _SNDRATE '44100 samples per second
Samples = SoundRate * SoundLenght
FOR GenerateSound
= 0 TO Samples
e
= e
+ .001 * _PI(2) * TAN(f
) f = f - .0001
WAV
(GenerateSound
) = SIN(e
)
FOR PlaySound
= 1 TO Samples
X = X + 1
LINE (X
, 0)-(X
, 768), &HFF000000, BF
LINE (X
- 1, 384 + WAV
(PlaySound
- 1) * 150)-(X
, 384 + WAV
(PlaySound
) * 150)
PRINT "Saving effect as EFFECT1.WAV" SAVESOUND16M WAV(), "EFFECT1.WAV"
size
AS LONG ' 4 bytes (file size) subchunksize
AS LONG ' 4 bytes (lo / hi), $00000010 for PCM audio format
AS INTEGER ' 2 bytes (0001 = standard PCM, 0101 = IBM mu-law, 0102 = IBM a-law, 0103 = IBM AVC ADPCM) channels
AS INTEGER ' 2 bytes (1 = mono, 2 = stereo) rate
AS LONG ' 4 bytes (sample rate, standard is 44100) ByteRate
AS LONG ' 4 bytes (= sample rate * number of channels * (bits per channel /8)) Block
AS INTEGER ' 2 bytes (block align = number of channels * bits per sample /8) Bits
AS INTEGER ' 2 bytes (bits per sample. 8 = 8, 16 = 16) subchunk2
AS STRING * 4 ' 4 bytes ("data") contains begin audio samples lenght
AS LONG ' 4 bytes Data block size
H16.chunk = "RIFF"
H16.size
= 44 + UBOUND(arr
) * 2 '1 channel, it create 16 bit, stereo wav file, one sample use 2 bytes for one channel
H16.fomat = "WAVE"
H16.sub1 = "fmt "
H16.subchunksize = 16
H16.format = 1
H16.channels = 1
H16.rate = 44100
H16.ByteRate = 44100 * 16 / 8
H16.Block = 2
H16.Bits = 16
H16.subchunk2 = "data"
LeftChannel = arr(audiodata) * 16384