-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMpgRead.h
More file actions
77 lines (61 loc) · 1.8 KB
/
CMpgRead.h
File metadata and controls
77 lines (61 loc) · 1.8 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
#ifndef AUDIODECODER_H
#define AUDIODECODER_H
#include <QThread>
#include <fstream>
#include <iostream>
#include <stdint.h>
extern "C" {
#include "fmt123.h"
#include "mpg123.h"
#include "out123.h"
}
using namespace std;
class CMpgRead : public QThread
{
Q_OBJECT
public:
CMpgRead(const char* inFilePath, const uint32_t blockLen);
int decodeWholeFile(const char *outFilePath);
inline bool isInstanceInitialized(){return isInitialized;}
inline uint32_t getSamplingRate() {return samplingRate;}
inline uint32_t getBlockSize() {return blockLen;}
inline uint16_t getNrOfChans() {return nChans;}
inline std::string getCurrentMessage() {return currentMessage;}
inline double getNormalizedPosition()
{
int currentPosition;
currentPosition = mpg123_tell(mpgHandle);
return ((double) currentPosition/nSamps);
}
inline int setNormalizedPosition(double normalizedPosition)
{
int samplePos;
double tmpPos;
if ((normalizedPosition < 0) || (normalizedPosition > 1)) return -1;
tmpPos = (double) normalizedPosition*nSamps/nChans;
samplePos = ((uint32_t)tmpPos)*nChans;
mpg123_seek(mpgHandle, samplePos, SEEK_SET);
return 0;
}
inline void fixedToFloat64(int16_t *inData, double *outData, int blockLen)
{
for (int kk = 0; kk < blockLen; kk++)
outData[kk] = (double) inData[kk] * normFact;
}
~CMpgRead();
public slots:
int readOneBlock(double *outBufDouble);
signals:
void isEOF(void);
private:
std::string currentMessage;
mpg123_handle *mpgHandle;
bool noError, isInitialized;
uint32_t blockLen, nSamps;
long samplingRate;
unsigned int bufferSize;
int encodingID, nChans;
int16_t *outBuf;
double normFact;
};
#endif // AUDIODECODER_H