From: Larry on
"Bob Masta" <N0Spam(a)daqarta.com> ha scritto nel messaggio
news:4b376982.416082(a)news.eternal-september.org...

>
> Begging to differ with Scott, but writing WAV
> files with standard file APIs need not be too
> difficult. You need to create one RIFF chunk, one
> WAVE chunk, and one DATA chunk for all the data,
> no matter how much it is (up to 2 GB or so limit
> of RIFF format.)
>
> The DATA section is just what you are already
> recording. The WAVE format header includes sample
> rate plus a few arcane details that you can
> usually boiler-plate if you are running at fixed
> sample rate. The only thing that's at all tricky
> is that the RIFF and DATA chunk size dwords are
> written last, after the recording is done (when
> you know what the final size is). So you have to
> move the file pointer back and fill those in after
> initially writing dummy placeholder values.

I have found this great piece of code!
http://www.nerdmodo.com/2009/07/creating-recording-sound-in-wav-file-using-mimos-with-cc/

I would like to understand why is he using:

//memset(&mmckinfo, 0, sizeof(mmckinfo));
//memset(&mmckinfoSubchunk, 0, sizeof(mmckinfoSubchunk));
//memset(&mmckinfoData, 0, sizeof(mmckinfoData));

so if comment that code and I recoder the first 32768 bytes I will get a
32KB file, if I uncomment I'll get a 46KB file...

Also, is it code to file with 0x00s the buffer? like this:

WAVEHDR buffer;
ZeroMemory(&buffer, sizeof(buffer));
buffer.dwBufferLength = BUFFER_LEN;
buffer.lpData = (LPSTR) malloc(BUFFER_LEN);

thanks

From: Bob Masta on
On Mon, 28 Dec 2009 06:20:02 +0100, "Larry"
<dontmewithme(a)got.it> wrote:

>"Bob Masta" <N0Spam(a)daqarta.com> ha scritto nel messaggio
>news:4b376982.416082(a)news.eternal-september.org...
>
>>
>> Begging to differ with Scott, but writing WAV
>> files with standard file APIs need not be too
>> difficult. You need to create one RIFF chunk, one
>> WAVE chunk, and one DATA chunk for all the data,
>> no matter how much it is (up to 2 GB or so limit
>> of RIFF format.)
>>
>> The DATA section is just what you are already
>> recording. The WAVE format header includes sample
>> rate plus a few arcane details that you can
>> usually boiler-plate if you are running at fixed
>> sample rate. The only thing that's at all tricky
>> is that the RIFF and DATA chunk size dwords are
>> written last, after the recording is done (when
>> you know what the final size is). So you have to
>> move the file pointer back and fill those in after
>> initially writing dummy placeholder values.
>
>I have found this great piece of code!
>http://www.nerdmodo.com/2009/07/creating-recording-sound-in-wav-file-using-mimos-with-cc/
>
>I would like to understand why is he using:
>
> //memset(&mmckinfo, 0, sizeof(mmckinfo));
> //memset(&mmckinfoSubchunk, 0, sizeof(mmckinfoSubchunk));
> //memset(&mmckinfoData, 0, sizeof(mmckinfoData));
>
>so if comment that code and I recoder the first 32768 bytes I will get a
>32KB file, if I uncomment I'll get a 46KB file...
>
>Also, is it code to file with 0x00s the buffer? like this:
>
> WAVEHDR buffer;
> ZeroMemory(&buffer, sizeof(buffer));
> buffer.dwBufferLength = BUFFER_LEN;
> buffer.lpData = (LPSTR) malloc(BUFFER_LEN);
>
>thanks
>

Check out:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
This shows the full layout of the RIFF WAVE
format. Or Google 'RIFF WAVE format', there are
plenty of examples. Again, assuming that you
always record at the same sample, most of this is
boilerplate. You don't need to fill anything with
zeroes; it's all format stuff or your data (or
chunk sizes).

Best regards,


Bob Masta

DAQARTA v5.00
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
Frequency Counter, FREE Signal Generator
Pitch Track, Pitch-to-MIDI
DaqMusic - FREE MUSIC, Forever!
(Some assembly required)
Science (and fun!) with your sound card!
From: Larry on
"Bob Masta" <N0Spam(a)daqarta.com> ha scritto nel messaggio
news:4b38b2b9.973480(a)news.eternal-september.org...

> https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
> This shows the full layout of the RIFF WAVE
> format. Or Google 'RIFF WAVE format', there are
> plenty of examples. Again, assuming that you
> always record at the same sample, most of this is
> boilerplate. You don't need to fill anything with
> zeroes; it's all format stuff or your data (or
> chunk sizes).

