WAV

From Atari Wiki
Revision as of 00:15, 21 March 2016 by Admin (talk | contribs)
Jump to navigation Jump to search

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 */ };