WAV: Difference between revisions

From AtariForumWiki
Jump to navigation Jump to search
>Atari74user
(Created page with "Waveform Audio File Format, WAV was introduced by Microsoft and IBM. WAVE is RIFF's equivalent of AIFF, and its inclusion in Microsoft Windows 3.1 has made it important to know ...")
 
>Atari74user
No edit summary
Line 1: Line 1:
Waveform Audio File Format, WAV was introduced by Microsoft and IBM.
Waveform Audio File Format, WAV was introduced by Microsoft and IBM.


WAVE is RIFF's equivalent of AIFF, and its inclusion in Microsoft Windows 3.1 has made it important to know about.
WAVE is RIFF's equivalent of AIFF, and its inclusion in Microsoft Windows 3.1 made it prominent.
 
Rob Ryan was kind enough to send me a description of the RIFF format. Unfortunately, it is too big to include here (27 k), but I've made it available for anonymous ftp at ftp://ftp.cwi.nl/pub/audio/RIFF-format.
 
Conor Frederick Prischmann <conor@owlnet.rice.edu> points to ftp://ftp.ircam.fr/pub/music/.


The following is a overly simple description of a WAV file and will generally only work when it contains PCM data. This isn't so bad since thats what 90% want to work with.
The following is a overly simple description of a WAV file and will generally only work when it contains PCM data. This isn't so bad since thats what 90% want to work with.




    WAVe file format (Microsoft)
WAVe file format (Microsoft)
    ----------------------------
----------------------------
      
      
        Wave files are a part of a file interchange format, called
Wave files are a part of a file interchange format, called
        RIFF, created by Microsoft.  The format basically is composed
RIFF, created by Microsoft.  The format basically is composed
        of a collection of data chunks.  Each chunk has a 32-bit Id
of a collection of data chunks.  Each chunk has a 32-bit Id
        field, followed by a 32-bit chunk length, followed by the
field, followed by a 32-bit chunk length, followed by the
        chunk data.  Note that values are in Intel form (ie: big-
chunk data.  Note that values are in Intel form (ie: big-
        endian notation).   
endian notation).   
      
      
        The format for a wave file is as follows:
The format for a wave file is as follows:
      
      
        Offset    Description
Offset    Description
        ------    -----------
------    -----------
          0x00    chunk id 'RIFF'
0x00    chunk id 'RIFF'
          0x04    chunk size (32-bits)
0x04    chunk size (32-bits)
          0x08    wave chunk id 'WAVE'
0x08    wave chunk id 'WAVE'
          0x0C    format chunk id 'fmt '
0x0C    format chunk id 'fmt '
          0x10    format chunk size (32-bits)
0x10    format chunk size (32-bits)
          0x14    format tag (currently pcm)
0x14    format tag (currently pcm)
          0x16    number of channels 1=mono, 2=stereo
0x16    number of channels 1=mono, 2=stereo
          0x18    sample rate in hz
0x18    sample rate in hz
          0x1C    average bytes per second
0x1C    average bytes per second
          0x20    number of bytes per sample
0x20    number of bytes per sample
                        1 =  8-bit mono
1 =  8-bit mono
                        2 =  8-bit stereo or
2 =  8-bit stereo or
                            16-bit mono
16-bit mono
                        4 = 16-bit stereo
4 = 16-bit stereo
          0x22    number of bits in a sample
0x22    number of bits in a sample
          0x24    data chunk id 'data'
0x24    data chunk id 'data'
          0x28    length of data chunk (32-bits)
0x28    length of data chunk (32-bits)
          0x2C    Sample data
0x2C    Sample data
      
      
      
      
        Notes
Notes
        -----
-----
          
          
        1.  Lengths do not include the chunk Id or the length bytes.  
1.  Lengths do not include the chunk Id or the length bytes.  
                e.g.if the data length is 1204 then the length of
e.g. if the data length is 1204 then the length of sample data is 1204 and not 1204-(4+4)
                        sample data is 1204 and not 1204-(4+4)
   
        2.  For samples with more than 1 channel, channel 0 data will
              start and be followed by channel 1 for a given sample
              then the next sample will follow. 
                e.g.:  for 8-bit stereo the samples will sample0left,
                        sample0right, sample1left, sample1right, etc.
      
      
        38-bit samples are stored in excess-128 notationThis
2For samples with more than 1 channel, channel 0 data will
              means that the value 0 is stored as 128, a value 1 is
start and be followed by channel 1 for a given sample then the next sample will follow.   
              stored as 129, a value of -1 is stored as 127 and so on.
e.g.  for 8-bit stereo the samples will sample0left,
sample0right, sample1left, sample1right, etc.
      
      
        4.  16-bit samples are stored as 2's compliment signed
3.  8-bit samples are stored in excess-128 notation.  This means that the value 0 is stored as 128, a value 1 is
              numbers.