Ok, this is the gist of that web page:

"A RIFF file starts out with a file header followed by a sequence of data
chunks. A WAVE file is /often/ just a RIFF file with a single "WAVE" chunk
which consists of two sub-chunks -- a "fmt " chunk specifying the data
format and a "data" chunk containing the actual sample data."

so, in a nutshell, my file must be made up of a RIFF chunk, a FMT chunk and
a DATA chunk followed up with the entire raw binary data.

If I am not mistaken the RIFF header makes up the first 44 Bytes of the WAVE
file (always), does not that?

> The only thing that's at all tricky
> is that the RIFF and DATA chunk size dwords are
> written last, after the recording is done (when
> you know what the final size is).

Since I am doing a streaming recorder (real time) I won't be able to know
beforehand what the DWORD values for RIFF and DATA are!

My idea was to fill with zeroes the first 44 Bytes of the .wav file then
append the actual raw data to it, real time. Finally, when I stop the
recording I will add the RIFF header at the beginning of the file with the
correct DWORD values for the RIFF and DATA chunck!

is that good to you?

**
By the way, I am a little bit struck by this: "The sample data must end on
an even byte boundary. Whatever that means."

From: Bob Masta on
On Mon, 28 Dec 2009 23:57:22 +0100, "Larry"
<dontmewithme(a)got.it> wrote:

>"Bob Masta" <N0Spam(a)daqarta.com> ha scritto nel messaggio
>news:4b38b2b9.973480(a)news.eternal-september.org...
>
>> https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
>> This shows the full layout of the RIFF WAVE
>> format. Or Google 'RIFF WAVE format', there are
>> plenty of examples. Again, assuming that you
>> always record at the same sample, most of this is
>> boilerplate. You don't need to fill anything with
>> zeroes; it's all format stuff or your data (or
>> chunk sizes).
>
>Ok, this is the gist of that web page:
>
>"A RIFF file starts out with a file header followed by a sequence of data
>chunks. A WAVE file is /often/ just a RIFF file with a single "WAVE" chunk
>which consists of two sub-chunks -- a "fmt " chunk specifying the data
>format and a "data" chunk containing the actual sample data."
>
>so, in a nutshell, my file must be made up of a RIFF chunk, a FMT chunk and
>a DATA chunk followed up with the entire raw binary data.
>
>If I am not mistaken the RIFF header makes up the first 44 Bytes of the WAVE
>file (always), does not that?
>
>> The only thing that's at all tricky
>> is that the RIFF and DATA chunk size dwords are
>> written last, after the recording is done (when
>> you know what the final size is).
>
>Since I am doing a streaming recorder (real time) I won't be able to know
>beforehand what the DWORD values for RIFF and DATA are!
>
>My idea was to fill with zeroes the first 44 Bytes of the .wav file then
>append the actual raw data to it, real time. Finally, when I stop the
>recording I will add the RIFF header at the beginning of the file with the
>correct DWORD values for the RIFF and DATA chunck!
>
>is that good to you?

As mentioned in my first post, you can fill in
everything but the RIFF and DATA sizes at the
start, since you know the sample rate, number of
bits, and mono/stereo already. All you need to do
at the end of the recording is fill in the sizes.
But it won't hurt to write the entire header at
that time.

>**
>By the way, I am a little bit struck by this: "The sample data must end on
>an even byte boundary. Whatever that means."

This only pertains to mono 8-bit data, where there
is the possibility of having an odd number of
bytes. Otherwise, everything is even
automatically.

Best regards,



Bob Masta

DAQARTA v5.00
Data AcQuisition And Real-Time Analysis
www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
Frequency Counter, FREE Signal Generator
Pitch Track, Pitch-to-MIDI
DaqMusic - FREE MUSIC, Forever!
(Some assembly required)
Science (and fun!) with your sound card!
From: Larry on
"Bob Masta" <N0Spam(a)daqarta.com> ha scritto nel messaggio
news:4b39fd1f.339630(a)news.eternal-september.org...

> As mentioned in my first post, you can fill in
> everything but the RIFF and DATA sizes at the
> start, since you know the sample rate, number of
> bits, and mono/stereo already. All you need to do
> at the end of the recording is fill in the sizes.
> But it won't hurt to write the entire header at
> that time.

ok, so supposed I have a .wav file containg:

1) the first 44 bytes padded with zeroes (0x00)
2) 100000 bytes of actual raw data

what values should I set RIFF and DATA dwords?

Also, what is the use of mmioAscend() function?

thanks