Faced with the problem of parsing a header of the wav sound?

Yuzayu this code:
struct WAVHEADER
{
 / / . WAV format starts with the RIFF header:

 // Contains the characters "RIFF" in ASCII
 // (0x52494646 in big-endian representation)
 char chunkId[4];

 // 36 + subchunk2Size, or more precisely:
 // 4 + (8 + subchunk1Size) + (8 + subchunk2Size)
 // Is the remaining size of the chain from this position.
 // In other words, the file size - 8,
 // excluded fields chunkId and chunkSize.
 unsigned long chunkSize;

 // Contains the characters "WAVE"
 // (0x57415645 in big-endian representation)
 char format[4];

 // Format "WAVE" consists of two podzamochek: "fmt" and "data":
 // Podrabotka "fmt" describes the format of the audio data:

 // Contains the characters "fmt "
 // (0x666d7420 in big-endian representation)
 subchunk1Id char[4];

 // 16 for PCM format.
 // Is the remaining size of podrabotki from this position.
 unsigned long subchunk1Size;

 // Audio format, a complete list can be found here http://audiocoding.ru/wav_formats.txt
 // For PCM = 1 (i.e. Linear quantization).
 // To a value other than 1 indicate some compression format.
 unsigned short audioFormat;

 // The number of channels. Mono = 1, Stereo = 2, etc.
 unsigned short numChannels;

 // Sampling frequency. 8000 Hz, 44100 Hz etc.
 unsigned long sampleRate;

 // sampleRate * numChannels * bitsPerSample/8
 unsigned long byteRate;

 // numChannels * bitsPerSample/8
 // Number of bytes for one sample including all channels.
 unsigned short blockAlign;

 // The so-called "downline" or precision sound. 8 bit, 16 bit etc.
 unsigned short bitsPerSample;

 // Podrabotka "data" includes audio data and their size.

 // Contains the characters "data"
 // (0x64617461 in big-endian representation)
 subchunk2Id char[4];

 // numSamples * numChannels * bitsPerSample/8
 // The number of bytes in the data area.
 unsigned long subchunk2Size;

 // Directly followed by the Wav data.
};
int j = 0;
#ifdef _WIN32
 file = open("content//konga.wav", _A_ARCH);
#else
 file = open(filename, O_RDONLY);
#endif // _WIN32
 if (file == -1)
{
 printf("Open failed on input file: %s\n", "content//konga.wav");
#ifdef _WIN32
 wchar_t path[MAX_PATH];
 GetCurrentDirectory(sizeof(path), path);
 std::wcout << path << std::endl;
#endif // _WIN32
}
 org = 0;

 FILE* file_;
 errno_t err;
 err = fopen_s(&file_, "content//konga.wav", "rb");
 if (err)
{
 printf_s("Failed open file, error %d", err);
 return 0;
}

 WAVHEADER header;

 fread_s(&header, sizeof(WAVHEADER), sizeof(WAVHEADER), 1, file_);
 printf("audioformat:%d\n", header.audioFormat);
 printf("bitsPerSample:%d\n", header.bitsPerSample);
 printf("blockAlign:%d\n", header.blockAlign);
 printf("byteRate:%lu\n", header.byteRate);
 printf("chunkId:%s\n", header.chunkId);
 printf("chunkSize:%lu\n", header.chunkSize);
 printf("format:%s\n", header.format);
 printf("numCannels:%d\n", header.numChannels);
 printf("sampleRate:%lu\n", header.sampleRate);
 printf("subchunk1Id:%s\n", header.subchunk1Id);
 printf("subchunk1Size:%lu\n", header.subchunk1Size);
 printf("subchunk2Id:%s\n", header.subchunk2Id);
 printf("subchunk2Size:%lu\n", header.subchunk2Size);
 fclose(file_);

A good file for this title:
5e4aa1b10aa7a864668947.png
The bad is this:
5e4aa1b806c7a313037418.png
the sound here https://wav-library.net/afrikanskij-konga-baraban-... translated into a wav on one of the sites https://audio.online-convert.com/ru/convert-to-wav
I tried to add the field char s[178]; to walk to fields data:
struct WAVHEADER
{
 / / . WAV format starts with the RIFF header:

 // Contains the characters "RIFF" in ASCII
 // (0x52494646 in big-endian representation)
 char chunkId[4];

 // 36 + subchunk2Size, or more precisely:
 // 4 + (8 + subchunk1Size) + (8 + subchunk2Size)
 // Is the remaining size of the chain from this position.
 // In other words, the file size - 8,
 // excluded fields chunkId and chunkSize.
 unsigned long chunkSize;

 // Contains the characters "WAVE"
 // (0x57415645 in big-endian representation)
 char format[4];

 // Format "WAVE" consists of two podzamochek: "fmt" and "data":
 // Podrabotka "fmt" describes the format of the audio data:

 // Contains the characters "fmt "
 // (0x666d7420 in big-endian representation)
 subchunk1Id char[4];

 // 16 for PCM format.
 // Is the remaining size of podrabotki from this position.
 unsigned long subchunk1Size;

 // Audio format, a complete list can be found here http://audiocoding.ru/wav_formats.txt
 // For PCM = 1 (i.e. Linear quantization).
 // To a value other than 1 indicate some compression format.
 unsigned short audioFormat;

 // The number of channels. Mono = 1, Stereo = 2, etc.
 unsigned short numChannels;

 // Sampling frequency. 8000 Hz, 44100 Hz etc.
 unsigned long sampleRate;

 // sampleRate * numChannels * bitsPerSample/8
 unsigned long byteRate;

 // numChannels * bitsPerSample/8
 // Number of bytes for one sample including all channels.
 unsigned short blockAlign;

 // The so-called "downline" or precision sound. 8 bit, 16 bit etc.
 unsigned short bitsPerSample;
 char s[178l];
 // Podrabotka "data" includes audio data and their size.
 // Contains the characters "data"
 // (0x64617461 in big-endian representation)
 subchunk2Id char[4];

 // numSamples * numChannels * bitsPerSample/8
 // The number of bytes in the data area.
 unsigned long subchunk2Size;

 // Directly followed by the Wav data.
};

Got this 5e4ad91fe8485223615625.png
April 7th 20 at 15:30
2 answers
April 7th 20 at 15:32
Solution
Skip the "left" blocks, until we reach the data! What can you do?
I got the file length 5.241.822, and there are blocks at offset 0C fmt length 0x10, offset 24=0C+8+10 AA LIST length, and offset D6=24+8+AA will need us data.

To clarify what I meant. RIFF is a standard block format, not limited to WAV'ohms. Suppose there is a format RMI = MIDI RIFF. Your decision implies that the block "fmt" immediately follows the block data that is not always true.

Again, man! At offset 0C is the unit "fmt": 4 bytes signature 4 bytes length and 0x10 bytes of data.
These 0x10 bytes at offset 24=0C+8+10, there is a block LIST: 4 bytes signature 4 bytes length and 0xAA bytes of data. Block our not — skip these bytes and go directly to offset 0xD6=24+8+AA. There are 4 bytes signature 4 bytes length and 0x4FFB00 bytes of data. They read.
You can code? Where is D6? if 178 bytes?
5e4ad56802198276168471.png - yolanda.Ledn commented on April 7th 20 at 15:35
PS responded and the Japanese IPS before the data 5e4ad63da6e23480164333.png - yolanda.Ledn commented on April 7th 20 at 15:38
@Jovani, to Hell with him, with the Japanese IPS. It's part of the block LIST. - anthony commented on April 7th 20 at 15:41
@Jovani, D6 — this is the point where the end of the block. - anthony commented on April 7th 20 at 15:44
@Jovani, You are allocated a plot [24, D6); 0xD6−0x24 = 0xB2 = 178. - anthony commented on April 7th 20 at 15:47
@Ciara.Johnson, but the dog with him at the offset I was able to solve the trouble in another action - yolanda.Ledn commented on April 7th 20 at 15:50
April 7th 20 at 15:34
Solution
Decided the conversion of the file from mp3 to wav with the command
ffmpeg -i konga.mp3 -map_metadata -1 -fflags +bitexact konga.wav
So, guys, question: are you satisfied with such a partial solution or not? - anthony commented on April 7th 20 at 15:37

Find more questions by tags C++Development of gamesWAV