framework2

Форк
0
281 строка · 6.8 Кб
1
#include "ofSoundPlayer.h"
2
#include "ofLog.h"
3
#define GLM_FORCE_CTOR_INIT
4
#include "glm/common.hpp"
5

6

7
#ifdef OF_SOUND_PLAYER_AV_ENGINE
8
#include "ofAVEngineSoundPlayer.h"
9
#define OF_SOUND_PLAYER_TYPE ofAVEngineSoundPlayer
10
#endif
11

12
#ifdef OF_SOUND_PLAYER_QUICKTIME
13
#include "ofQuicktimeSoundPlayer.h"
14
#define OF_SOUND_PLAYER_TYPE ofQuicktimeSoundPlayer
15
#endif
16

17
#ifdef OF_SOUND_PLAYER_FMOD
18
#include "ofFmodSoundPlayer.h"
19
#define OF_SOUND_PLAYER_TYPE ofFmodSoundPlayer
20
#endif
21

22
#ifdef OF_SOUND_PLAYER_MEDIA_FOUNDATION
23
#include "ofMediaFoundationSoundPlayer.h"
24
#define OF_SOUND_PLAYER_TYPE ofMediaFoundationSoundPlayer
25
#endif
26

27
#ifdef OF_SOUND_PLAYER_OPENAL
28
#include "ofOpenALSoundPlayer.h"
29
#define OF_SOUND_PLAYER_TYPE ofOpenALSoundPlayer
30
#endif
31

32
#ifdef TARGET_OF_IOS
33
#include "ofxiOSSoundPlayer.h"
34
#define OF_SOUND_PLAYER_TYPE ofxiOSSoundPlayer
35
#endif
36

37
#ifdef OF_SOUND_PLAYER_EMSCRIPTEN
38
#include "ofxEmscriptenSoundPlayer.h"
39
#define OF_SOUND_PLAYER_TYPE ofxEmscriptenSoundPlayer
40
#endif
41

42
#ifdef TARGET_ANDROID
43
#include "ofxAndroidSoundPlayer.h"
44
#define OF_SOUND_PLAYER_TYPE ofxAndroidSoundPlayer
45
#endif
46

47

48
// these are global functions, that affect every sound / channel:
49
// ------------------------------------------------------------
50

51
//--------------------
52
void ofSoundStopAll(){
53
	#ifdef OF_SOUND_PLAYER_FMOD
54
		ofFmodSoundStopAll();
55
	#else
56
		ofLogWarning("ofSoundPlayer") << "ofSoundStopAll() not implemented on this platform";
57
	#endif
58
}
59

60
//--------------------
61
void ofSoundSetVolume(float vol){
62
	#ifdef OF_SOUND_PLAYER_FMOD
63
		ofFmodSoundSetVolume(vol);
64
	#elif defined(OF_SOUND_PLAYER_MEDIA_FOUNDATION)
65
		ofMediaFoundationSoundPlayer::SetMasterVolume(vol);
66
	#else
67
		ofLogWarning("ofSoundPlayer") << "ofSoundSetVolume() not implemented on this platform";
68
	#endif
69
}
70

71
//--------------------
72
void ofSoundUpdate(){
73
	#ifdef OF_SOUND_PLAYER_FMOD
74
		ofFmodSoundUpdate();
75
	#endif
76
}
77

78
#if !defined(TARGET_ANDROID) && !defined(TARGET_LINUX_ARM)
79
//--------------------
80
void ofSoundShutdown(){
81
	#ifdef OF_SOUND_PLAYER_FMOD
82
		ofFmodSoundPlayer::closeFmod();
83
	#endif
84
	// ofSoundShutdown doesn't log an "unimplemented" message like the related functions
85
	// above, because it's called by the openFrameworks shutdown routine regardless
86
}
87
#endif
88

89
//--------------------
90
float * ofSoundGetSpectrum(int nBands){
91
	#ifdef OF_SOUND_PLAYER_FMOD
92
		return ofFmodSoundGetSpectrum(nBands);
93
	#elif defined(OF_SOUND_PLAYER_OPENAL)
94
		return ofOpenALSoundPlayer::getSystemSpectrum(nBands);
95
	#elif defined(OF_SOUND_PLAYER_EMSCRIPTEN)
96
		return ofxEmscriptenSoundPlayer::getSystemSpectrum(nBands);
97
	#else
98
		ofLogWarning("ofSoundPlayer") << "ofSoundGetSpectrum() not implemented on this platform, returning nullptr";
99
		return nullptr;
100
	#endif
101
}
102

103
//---------------------------------------------------------------------------
104
ofSoundPlayer::ofSoundPlayer (){
105
#ifdef OF_SOUND_PLAYER_TYPE
106
	player	= std::make_shared<OF_SOUND_PLAYER_TYPE>();
107
#endif
108
}
109

