table of Contents
1. Comparison between OSS and ALSA
OSS is an old framework and requires fees.
ALSA is the latest Linux open source framework. It can simulate OSS and is currently very useful.
2. Principle of sound hardware collection
3. Sound storage format
4. Sound card driver module diagram
5. WAV file format
RIFF Chunk
can abstract the structure of RIFF chunk according to the format of RIFF:
[cpp] view plain copy
struct RIFF_CHUNK
{
char ChunkID[4]; //'R','I','F','F'
unsigned int ChunkSize;
char Format[4]; //'W','A','V','E'
};
Among them, ChunkSize represents the size of the entire wav_file minus the size of ChunkID and ChunkSize, that is, wav_file_size=ChunkSize+8.
Format Chunk
Format chunk mainly describes the format of audio data. According to the format of Format chunk, the data structure of Format Chunk can be abstracted:
[cpp] view plain copy
struct FORMAT_CHUNK
{
char FmtID[4]; //'f','m','t'
unsigned int FmtSize;
unsigned short FmtTag;
unsigned short FmtChannels;
unsigned int SampleRate;
unsigned int ByteRate;
unsigned short BlockAilgn;
unsigned short BitsPerSample;
};
.FmtSize: Usually the value is 16 or 18. 16 means that the audio uses PCM encoding.
.FmtTag: If the above value is 16, this value is usually 1, which means that the audio encoding method is PCM encoding.
.FmtChannels: The number of channels, 1 represents mono, 2 represents dual channels, which is the so-called stereo.
.SampleRate: sampling frequency. If you are not familiar with this concept, you can check this article: Linux Audio Driver-Sound Acquisition Process.
ByteRate: The number of bytes required per second. Equal to SampleRate * NumChannels * BitsPerSample/8.
.BlockAilgn: Data block alignment unit. Equal to NumChannels * BitsPerSample/8.
.BitsPerSample: The number of sampling bits.
Data Chunk
Data Chunk mainly describes the raw sound data and size. According to the Data Chunk format, the data structure of Data Chunk is abstracted:
[cpp] view plaincopy
struct DATA_CHUNK
{
char DataID[4]; //'d','a','t','a'
unsigned int DataSize;
};