-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaveFileHandler.h
More file actions
70 lines (56 loc) · 1.66 KB
/
WaveFileHandler.h
File metadata and controls
70 lines (56 loc) · 1.66 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// Created by hmaurya on 21/02/20.
//
#ifndef AUDIO_WAVEFILEHANDLER_H
#define AUDIO_WAVEFILEHANDLER_H
#include "FileHandler.h"
#include <string>
using namespace std;
class WaveFileHandler {
private:
FileHandler rawFileHandler;
unsigned int dataSubChunkSizeLocation{};
unsigned int dataStartLocation{};
// Size of a single sample/frame in bits
// 8 bits = 8, 16 bits = 16, etc.
unsigned short bitsPerSample;
void setDataSubChunkSizeLocation(unsigned int locationBytes) {
dataSubChunkSizeLocation = locationBytes;
}
void setDataStartLocation(unsigned int locationBytes) {
dataStartLocation = locationBytes;
}
/**
* Write RIFF header
*/
void writeRiffChunkDescriptor();
/**
* Set chunk size when all headers and data have been written
*/
void setChunkSize();
/**
* Write fmt sub-chunk header
* Currently assuming PCM mode.
* TODO: Make this function generic to write other formats other than PCM as well.
*/
void writeFmtSubChunk();
/**
* Write only the header of data sub-chunk
* Actual data to be written by separate function
*/
void writeDataSubChunkHeader();
void writeDataSubChunkSize();
public:
explicit WaveFileHandler(string filename) {
this->bitsPerSample = 16;
this->rawFileHandler.initializeFile(std::move(filename));
this->writeRiffChunkDescriptor();
this->writeFmtSubChunk();
this->writeDataSubChunkHeader();
}
template <typename T>
void writeSample(T sample_data, size_t sample_size);
void close();
};
#include "WaveFileHandler.tpp"
#endif //AUDIO_WAVEFILEHANDLER_H