Dear Gareth
I hope that you are already familiar with wave file format.
Wave files have a RIFF header at the top and then a number of
different chunks after that. These chunks are "data" chunks, "fmt"
chunks etc.
"fmt" chunks describe the format of the waveform data in wavefile.
E.g. they describe sampling frequency, number of channels, bitrate
etc.
"data" chunks contain the actual waveform data.
For details, look at
http://www.sonicspot.com/guide/wavefiles.html
For your program, you need to send format chunks first to the
receiving computer. This helps the receiving computer open the wave
device accordingly as the paramters in it. Then you need to send the
data chunks. Since in most of the wavefiles, there is only one data
chunk, it might be very big in size to fit into one UDP sendto(). So
you can split the waveform data in the single data chunk in the wave
file in question into multiple data chunks and send them one by one
over UDP using sendto.
E.g if the wave file contains 10240 bytes of waveform in each of data
chunk, you can split it into 10 udp sendto of 1024 bytes each.
Thus the buffer for sendto() to send actual waveform data should look like:
struct wave_data
{
unsigned long int size;
char wave_form_data[1024];
}
At the receiving end, the data chunks containing waveform should be
converted to WAVEHDR using waveOutPrepareHeader before passing to
waveOutWrite.
Important:
Please make sure that you poll for 'WHDR_DONE' over 'dwFlags' in
WAVEHDR. If your programs terminates before WAVEHDR buffer is played
fully by sound driver, then no sound would be audible.
Before playing the wavefile over network, make sure that you are able
to play the chunks prepared locally. Once it works, network enabling
is quite easy..
I have developed a sample code (LCC-Win32) for playing wavefile
locally which can be enhanced easily. If you need, then you can
indicate.
Please ask if you need more help or anything is unclear. |