"Jason Cipriani" <
XXXX@XXXXX.COM >wrote in message
Quote
"James5950" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>Hello Jason,
>
>You are right, I am just try to do wave data mix at first time.
>I create two wave file by cool edit, the wave format is 44.1k, 16bit,
>stereo.
>I don't know how to start it...
Here, I dug this up from an old project I had:
pastebin.com/f6e3a9e5d
I hope that helps; it is some code snippets that read and write WAV files.
You will not quite be able to compile that code as-is, because I just pulled
the relevant parts out of a project and pasted them there. Sorry for that
but maybe it will at least give an example. In that snippet, you will see:
AudioClip - a base class I was using for all kinds of audio data.
WAVAudioClip - an AudioClip with data from a WAV file; in this code I loaded
all WAV data into an array of doubles, with values in the range [-1.0, 1.0];
you can do whatever you want; but keeping the values in a consistent range
regardless of the WAV file format itself makes mixing easier.
There are only two functions in WAVAudioClip worth looking at for you:
_read_header find and reads the WAV format header, and also determines the
location of the start of the audio data in the file. Then, the _parse_data
function is used to load the data from the file according to the parameters
in the WAV format header. So, _read_header loads the header and some info,
then that is passed along to _parse_data to load the actual data. That
_process function I have in there, that's something else, it's not quite
related, but it does show how the _read_header and _parse_data functions
were called.
The final thing you see is AudioClip::writewav. I put that in as an example
of writing WAV data back out. Writing it out is slightly simpler than
reading it; because you have full control over the file's contents. That
code only writes the "fmt " and "data" RIFF chunks.
The fopen(), fread(), and fwrite() functions you see there can be replaced
almost directly with the corresponding functions in TFileStream.
Again, sorry that this code doesn't compiler stand-alone, but hopefully it
helps. There are many other ways you could implement this, too, and don't
forget about IMultiMediaStream if you want to go that route.
Jason