framework2
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//--------------------
52void ofSoundStopAll(){
53#ifdef OF_SOUND_PLAYER_FMOD
54ofFmodSoundStopAll();
55#else
56ofLogWarning("ofSoundPlayer") << "ofSoundStopAll() not implemented on this platform";
57#endif
58}
59
60//--------------------
61void ofSoundSetVolume(float vol){
62#ifdef OF_SOUND_PLAYER_FMOD
63ofFmodSoundSetVolume(vol);
64#elif defined(OF_SOUND_PLAYER_MEDIA_FOUNDATION)
65ofMediaFoundationSoundPlayer::SetMasterVolume(vol);
66#else
67ofLogWarning("ofSoundPlayer") << "ofSoundSetVolume() not implemented on this platform";
68#endif
69}
70
71//--------------------
72void ofSoundUpdate(){
73#ifdef OF_SOUND_PLAYER_FMOD
74ofFmodSoundUpdate();
75#endif
76}
77
78#if !defined(TARGET_ANDROID) && !defined(TARGET_LINUX_ARM)
79//--------------------
80void ofSoundShutdown(){
81#ifdef OF_SOUND_PLAYER_FMOD
82ofFmodSoundPlayer::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//--------------------
90float * ofSoundGetSpectrum(int nBands){
91#ifdef OF_SOUND_PLAYER_FMOD
92return ofFmodSoundGetSpectrum(nBands);
93#elif defined(OF_SOUND_PLAYER_OPENAL)
94return ofOpenALSoundPlayer::getSystemSpectrum(nBands);
95#elif defined(OF_SOUND_PLAYER_EMSCRIPTEN)
96return ofxEmscriptenSoundPlayer::getSystemSpectrum(nBands);
97#else
98ofLogWarning("ofSoundPlayer") << "ofSoundGetSpectrum() not implemented on this platform, returning nullptr";
99return nullptr;
100#endif
101}
102
103//---------------------------------------------------------------------------
104ofSoundPlayer::ofSoundPlayer (){
105#ifdef OF_SOUND_PLAYER_TYPE
106player = std::make_shared<OF_SOUND_PLAYER_TYPE>();
107#endif
108}
109
110//---------------------------------------------------------------------------
111void ofSoundPlayer::setPlayer(std::shared_ptr<ofBaseSoundPlayer> newPlayer){
112player = std::move(newPlayer);
113}
114
115//--------------------------------------------------------------------
116std::shared_ptr<ofBaseSoundPlayer> ofSoundPlayer::getPlayer(){
117return player;
118}
119
120//--------------------------------------------------------------------
121bool ofSoundPlayer::load(const of::filesystem::path& fileName, bool stream){
122if( player ){
123return player->load(fileName, stream);
124}
125return false;
126}
127
128//--------------------------------------------------------------------
129bool ofSoundPlayer::loadSound(std::string fileName, bool stream){
130return load(fileName,stream);
131}
132
133//--------------------------------------------------------------------
134void ofSoundPlayer::unload(){
135if( player ){
136player->unload();
137}
138}
139
140//--------------------------------------------------------------------
141void ofSoundPlayer::unloadSound(){
142unload();
143}
144
145//--------------------------------------------------------------------
146void ofSoundPlayer::play(){
147if( player ){
148player->play();
149}
150}
151
152//--------------------------------------------------------------------
153void ofSoundPlayer::stop(){
154if( player ){
155player->stop();
156}
157}
158
159//--------------------------------------------------------------------
160void ofSoundPlayer::setVolume(float vol){
161if( player ){
162player->setVolume(vol);
163}
164}
165
166//--------------------------------------------------------------------
167void ofSoundPlayer::setPan(float pan){
168if( player ){
169player->setPan(glm::clamp(pan,-1.0f,1.0f));
170}
171}
172
173//--------------------------------------------------------------------
174void ofSoundPlayer::setSpeed(float spd){
175if( player ){
176player->setSpeed(spd);
177}
178}
179
180//--------------------------------------------------------------------
181void ofSoundPlayer::setPaused(bool bP){
182if( player ){
183player->setPaused(bP);
184}
185}
186
187//--------------------------------------------------------------------
188void ofSoundPlayer::setLoop(bool bLp){
189if( player ){
190player->setLoop(bLp);
191}
192}
193
194//--------------------------------------------------------------------
195void ofSoundPlayer::setMultiPlay(bool bMp){
196if( player ){
197player->setMultiPlay(bMp);
198}
199}
200
201//--------------------------------------------------------------------
202void ofSoundPlayer::setPosition(float pct){
203if( player ){
204player->setPosition(pct);
205}
206}
207
208//--------------------------------------------------------------------
209void ofSoundPlayer::setPositionMS(int ms){
210if( player ){
211player->setPositionMS(ms);
212}
213}
214
215//--------------------------------------------------------------------
216float ofSoundPlayer::getPosition() const{
217if( player ){
218return player->getPosition();
219} else {
220return 0;
221}
222}
223
224//--------------------------------------------------------------------
225int ofSoundPlayer::getPositionMS() const{
226if( player ){
227return player->getPositionMS();
228} else {
229return 0;
230}
231}
232
233//--------------------------------------------------------------------
234bool ofSoundPlayer::isPlaying() const{
235if( player ){
236return player->isPlaying();
237} else {
238return false;
239}
240}
241
242//--------------------------------------------------------------------
243bool ofSoundPlayer::getIsPlaying() const{
244return isPlaying();
245}
246
247//--------------------------------------------------------------------
248bool ofSoundPlayer::isLoaded() const{
249if( player ){
250return player->isLoaded();
251} else {
252return false;
253}
254}
255
256//--------------------------------------------------------------------
257float ofSoundPlayer::getSpeed() const{
258if( player ){
259return player->getSpeed();
260} else {
261return 0;
262}
263}
264
265//--------------------------------------------------------------------
266float ofSoundPlayer::getPan() const{
267if( player ){
268return player->getPan();
269} else {
270return 0;
271}
272}
273
274//--------------------------------------------------------------------
275float ofSoundPlayer::getVolume() const{
276if( player ){
277return player->getVolume();
278} else {
279return 0;
280}
281}
282