-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
44 lines (37 loc) · 1.27 KB
/
Copy pathparser.cpp
File metadata and controls
44 lines (37 loc) · 1.27 KB
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
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
uint16_t bitReader16(char* buffer){
return ((unsigned char)buffer[0]) + ((unsigned char)buffer[1] << 8);
}
uint32_t bitReader32(char* buffer){
return ((unsigned char)buffer[0]) + ((unsigned char)buffer[1] << 8) + ((unsigned char)buffer[2] << 16) + ((unsigned char)buffer[3] << 24);
}
bool wavAnalyser(std::string fileName){
uint32_t samplerate;
int numChannels;
uint16_t bitsPerSample;
std::string format;
std::vector<char> audioBuffer(44);
std::ifstream audioFile(fileName, std::ios::binary);
if (audioFile.read(audioBuffer.data(), 44)) {
samplerate = bitReader32(&audioBuffer[24]);
bitsPerSample = bitReader16(&audioBuffer[34]);
numChannels = bitReader16(&audioBuffer[22]);
std::cout << "bits per sample is " << bitsPerSample << "\n";
std::cout << "samplerate is " << samplerate << "\n";
std::cout << "num channels is " << numChannels << "\n";
return true;
}
return false;
}
int main(){
std::string fileName = "silence.wav";
if (wavAnalyser(fileName)){
std::cout << "wav analyser started successfully \n";
}else {
std::cout << "error trying to start wav analyser";
}
return 0;
}