stored as 129, a value of -1 is stored as 127 and so on.
4.  16-bit samples are stored as 2's compliment signed numbers.
      
      
      
      
        Sample C Structure
Sample C Structure
        ------------------
------------------
          
          
        typedef unsigned word;
typedef unsigned word;
        typedef unsigned long dword;
typedef unsigned long dword;
      
      
        struct WAVEheader
struct WAVEheader
            {
{
            char  ckID[4];            /* chunk id 'RIFF'            */
char  ckID[4];            /* chunk id 'RIFF'            */
            dword ckSize;              /* chunk size                */
dword ckSize;              /* chunk size                */
            char  wave_ckID[4];        /* wave chunk id 'WAVE'      */
char  wave_ckID[4];        /* wave chunk id 'WAVE'      */
            char  fmt_ckID[4];        /* format chunk id 'fmt '    */
char  fmt_ckID[4];        /* format chunk id 'fmt '    */
            dword fmt_ckSize;          /* format chunk size          */
dword fmt_ckSize;          /* format chunk size          */
            word  formatTag;          /* format tag currently pcm  */
word  formatTag;          /* format tag currently pcm  */
            word  nChannels;          /* number of channels        */
word  nChannels;          /* number of channels        */
            dword nSamplesPerSec;      /* sample rate in hz          */
dword nSamplesPerSec;      /* sample rate in hz          */
            dword nAvgBytesPerSec;    /* average bytes per second  */
dword nAvgBytesPerSec;    /* average bytes per second  */
            word  nBlockAlign;        /* number of bytes per sample */
word  nBlockAlign;        /* number of bytes per sample */
            word  nBitsPerSample;      /* number of bits in a sample */
word  nBitsPerSample;      /* number of bits in a sample */
            char  data_ckID[4];        /* data chunk id 'data'      */
char  data_ckID[4];        /* data chunk id 'data'      */
            dword data_ckSize;        /* length of data chunk      */
dword data_ckSize;        /* length of data chunk      */
            };
};

Revision as of 20:15, 20 March 2016

Waveform Audio File Format, WAV was introduced by Microsoft and IBM.

WAVE is RIFF's equivalent of AIFF, and its inclusion in Microsoft Windows 3.1 made it prominent.

The following is a overly simple description of a WAV file and will generally only work when it contains PCM data. This isn't so bad since thats what 90% want to work with.


WAVe file format (Microsoft)


Wave files are a part of a file interchange format, called RIFF, created by Microsoft. The format basically is composed of a collection of data chunks. Each chunk has a 32-bit Id field, followed by a 32-bit chunk length, followed by the chunk data. Note that values are in Intel form (ie: big- endian notation).

The format for a wave file is as follows:

Offset Description


-----------

0x00 chunk id 'RIFF' 0x04 chunk size (32-bits) 0x08 wave chunk id 'WAVE' 0x0C format chunk id 'fmt ' 0x10 format chunk size (32-bits) 0x14 format tag (currently pcm) 0x16 number of channels 1=mono, 2=stereo 0x18 sample rate in hz 0x1C average bytes per second 0x20 number of bytes per sample

1 =  8-bit mono
2 =  8-bit stereo or
16-bit mono
4 = 16-bit stereo

0x22 number of bits in a sample 0x24 data chunk id 'data' 0x28 length of data chunk (32-bits) 0x2C Sample data


Notes


1. Lengths do not include the chunk Id or the length bytes. e.g. if the data length is 1204 then the length of sample data is 1204 and not 1204-(4+4)

2. For samples with more than 1 channel, channel 0 data will start and be followed by channel 1 for a given sample then the next sample will follow. e.g. for 8-bit stereo the samples will sample0left, sample0right, sample1left, sample1right, etc.

3. 8-bit samples are stored in excess-128 notation. This means that the value 0 is stored as 128, a value 1 is stored as 129, a value of -1 is stored as 127 and so on. 4. 16-bit samples are stored as 2's compliment signed numbers.


Sample C Structure


typedef unsigned word; typedef unsigned long dword;

struct WAVEheader { char ckID[4]; /* chunk id 'RIFF' */ dword ckSize; /* chunk size */ char wave_ckID[4]; /* wave chunk id 'WAVE' */ char fmt_ckID[4]; /* format chunk id 'fmt ' */ dword fmt_ckSize; /* format chunk size */ word formatTag; /* format tag currently pcm */ word nChannels; /* number of channels */ dword nSamplesPerSec; /* sample rate in hz */ dword nAvgBytesPerSec; /* average bytes per second */ word nBlockAlign; /* number of bytes per sample */ word nBitsPerSample; /* number of bits in a sample */ char data_ckID[4]; /* data chunk id 'data' */ dword data_ckSize; /* length of data chunk */ };