I've looked all over for an example of how to create a Wave file.
No luck.

Plenty of examples of how to use one.

Any ideas where I can find one????

EX: want to create a wave file to sound middle C.
Frequency 261.63 Wavelength 132 cm

Any help would be very much appreciated.
JPS
Posted on 2003-03-07 08:13:49 by shankle
now, open a very small 16-bit 44100 mono wavefile you have at your HDD. If you do not have one, create with Record. Make sure you convert it to that format. No matter whether it's a silent wave or anything. While looking at the structure definition of the waveheader ("fmt ") chunk, see the hex-editor view of the file (so that you can see the "RIFF" and "data" texts). Aww, here's the structure:

WaveFile struct
RIFF dd "FFIR" ; note that it's reversed. Do not modify
TotalSize dd ? ; fill later !
WAVE dd "EVAW"
FMT dd " tmf"
fmtsiz dd 16
format dw 1
channels dw 1
samplespers dd 44100
avgbytesps dd 88200
blockali dw 2
bitspersa dw 16
datum dd "ATAD"
datumsiz dd ? ; fill later!
WaveFile ends


TotalSize = (2 * SamplesNum) + 32
,where SamplesNum is the number of samples :P
datumsiz = 2 * SamplesNum

after you fill in these 2 variables, write the whole structure into a file. The next thing to write in the file is the waveform itself.

To create it, first allocate some memory
.data
HEAP1 dd 0
.code
invoke GetProcessHeap
mov HEAP1,eax


Then, with the help of fsin compute the sinusoidal wave, write the buffer into the file,
invoke CloseHandle,file1 ; this is the wavefile
free buffer, and you're ready.
Posted on 2003-03-07 15:37:31 by Ultrano
Here is some stuff I found a while ago on RIFF format. >> RIff Format

As well can't hurt looking through these postings >> Search Results (I've had my nose in almost all wave and sound related discussions ;) )

:alright:
NaN
Posted on 2003-03-07 21:43:11 by NaN
[b]WaveFile struct[/b]

[color=red] RIFF dd "FFIR" ; note that it's reversed. Do not modify
TotalSize dd ? ; fill later !
WAVE dd "EVAW" [/color]

[color=blue] FMT dd " tmf"
fmtsiz dd 16[/color]
format dw 1
channels dw 1
samplespers dd 44100
avgbytesps dd 88200
blockali dw 2
bitspersa dw 16

[color=blue]datum dd "ATAD"
datumsiz dd ? ; fill later![/color]
wavedata db WaveBytes dup (?)
[b]WaveFile ends[/b]


To help thinks get more clear, I spaced/indent/colored the different header areas so it should now be very clear what Ultrano has given you, and how it coresponds to the RIFF format I linked to above.

Best of luck!
:alright:
NaN
Posted on 2003-03-07 21:59:14 by NaN