Here is something similar, with the header in question in plain view, being dummied up. There is a Bug Report about this issue in that forum, check for the difference there.
This is a little more commented, but...the first code is much more flexible, you use an array in that case. You must be careful about mixing the volumes, you can't simply keep adding amplitude, it will clip, and you will get garbage...annoying garbage!
Actually, there is work being done as we speak on making guitar chords using samples...should be a real hoot when its done. That thread is still on this first page, check it out!
This code will produce what my friend says is the EBS test signal, 440.0 hz stereo, very annoying, but a pure sinewave, nontheless. Adding more frequencies is part of the key to making it sound pretty. I will be making chords of my own using waveform synthesis and ADSR. I will post a simple example that could be used to write something more musical, like a roll piano player, those are pretty cool, and not so tough to write, it just takes alot of time.
+ Code SnippetREM Project: siggen1
REM Created: 6/16/2007 5:05:46 PM
REM
REM ***** Main Source File *****
REM Project: binauralBeats
REM Created: 3/9/2007 7:26:52 PM
REM
REM ***** Main Source File *****
REM
#constant MAX_VOLUME = 32767
#constant WAVE_FORMAT_PCM = 1
#constant SIZEOF_WAVEFORMATEX = 18
type WAVEFORMATEX
wFormat as word
nChannels as word
nSamplesPerSec as dword
nAvgBytesPerSec as dword
nBlockAlign as word
wBitsPerSample as word
cbSize as word
endtype
global sound_block as integer
global offset as integer
global waveformatex_f as WAVEFORMATEX
global sample_rate as integer
global sample_size as integer
global num_channels as integer
global data_rate as integer
global left_frequency as float
global right_frequency as float
global thetaL as float
global thetaR as float
global deltaL as float
global deltaR as float
global wLTemp as word
global wRTemp as word
global volume as integer
global fileHandle as integer = 1
volume = MAX_VOLUME
sound_block = 1
sample_rate = 11025
sample_size = 16
num_channels = 2
data_rate = ((sample_size * num_channels) / 8) * sample_rate
left_frequency = 440.0
right_frequency = 440.0
waveformatex_f.wFormat = WAVE_FORMAT_PCM
waveformatex_f.nChannels = 2
waveformatex_f.nSamplesPerSec = 11025
waveformatex_f.nAvgBytesPerSec = 44100
waveformatex_f.nBlockAlign = 4
waveformatex_f.wBitsPerSample = 16
waveformatex_f.cbSize = SIZEOF_WAVEFORMATEX
rem WritePCMWaveFile("test.wav", 0, 0)
rem end
make memblock sound_block, 44100 + 28 rem 2 * samples + size of structure.
offset = 0
rem Make the DBPro version of the waveformatex structure. Note it is all DWORDs.
write memblock dword sound_block, offset, WAVE_FORMAT_PCM rem wFormatTag
inc offset, 4
write memblock dword sound_block, offset, num_channels rem nChannels = STEREO
inc offset, 4
write memblock dword sound_block, offset, sample_rate rem nSamplesPerSec
inc offset, 4
write memblock dword sound_block, offset, data_rate rem nAvgBytesPerSec
inc offset, 4
write memblock dword sound_block, offset, 4 rem nBlockAlign = word
inc offset, 4
write memblock dword sound_block, offset, 16 rem wBitsPerSample = 16
inc offset, 4
write memblock dword sound_block, offset, 0 rem cbSize = 0
inc offset, 4
deltaL = left_frequency * 360.0 / sample_rate
deltaR = right_frequency * 360.0 / sample_rate
thetaL = 0.0
thetaR = 180.0 * deltaR
volume = 16384
for i = 0 to 11024
wLTemp = int(sin(wrapvalue(thetaL)) * volume)
wRTemp = int(sin(wrapvalue(thetaR)) * volume)
write memblock word sound_block, offset, wLTemp
inc offset, 2
write memblock word sound_block, offset, wRTemp
inc offset, 2
inc thetaL, deltaL
inc thetaR, deltaR
next i
if sound exist(1)
delete sound 1
endif
make sound from memblock 1, sound_block
delete memblock sound_block
loop sound 1
wait key
end
function WritePCMWaveFile(filename as string, wavedata_blk as integer, ...
size as integer)
local i as integer
local j as integer
local k as integer
local wavesize as integer = 0
if file exist(filename)
delete file filename
endif
wavesize = 44100 * 1 rem 1 second
open to write 1, filename
write byte 1, asc("R")
write byte 1, asc("I")
write byte 1, asc("F")
write byte 1, asc("F")
write long 1, wavesize + 38
write byte 1, asc("W")
write byte 1, asc("A")
write byte 1, asc("V")
write byte 1, asc("E")
write byte 1, asc("f")
write byte 1, asc("m")
write byte 1, asc("t")
write byte 1, asc(" ")
write long 1, waveformatex_f.cbSize
write word 1, waveformatex_f.wFormat
write word 1, waveformatex_f.nChannels
write long 1, waveformatex_f.nSamplesPerSec
write long 1, waveformatex_f.nAvgBytesPerSec
write word 1, waveformatex_f.nBlockAlign
write word 1, waveformatex_f.wBitsPerSample
write word 1, 0
write byte 1, asc("d")
write byte 1, asc("a")
write byte 1, asc("t")
write byte 1, asc("a")
write long 1, wavesize
deltaL = 28800.0 / 11025.0 rem delta = angular rotation per sample period.
deltaR = 30240.0 / 11025.0
volume = 16384
rem FANCY NAME = 2-channel time domain sinewave generator filter.
thetaL = 0.0 rem theta is the angle at any given instant.
thetaR = 180.0 * deltaR rem signals 180 deg out of phase.
for k = 0 to 11024
wLTemp = int(sin(wrapvalue(thetaL)) * volume)
wRTemp = int(sin(wrapvalue(thetaR)) * volume)
write word 1, wLTemp
write word 1, wRTemp
inc thetaL, deltaL
inc thetaR, deltaR
next k
close file 1
endfunction
REM
There is a rem'ed out section and a function to write to a file, this is a piece of code I used to experiment with for a few days, I have some DSP code but I am building a test setup right now. I hope that you can get this working, its svery encouraging to be able to do this type of coding and it is really a good tool in game programming.
Cheers.