-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCWavRW.h
More file actions
137 lines (111 loc) · 3.33 KB
/
CWavRW.h
File metadata and controls
137 lines (111 loc) · 3.33 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//wavReadWrite
#ifndef WAV_RW_H
#define WAV_RW_H
#include <QThread>
#include <fstream>
#include <stdio.h>
#include <stdint.h>
#include <iostream>
using namespace std;
class CWavRead : public QThread
{
Q_OBJECT
public:
CWavRead(const char *filePath, int blockLen);
inline bool isInstanceInitialized() {return isInitialized;}
inline uint32_t getSamplingRate() {return fs;}
inline uint32_t getBlockSize() {return blockLen;}
inline uint16_t getNrOfChans() {return nChans;}
inline uint32_t getBytesPerSecond() {return bytesPerSecond;}
inline uint16_t getNrBytesPerBlock() {return bytesPerBlock;}
inline uint32_t getNrBytesPerBlockForDouble() {return bytesPerBlockForDouble;}
inline uint32_t getSamplesPerFrame() {return nSamplesPerFrame;}
inline uint16_t getBitDepth() {return nBitsPerSample;}
inline uint32_t getOverallLen() {return nAudioBytes;}
inline double getNormalizedPosition(){return ((double) byteCnt/nAudioBytes);}
inline std::string getCurrentMessage(){return currentMessage;}
inline int setNormalizedPosition(double normalizedPosition)
{
double tmpPos;
if ((normalizedPosition < 0) || (normalizedPosition > 1)) return -1;
tmpPos = (double) normalizedPosition*(nAudioBytes-bytesPerBlock)/frameSize;
byteCnt = ((uint32_t)tmpPos)*frameSize+beginPos;
inFile->seekg(byteCnt, inFile->beg);
return 0;
}
~CWavRead();
public slots:
void readOneBlock(double* outData);
protected:
inline void fixedToFloat64(int16_t *inData, double *outData, int blockLen)
{
for (int kk = 0; kk < blockLen; kk++)
outData[kk] = (double) inData[kk] * normFact;
}
inline void fixedToFloat64(int32_t *inData, double *outData, int blockLen)
{
for (int kk = 0; kk < blockLen; kk++)
outData[kk] = (double) inData[kk] * normFact;
}
signals:
void isEOF(void);
private:
ifstream *inFile;
uint32_t blockLen;
uint32_t nSamplesPerFrame;
uint16_t nChans;
uint32_t fs;
uint32_t bytesPerBlock;
uint32_t bytesPerBlockForDouble;
uint32_t bytesPerSecond;
uint16_t frameSize;
uint16_t bytesPerSample;
uint16_t nBitsPerSample;
uint32_t nAudioBytes;
uint32_t byteCnt;
uint32_t beginPos;
int32_t *tmpAudio32;
int16_t *tmpAudio16;
double normFact;
bool isInitialized, noError;
std::string currentMessage;
};
class CWavWrite : public QThread
{
Q_OBJECT
public:
CWavWrite(const char *filePath, int blockSize,
int fs, int nChans, int bitDepth);
~CWavWrite();
inline bool isInstanceInitialized() {return isInitialized;}
inline std::string getCurrentMessage(){return currentMessage;}
public slots:
void writeOneBlock(double* inData);
protected:
inline void float64ToFixed(double *inData, int16_t *outData, int blockLen)
{
for (int kk = 0; kk < blockLen; kk++)
outData[kk] = inData[kk] * normFact;
}
inline void float64ToFixed(double *inData, int32_t *outData, int blockLen)
{
for (int kk = 0; kk < blockLen; kk++)
outData[kk] = inData[kk] * normFact;
}
private:
ofstream *outFile;
uint32_t blockLen;
uint32_t nSamplesPerFrame;
uint16_t nChans;
uint32_t fs;
uint32_t bytesPerBlock;
uint16_t frameSize;
uint16_t nBitsPerSample;
uint32_t byteCnt;
int32_t *tmpAudio32;
int16_t *tmpAudio16;
double normFact;
bool isInitialized, noError;
std::string currentMessage;
};
#endif