110
//---------------------------------------------------------------------------
111
void ofSoundPlayer::setPlayer(std::shared_ptr<ofBaseSoundPlayer> newPlayer){
112
	player = std::move(newPlayer);
113
}
114

115
//--------------------------------------------------------------------
116
std::shared_ptr<ofBaseSoundPlayer> ofSoundPlayer::getPlayer(){
117
	return player;
118
}
119

120
//--------------------------------------------------------------------
121
bool ofSoundPlayer::load(const of::filesystem::path& fileName, bool stream){
122
	if( player ){
123
		return player->load(fileName, stream);
124
	}
125
	return false;
126
}
127

128
//--------------------------------------------------------------------
129
bool ofSoundPlayer::loadSound(std::string fileName, bool stream){
130
	return load(fileName,stream);
131
}
132

133
//--------------------------------------------------------------------
134
void ofSoundPlayer::unload(){
135
	if( player ){
136
		player->unload();
137
	}
138
}
139

140
//--------------------------------------------------------------------
141
void ofSoundPlayer::unloadSound(){
142
	unload();
143
}
144

145
//--------------------------------------------------------------------
146
void ofSoundPlayer::play(){
147
	if( player ){
148
		player->play();
149
	}
150
}
151

152
//--------------------------------------------------------------------
153
void ofSoundPlayer::stop(){
154
	if( player ){
155
		player->stop();
156
	}
157
}
158

159
//--------------------------------------------------------------------
160
void ofSoundPlayer::setVolume(float vol){
161
	if( player ){
162
		player->setVolume(vol);
163
	}
164
}
165

166
//--------------------------------------------------------------------
167
void ofSoundPlayer::setPan(float pan){
168
	if( player ){
169
		player->setPan(glm::clamp(pan,-1.0f,1.0f));
170
	}
171
}
172

173
//--------------------------------------------------------------------
174
void ofSoundPlayer::setSpeed(float spd){
175
	if( player ){
176
		player->setSpeed(spd);
177
	}
178
}
179

180
//--------------------------------------------------------------------
181
void ofSoundPlayer::setPaused(bool bP){
182
	if( player ){
183
		player->setPaused(bP);
184
	}
185
}
186

187
//--------------------------------------------------------------------
188
void ofSoundPlayer::setLoop(bool bLp){
189
	if( player ){
190
		player->setLoop(bLp);
191
	}
192
}
193

194
//--------------------------------------------------------------------
195
void ofSoundPlayer::setMultiPlay(bool bMp){
196
	if( player ){
197
		player->setMultiPlay(bMp);
198
	}
199
}
200

201
//--------------------------------------------------------------------
202
void ofSoundPlayer::setPosition(float pct){
203
	if( player ){
204
		player->setPosition(pct);
205
	}
206
}
207

208
//--------------------------------------------------------------------
209
void ofSoundPlayer::setPositionMS(int ms){
210
	if( player ){
211
		player->setPositionMS(ms);
212
	}
213
}
214

215
//--------------------------------------------------------------------
216
float ofSoundPlayer::getPosition() const{
217
	if( player ){
218
		return player->getPosition();
219
	} else {
220
		return 0;
221
	}
222
}
223

224
//--------------------------------------------------------------------
225
int ofSoundPlayer::getPositionMS() const{
226
	if( player ){
227
		return player->getPositionMS();
228
	} else {
229
		return 0;
230
	}
231
}
232

233
//--------------------------------------------------------------------
234
bool ofSoundPlayer::isPlaying() const{
235
	if( player ){
236
		return player->isPlaying();
237
	} else {
238
		return false;
239
	}
240
}
241

242
//--------------------------------------------------------------------
243
bool ofSoundPlayer::getIsPlaying() const{
244
	return isPlaying();
245
}
246

247
//--------------------------------------------------------------------
248
bool ofSoundPlayer::isLoaded() const{
249
	if( player ){
250
		return player->isLoaded();
251
	} else {
252
		return false; 
253
	}
254
}
255

256
//--------------------------------------------------------------------
257
float ofSoundPlayer::getSpeed() const{
258
	if( player ){
259
		return player->getSpeed();
260
	} else {
261
		return 0;
262
	}
263
}
264

265
//--------------------------------------------------------------------
266
float ofSoundPlayer::getPan() const{
267
	if( player ){
268
		return player->getPan();
269
	} else {
270
		return 0;
271
	}
272
}
273

274
//--------------------------------------------------------------------
275
float ofSoundPlayer::getVolume() const{
276
	if( player ){
277
		return player->getVolume();
278
	} else {
279
		return 0;
280
	}
281
}
282

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.