-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavefile.cpp
112 lines (95 loc) · 3 KB
/
wavefile.cpp
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "wavefile.h"
WaveFile::WaveFile(QFile* file): RiffFile(file)
{
info = NULL;
waveData = NULL;
WaveDataCursorPosition = 0;
}
// don't work yet
bool WaveFile::write(){
Chunk* dataChunk = getDataChunk();
if (dataChunk){
} else {
ERROR_MACRO("there is no data chunk", false);
}
return true;
}
WaveFileInfo* WaveFile::getInfo(){
if (info) return info;
if (file->openMode() & QIODevice::ReadOnly) {
return readInfo();
}
return NULL;
}
bool WaveFile::readWaveData(Byte* bytes, myDWORD bytesCount){
Chunk* dataChunk = getDataChunk();
if (dataChunk ){
return dataChunk->readData(bytes, bytesCount);
}
return false;
}
bool WaveFile::setInfo(WaveFileInfo* w) {
info = w;
if (file->openMode() & QIODevice::ReadOnly)
ERROR_MACRO("WaveFile::setInfo error: file is read only", false);
return true;
}
bool WaveFile::addWaveData(Byte* bytes, myDWORD bytesCount){
// qDebug("GLFunctionGraph::getValues()");
// QString str = QString::fromLocal8Bit("sasha molodec");
// qDebug() << str;
qDebug() << "Items in list";
for (myDWORD i=0; i<bytesCount; i++){
Byte b = *(bytes+i);
waveData->append(b);
}
// waveData->push_back(ByteBuffer(bytes, bytesCount));
return true;
}
Chunk* WaveFile::getDataChunk(){
return findChunkByName("data");
}
Chunk* WaveFile::getFMTChunk(){
return findChunkByName("fmt ");
}
WaveFileInfo* WaveFile::readInfo(){
Chunk* fmtChunk = getFMTChunk();
if (fmtChunk) {
Byte* bytes = new Byte[16];
bool ok = fmtChunk->readData(bytes, 16);
if (ok) {
if (!info) info = new WaveFileInfo;
memcpy(&(info->compressionCode) , bytes, 2);
memcpy(&(info->channelsCount) , bytes + 2, 2);
memcpy(&(info->sampleRate) , bytes + 4, 4);
memcpy(&(info->bytesPerSecond) , bytes + 8, 4);
memcpy(&(info->blockAllign) , bytes + 12, 2);
memcpy(&(info->bitsPerSamle) , bytes + 14, 2);
return info;
}
}
return NULL;
}
void WaveFile::createChunks(){
if (!writing()){
rootChunk = new Chunk("RIFF", file);
ChunkList* children = rootChunk -> getChildren();
children -> push_back(new Chunk("fmt ", file));
children -> push_back(new Chunk("data", file));
} else
qDebug()<<"oyjojojoyjoy";
// ERROR_MACRO("WaveFile::createChunks error: need write mode ", );
}
bool WaveFile::writing() {return file->openMode() & QIODevice::WriteOnly; }
bool WaveFile::reading() {return file->openMode() & QIODevice::ReadOnly; }
bool WaveFile::open(QIODevice::OpenModeFlag fl){
// qDebug() << file->openMode() << (file->openMode() == QIODevice::NotOpen);
if (file->openMode() == QIODevice::NotOpen){
bool ok = RiffFile::open(fl);
if (fl & QIODevice::WriteOnly)
this->waveData = new ByteBuffer;
qDebug() << file->fileName() << file->isOpen();
return ok;
} else {
}
}