This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infopiste.cpp
145 lines (91 loc) · 3.29 KB
/
infopiste.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
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
138
139
140
141
142
143
144
145
#include "infopiste.h"
InfoPiste::InfoPiste(const QString _chemin, const qint64 _finPiste, const int _frequence, const int _debit)
:finPiste(_finPiste),frequence(_frequence),debit(_debit)
{
touche="-";
valDebut=0;
affDebut="0:00:0";
echantillonage=16;
boucler=false;
if(_chemin!="")
cheminPiste(_chemin);
}
void InfoPiste::cheminPiste(QString val){
chemin=val;
//Définition nom de piste
int temp=val.lastIndexOf("/");
temp++;
nom=val.right(val.length()-temp);
//Définition extension
temp=val.lastIndexOf(".");
temp++;
extension=val.right(val.length()-temp);
if(extension=="wav")
analyseWAV();
if(extension=="aif" || extension=="aiff")
analyseAIFF();
}
void InfoPiste::analyseWAV(){
//Ouverture du fichier
QFile wavFile(chemin);
wavFile.open(QFile::ReadOnly);
//Lecture des données
QByteArray wavFileContent = wavFile.readAll();
//Taille (non sur disque)
tailleFichier=wavFileContent.size();
// Define the header components
char fileType[4];
qint32 fileSize;
char waveName[4];
char fmtName[3];
qint32 fmtLength;
short fmtType;
short numberOfChannels;
qint32 frequ;
qint32 sampleRateXBitsPerSampleXChanngelsDivEight;
short bitsPerSampleXChannelsDivEightPointOne;
short bitsPerSample;
char dataHeader[4];
qint32 dataSize;
// Create a data stream to analyze the data
QDataStream analyzeHeaderDS(&wavFileContent,QIODevice::ReadOnly);
analyzeHeaderDS.setByteOrder(QDataStream::LittleEndian);
// Now pop off the appropriate data into each header field defined above
analyzeHeaderDS.readRawData(fileType,4); // "RIFF"
analyzeHeaderDS >> fileSize; // File Size
analyzeHeaderDS.readRawData(waveName,4); // "WAVE"
analyzeHeaderDS.readRawData(fmtName,3); // "fmt"
analyzeHeaderDS >> fmtLength; // Format length
analyzeHeaderDS >> fmtType; // Format type
//Nombre de canaux
analyzeHeaderDS >> numberOfChannels;
numberOfChannels/=256;
//Fréquence
analyzeHeaderDS >> frequ;
frequ/=256;
analyzeHeaderDS >> sampleRateXBitsPerSampleXChanngelsDivEight; // (Sample Rate * BitsPerSample * Channels) / 8
analyzeHeaderDS >> bitsPerSampleXChannelsDivEightPointOne; // (BitsPerSample * Channels) / 8.1
//Echantillonage
analyzeHeaderDS >> bitsPerSample;
bitsPerSample/=256;
analyzeHeaderDS.readRawData(dataHeader,4); // "data" header
analyzeHeaderDS >> dataSize; // Data Size
echantillonage=bitsPerSample;
}
void InfoPiste::analyseAIFF()
{
QFile aiffFile(chemin);
aiffFile.open(QFile::ReadOnly);
QByteArray aiffFileContent = aiffFile.readAll();
char temp[20];
short nbCanaux;
qint32 nbFrames;
short bitsPerSample;
QDataStream analyse(&aiffFileContent,QIODevice::ReadOnly);
analyse.setByteOrder(QDataStream::BigEndian);
analyse.readRawData(temp,20);
analyse>>nbCanaux;
analyse>>nbFrames;
analyse>>bitsPerSample;
echantillonage=bitsPerSample;
}