
Audio Intro Part 3

WAV

structure
file header
The WAV format follows the RIFF Resource Interchange File Format, so the WAV format is actually a three-layer relationship, which is simplified here. Its file header format is as follows:
Address Carving type content
00H-03H 4 character * 4 RIFF resource file exchange flag
04H-07H 4 unsigned int The number of bytes from the next address to the end of the file.
08H-0BH 4 character * 4 WAV file WAVE logo
0CH-0FH 4 character * 4 fmt wave file flag, the last digit is 0x20 space
10H-13H 4 unsigned int The size of the subchunk file header. For the WAV subfragment, the value is 0x10.
14H-15H 2 short unsigned Format type, when the value is 1, it means the data is linear PCM encoding
16H-17H 2 short unsigned number of channels
18H-1BH 4 int unsigned Sampling rate
1CH-1FH 4 int unsigned Wave file bytes per second = sample rate Bit depth PCM / 8 channels
20H-21H 2 short unsigned DATA data block unit length = number of channels * PCM bit depth / 8
22H-23H 2 short unsigned Bit depth PCM
24H-27H 4 character * 4 data stamp data
28H-2BH 4 unsigned int Total length of data part (bytes)
struct WAVHeader
{ char RIFF[ 4 ]; ///Resource file exchange flag RIFF unsigned LEN; ///Number of bytes from the next address to the end of the file char WAV[ 4 ]; ///WAV file flag WAVE char FMT [ 4 ]; ///Wave fmt file pointer, last digit is 0x20 space unsigned SubchunkSize; ///The size of the sub-chunk file header, for WAV this sub-chunk, the value is 0x10 DATATYPE short unsigned; / //Format type, when the value is 1, it means the data is unsigned linear PCM encoding short CH ; ///Number of unsigned channels F; ///Unsigned sample rate BYTERATE; ///Number of bytes per second of wave file = sample rate*PCM bit depth/8*Number of unsigned channels
short DATAUNITLEN; ///DATA block unit length=channel number*Bit depth PCM/8 unsigned short BITDEPTH; ///Bit depth character PCM DATA[ 4 ]; ///Data flag data unsigned DATALEN ; ///Data partial total length (bytes) };
data organization
After the file header is the data part of the WAV file. Its data organization is: the left channel value of the first sample point, the right channel value of the first sample point, …, the left channel value of the last sample point, the right channel value of the last sample point value. Each value has a bit depth of bits.
Generate a simple wav
First complete the Wav header.
WAVHeader getHeader ( int number )
{
WAV Header res; memcpy (res.RIFF, “RIFF” , sizeof (res.RIFF)); memcpy (res.WAV, “WAVE” , sizeof (res.WAV)); memcpy (res.FMT, “fmt ” , size of ( res.FMT )); res.SubchunkSize= 0x10 ; res.DATATYPE= 1 ; res.CH= 2 ; res.F=F; res.BITDEPTH=DEPTH; res.BYTERATE=res.F*res.BITDEPTH/ 8 *res.CH; res.DATAUNITLEN=res.CH*res.BITDEPTH/ 8 ; memcpy(res.DATA, “data”
, size of ( res.DATA ));
res.DATALEN=num*res.DATAUNITLEN;
res.LEN=res.DATALEN+ 44 -8 ; returnres; }
First, define the key name – frequency comparison table.
const double keyf[]=
{ 27.5 , 29.1352 , 30.8677 , 32.7032 , 34.6478 , 36.7081 , 38.8909 , 41.2034 , 43.6535 , 46.2493 , 48.9994 , 51.9131 , 55 , 58.2705 , 61.7354 , 65.4064 , 69.2957 , 73.4162 , 77.7817 , 82.4069 , 87.3071 , 92.4986 , 97.9989 ,
103.826 , 110 , 116.541 , 123.471 , 130.813 , 138.591 , 146.832 , 155.563 , 164.814 , 174.614 , 184.997 , 195.998 , 207.652 , 220 , 233.082 , 246.942 , 261.626 , 277.183 , 293.665 , 311.127 , 329.628 , 349.228 , 369.994 , 391.995 , 415.305 , 440
, 466.164 , 493.883 , 523.251 , 554.365 , 587.33 , 622.254 , 659.255 , 698.456 , 739.989 , 783.991 , 830.609 , 880 , 932.328 , 987.767 , 1046.5 , 1108.73 , 1174.66 , 1244.51 , 1318.51 , 1396.91 , 1479.98 , 1567.98 , 1661.22 , 1760 , 1864.66 ,
1975.53 , 2093 , 2217.46 , 2349.32 , 2489.02 , 2637.02 , 2793.83 , 2959.96 , 3135.96 , 3322.44 , 3729.31 , 3951.07 , 4186.01 } ___ { “A-0” , “A#0” , “B- 0” , “C-1” , “C#1” , “D-1” , “D#1” , “E-1” , “F-1”, “F#1”
, “G-1” , “G#1” , “A-1” , “A#1” , “B-1” , “C-2” , “C#2” , “D-2″ , ” D#2″ , “E-2” , “F-2” , “F#2” , “G-2” , “G#2” , “A-2” , “A#2” , “B- 2” , “C-3” , “C#3” , “D-3” , “D#3” , “E-3” , “F-3” , “F#3” , “G-3” , “sun#3” ,














