--- In [email protected], "David WardenDurkee" <[EMAIL PROTECTED]>
wrote:
>
> Hi Alberto or anyone on the list,
> Can you help me with understanding the RIFF chunk of a wav file?
> [snip]

David,

  you are mixing two different things. What you have posted are the
typical instructions used for initializing a structure (named wformat
in that sample of code) that will then be used with the waveInOpen or
the waveOutOpen APIs, to manage the flow of audio sample to and from
the sound card. This has nothing to do with reading or writing from/to
a WAV file...

I attach here following the OutOpen method of the class WavIO, as
coded in my program Spectran, followed by the declaration of the
various structures needed. I never tried to write wav files with 24
bits per sample, but logically the instructions affected should be these:

       fmthdr.nSamplesPerSec =  (int) rate;
       fmthdr.nAvgBytesPerSec = (int) rate * 2;
       fmthdr.nBlockAlign = 2;
       fmthdr.nBitsPerSample = 16;

The first two are trivial, you must specify the sampling rate, 96kHz
in your case. The fourth one will assign a value of 24 in your case.
For the third one, this is the explanation fromthe Borland Developer site:

> If wFormatTag is WAVE_FORMAT_PCM, nBlockAlign should be equal 
> to the product of nChannels and wBitsPerSample divided by 8 
> (bits per byte).

So, if you want to write a stereo wav file, with 24 bit samples, the
value to assign to nBlockAlign will be 6.

A good place where to spend some time reading could be this one:
http://bdn.borland.com/article/0,1410,21300,00.html

73  Alberto  I2PHD
-------------------------------------- 

bool WavIO::OutOpen(char *name)
{
    strcpy(outname, name);
    outhandle = FileCreate(outname);

    if(outhandle > 0)
    {  strncpy(riffhdr.riff, "RIFF", 4);
       riffhdr.filesize = 0L;
       strncpy(riffhdr.wave, "WAVE", 4);
       strncpy(fmthdr.ckID, "fmt ", 4);
       fmthdr.nChunkSize = 16L;
       fmthdr.wFormatTag = 1;
       fmthdr.nChannels = 1;
       fmthdr.nSamplesPerSec =  (int) rate;
       fmthdr.nAvgBytesPerSec = (int) rate * 2;
       fmthdr.nBlockAlign = 2;
       fmthdr.nBitsPerSample = 16;
       strncpy(datahdr.ckID, "data", 4);
       datahdr.nChunkSize = 0L;
       if(12!=FileWrite(outhandle, &riffhdr, 12)) return false;
       if(24!=FileWrite(outhandle, &fmthdr, 24))  return false;
       if(8 !=FileWrite(outhandle, &datahdr, 8))  return false;
       return true;
    }

    return false;
}
//---------------------------------------------------------------------------
  struct riffhdr
  {
        char riff[4];      // RIFF string
        long filesize;     // filesize
        char wave[4];      // WAVE string
  };

  struct fmthdr
  {
        char   ckID[4];
        long   nChunkSize;
        short  wFormatTag;
        short  nChannels;
        long   nSamplesPerSec;
        long   nAvgBytesPerSec;
        short  nBlockAlign;
        short  nBitsPerSample;
  };

  struct facthdr
  {
        char ckID[4];
        long nChunkSize;
  };

  struct datahdr
  {
        char ckID[4];
        long nChunkSize;
  };
//---------------------------------------------------------------------------






 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/soft_radio/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to