This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaPlayer.cpp
229 lines (203 loc) · 6.24 KB
/
MediaPlayer.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include ".\mediaplayer.h"
MediaPlayer::MediaPlayer()
{
}
MediaPlayer::~MediaPlayer()
{
}
void MediaPlayer::init()
{
result = FMOD::System_Create(&system);
ERRCHECK(result);
result = system->getVersion(&version);
ERRCHECK(result);
if (FMOD_VERSION < version)
{
if (RETRIEVESETTEST())
{
std:: cerr << "This is an old version of FMOD" << std::endl;
}
exit(0);
}
result = system->init(2, FMOD_INIT_NORMAL, 0);
ERRCHECK(result);
memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));
exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.nonblockcallback = nonblockcallback;
AudioChange = false;
matrix = new TableLocation();
returnresult = 0;
// PROCESSOR POWER OVERVIEW VARIABLES
prevchan = nchan = 0;
pdsp = pstream = pupdate = ptotal = cdsp = cstream = cupdate = ctotal = 0.0;
// /PROCESSOR POWER OVERVIEW VARIABLES
}
void MediaPlayer::update()
{
system->update();
if (AudioChange)
{
bool getchannelpaused = false;
int getchannelsplaying = 0;
result = system->getChannelsPlaying(&getchannelsplaying);
ERRCHECK(result);
if (getchannelsplaying > 0)
{
if (!matrix->returnCurrentPlaying()->getbeentroughCurrentUpdate())
{
returnresult = matrix->returnCurrentPlaying()->getCurrentLocationReference();
pending->LoadSound(system);
}
if (matrix->returnCurrentPlaying()->updatePosition(pending, returnresult) == 1)
{
AudioChange = false;
}
/*else if (matrix->returnCurrentPlaying()->updatePosition(pending, returnresult) == 3)
{
AudioChange = false;
this->InsertAudio(location_number, threat_number, succes_number);
}*/
}
else
{
unsigned int percentbuffed;
FMOD_OPENSTATE status;
bool starving;
pending->LoadSound(system);
//play chosen channel
FMOD::Channel *tempchan = NULL;
result = pending->getSound()->getOpenState(&status, &percentbuffed, &starving);
ERRCHECK(result);
if (status == FMOD_OPENSTATE_READY)
{
pending->Play(NULL);
Singleton::setCurrentlyPlaying(pending);
AudioChange = false;
}
else
{
if (RETRIEVESETTEST())
{
std::cout << "percentage loaded: " << percentbuffed << std::endl;
}
}
}
}
else
{
int getchannelsplaying = 0;
result = system->getChannelsPlaying(&getchannelsplaying);
ERRCHECK(result);
if (getchannelsplaying > 0)
{
if(matrix->returnCurrentPlaying()->getCurrentPosition() >= (matrix->returnCurrentPlaying()->getSoundLength() - 176400))
{
AudioChange = false;
InsertAudio(location_number, threat_number, succes_number);
}
}
}
Sleep(10);
prevchan = nchan;
result = system->getChannelsPlaying(&nchan);
ERRCHECK(result);
if (nchan != prevchan)
{
if (RETRIEVESETTEST())
{
std::cout << "Number of channels playing CHANGED!!! Current number of channels playing: " << nchan << std::endl;
}
}
pdsp = cdsp;
pstream = cstream;
pupdate = cupdate;
ptotal = ctotal;
result = system->getCPUUsage(&cdsp, &cstream, &cupdate, &ctotal);
ERRCHECK(result);
if ((ctotal - ptotal) >= 0.3 )
{
if (RETRIEVESETTEST())
{
std::cout << std::setprecision(2) << "current CPU usage: DSP: " << cdsp << "%, Stream: " << cstream
<< "%, Update: "<< cupdate << "%, Total :" << ctotal << "%"<< std::endl;
}
}
}
void MediaPlayer::InsertAudio(unsigned int location_vnumber, unsigned int threat_vnumber, unsigned int succes_vnumber, unsigned int AudioLoopnumber)
{
pending = matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->getVector()[succes_vnumber]->getVector()[AudioLoopnumber];
AudioChange = true;
}
void MediaPlayer::InsertAudio(unsigned int location_vnumber, unsigned int threat_vnumber, unsigned int succes_vnumber)
{
pending = matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->getVector()[succes_vnumber]->ChooseAudioLoopfromVector();
if (RETRIEVESETTEST())
{
std::cout << "MediaPlayer::InserAudio(unsigned int location_vnumber, unsigned int threat_vnumber, unsigned int succes_vnumber) return the following AudioLoop: " << pending->getFileName() << std::endl;
}
AudioChange = true;
}
void MediaPlayer::quit()
{
system->close();
exit(0);
}
void MediaPlayer::InsertFile(unsigned int location_vnumber, unsigned int threat_vnumber, unsigned int succes_vnumber, char* AudioLoopFilename, std::vector<int> *breakpoints)
{
location_number = location_vnumber;
threat_number = threat_vnumber;
succes_number = succes_vnumber;
if (matrix->getVector().size() < (location_vnumber+1))
{
while(matrix->getVector().size() <= location_vnumber)
{
matrix->add(new TableThreat());
}
}
else if (matrix->getVector()[location_vnumber]->getVector().size() < (threat_vnumber+1))
{
while(matrix->getVector()[location_vnumber]->getVector().size() <= threat_vnumber)
{
matrix->getVector()[location_vnumber]->add(new TableSucces());
}
}
else if (matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->getVector().size() < (succes_vnumber+1))
{
while(matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->getVector().size() <= succes_vnumber)
{
matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->add(new TableAudioLoop());
}
}
AudioLoop *test = new AudioLoop(AudioLoopFilename, 6, 44100, *breakpoints, system);
matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->getVector()[succes_vnumber]->add(test);
matrix->getVector()[location_vnumber]->getVector()[threat_vnumber]->getVector()[succes_vnumber]->_SETTEST = 0;
}
TableLocation* MediaPlayer::getMatrix()
{
return matrix;
}
void MediaPlayer::SETTEST(int newtestvariable)
{
this->_SETTEST = 0;
matrix->_SETTEST = 0;
for (unsigned int i = 0; i < matrix->getVector().size(); i++)
{
for (unsigned int k = 0; k < matrix->getVector()[i]->getVector().size(); k++)
{
for (unsigned int l = 0; l <matrix->getVector()[i]->getVector()[k]->getVector().size(); l++)
{
for (unsigned int m = 0; m < matrix->getVector()[i]->getVector()[k]->getVector()[l]->getVector().size(); m++)
{
matrix->getVector()[i]->getVector()[k]->getVector()[l]->getVector()[m]->_SETTEST = 0;
}
matrix->getVector()[i]->getVector()[k]->getVector()[l]->_SETTEST = 0;
}
matrix->getVector()[i]->getVector()[k]->_SETTEST = 0;
}
matrix->getVector()[i]->_SETTEST = 0;
}
}
int MediaPlayer::RETRIEVESETTEST()
{
return _SETTEST;
}