-
Notifications
You must be signed in to change notification settings - Fork 0
/
WAV_parsing
61 lines (60 loc) · 3.23 KB
/
WAV_parsing
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// taken from https://stackoverflow.com/q/67542461
typedef struct WAV_HEADER
{
/* RIFF Chunk Descriptor */
uint8_t RIFF[4]; // RIFF Header Magic header
uint32_t ChunkSize; // RIFF Chunk Size
uint8_t WAVE[4]; // WAVE Header
/* "fmt" sub-chunk */
uint8_t fmt[4]; // FMT header
uint32_t Subchunk1Size; // Size of the fmt chunk
uint16_t AudioFormat; // Audio format 1=PCM,6=mulaw,7=alaw, 257=IBM Mu-Law, 258=IBM A-Law, 259=ADPCM
uint16_t NumOfChan; // Number of channels 1=Mono 2=Stereo
uint32_t SamplesPerSec; // Sampling Frequency in Hz
uint32_t bytesPerSec; // bytes per second
uint16_t blockAlign; // 2=16-bit mono, 4=16-bit stereo
uint16_t bitsPerSample; // Number of bits per sample
/* "data" sub-chunk */
uint8_t Subchunk2ID[4]; // "data" string
uint32_t Subchunk2Size; // Sampled data length
} wav_hdr;
//int main() {
// wav_hdr wavHeader;
// size_t headerSize = sizeof(wav_hdr), filelength = 0;
//
// const char* filePath;
//
//Read the header
// size_t bytesRead = fread(&wavHeader, 1, headerSize, wavFile);
// cout << "Header Read " << bytesRead << " bytes." << endl;
//Read the data
// uint16_t bytesPerSample = wavHeader.bitsPerSample / 8; // Number of bytes per sample
// uint64_t numSamples = wavHeader.ChunkSize / bytesPerSample; // How many samples are in the wav file?
// static int8_t buffer[4096];
// while ((bytesRead = fread(buffer, sizeof buffer[0], BUFFER_SIZE / (sizeof buffer[0]), wavFile)) > 0)
// {
// * /** DO SOMETHING WITH THE WAVE DATA HERE **/ *
// cout << "Read " << bytesRead << " bytes." << endl;
// }
// filelength = getFileSize(wavFile);
//
// cout << "File is :" << filelength << " bytes." << endl;
// cout << "RIFF header :" << wavHeader.RIFF[0] << wavHeader.RIFF[1] << wavHeader.RIFF[2] << wavHeader.RIFF[3] << endl;
// cout << "WAVE header :" << wavHeader.WAVE[0] << wavHeader.WAVE[1] << wavHeader.WAVE[2] << wavHeader.WAVE[3] << endl;
// cout << "FMT :" << wavHeader.fmt[0] << wavHeader.fmt[1] << wavHeader.fmt[2] << wavHeader.fmt[3] << endl;
// cout << "Data size :" << wavHeader.ChunkSize << endl;
//
// Display the sampling Rate from the header
// cout << "Sampling Rate :" << wavHeader.SamplesPerSec << endl;
// cout << "Number of bits used :" << wavHeader.bitsPerSample << endl;
// cout << "Number of channels :" << wavHeader.NumOfChan << endl;
// cout << "Number of bytes per second :" << wavHeader.bytesPerSec << endl;
// cout << "Data length :" << wavHeader.Subchunk2Size << endl;
// cout << "Audio Format :" << wavHeader.AudioFormat << endl;
// Audio format 1=PCM,6=mulaw,7=alaw, 257=IBM Mu-Law, 258=IBM A-Law, 259=ADPCM
//
// cout << "Block align :" << wavHeader.blockAlign << endl;
// cout << "Data string :" << wavHeader.Subchunk2ID[0] << wavHeader.Subchunk2ID[1] << wavHeader.Subchunk2ID[2] << wavHeader.Subchunk2ID[3] << endl;
//
// return 0;
//}