-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWAVParser.cpp
More file actions
32 lines (23 loc) · 910 Bytes
/
Copy pathWAVParser.cpp
File metadata and controls
32 lines (23 loc) · 910 Bytes
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
#include <iostream>
#include "WAVParser.h"
WAVParser::WAVParser(std::string fileName): fileName(fileName) {}
std::vector<short int> WAVParser::parse() {
std::ifstream file(fileName, std::ios::binary); // читаем файл
if(!file.is_open()) {
throw std::runtime_error("Unable to open and parse WAV file " + fileName);
}
header =(wav_header* ) malloc(sizeof(wav_header));
file.read((char* )header, sizeof(wav_header));
char* junk =(char *)malloc(sizeof(char) * (header->subchunk2_size + 4));
file.read(junk, sizeof(char) * (header->subchunk2_size + 4));
int dataSize;
file.read(reinterpret_cast<char *>(&dataSize), sizeof(dataSize));
std::vector<short int> data;
data.resize(dataSize);
file.read((char *)data.data(), dataSize);
free(junk);
return data;
}
WAVParser::~WAVParser() {
free(header);
}