-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavefile.h
87 lines (64 loc) · 1.92 KB
/
wavefile.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef WAVEFILE_H
#define WAVEFILE_H
#include "RiffFile.h"
// using namespace RiffChunk;
// typedef unsigned int int4b;
// typedef unsigned int int2b;
struct WaveFileInfo {
int2b compressionCode;
int2b channelsCount;
int4b sampleRate;
int4b bytesPerSecond;
int2b blockAllign;
int2b bitsPerSamle;
WaveFileInfo(int2b compressionCode = 1,
int2b channelsCount = 1,
int4b sampleRate = 22050,
int4b bytesPerSecond = 44100,
int2b blockAllign = 2, // êîëè÷åñòâî áàéò â ñåìïëå
int2b bitsPerSamle = 16){
this->compressionCode = compressionCode;
this->channelsCount = channelsCount;
this->sampleRate = sampleRate;
this->bytesPerSecond = bytesPerSecond;
this->blockAllign = blockAllign;
this->bitsPerSamle = bitsPerSamle;
}
Byte* toBytes(){
Byte* bytes = new Byte(16);
memcpy(bytes, &compressionCode, 2);
memcpy(bytes+2, &channelsCount, 2);
memcpy(bytes+4, &sampleRate, 4);
memcpy(bytes+8, &bytesPerSecond, 4);
memcpy(bytes+12,&blockAllign, 2);
memcpy(bytes+14,&bitsPerSamle, 2);
return bytes;
}
myDWORD getBytesCount(){
return 16;
}
};
class WaveFile : public RiffFile
{
protected:
myDWORD WaveDataCursorPosition;
WaveFileInfo* info;
ByteBuffer* waveData;
public:
// WaveFile(QString fileName);
WaveFile(QFile* fileName);
bool write();
WaveFileInfo* getInfo();
bool readWaveData(Byte* bytes, myDWORD bytesCount);
bool setInfo(WaveFileInfo*);
bool addWaveData(Byte* bytes, myDWORD bytesCount);
bool open(QIODevice::OpenModeFlag);
protected:
Chunk* getDataChunk();
Chunk* getFMTChunk();
void createChunks();
WaveFileInfo* readInfo();
bool writing();
bool reading();
};
#endif // WAVEFILE_H