summaryrefslogtreecommitdiff
path: root/futuregael/soundPlayerDuration.patch
blob: b7cdd285c02ab414bd1c8733134dd137bd453d58 (plain)
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
diff --git a/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp b/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp
index 51cc5f05a..aaa4e283c 100644
--- a/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp
+++ b/libs/openFrameworks/sound/ofFmodSoundPlayer.cpp
@@ -5,6 +5,7 @@
 #include "ofMath.h"
 #include "ofLog.h"
 
+#include "ofAppRunner.h"
 
 static bool bFmodInitialized_ = false;
 static float fftInterpValues_[8192];			//
@@ -36,6 +37,23 @@ void ofFmodSoundSetVolume(float vol){
 void ofFmodSoundUpdate(){
 	if (bFmodInitialized_){
 		FMOD_System_Update(sys);
+
+		unsigned int size;
+		int numbuffers;
+		FMOD_System_GetDSPBufferSize(sys, &size, &numbuffers);
+		/*
+		unsigned int hi, lo;
+		FMOD_Channel_GetDSPClock(sys, &hi, &lo);
+		int rate;
+		FMOD_SOUND_FORMAT format;
+		int outchannels, inchannels;
+		FMOD_DSP_RESAMPLER resamplemethod;
+		int bits;
+		FMOD_System_GetSoftwareFormat(sys, &rate, &format, &outchannels, &inchannels, &resamplemethod, &bits);
+		std::cout << "size: " << buffersize << std::endl;
+		std::cout << hi << " " << lo << std::endl;
+		std::cout << lo / double(rate) << " - " << ofGetElapsedTimef() << std::endl;
+		*/
 	}
 }
 
@@ -280,6 +298,16 @@ void ofFmodSoundPlayer::setPositionMS(int ms) {
 		FMOD_Channel_SetPosition(channel, ms, FMOD_TIMEUNIT_MS);
 	}
 }
+//------------------------------------------------------------
+uint64_t ofFmodSoundPlayer::getDurationMS() const{
+	if(isLoaded()){
+		unsigned int ms;
+		FMOD_Sound_GetLength(sound, &ms, FMOD_TIMEUNIT_MS);
+		return ms;
+	}else{
+		return 0;
+	}
+}
 
 //------------------------------------------------------------
 float ofFmodSoundPlayer::getPosition() const{
diff --git a/libs/openFrameworks/sound/ofFmodSoundPlayer.h b/libs/openFrameworks/sound/ofFmodSoundPlayer.h
index b54f1b2e6..ea211f7ad 100644
--- a/libs/openFrameworks/sound/ofFmodSoundPlayer.h
+++ b/libs/openFrameworks/sound/ofFmodSoundPlayer.h
@@ -62,6 +62,7 @@ class ofFmodSoundPlayer : public ofBaseSoundPlayer {
 		float getPan() const;
 		float getVolume() const;
 		bool isLoaded() const;
+		uint64_t getDurationMS() const;
 
 		static void initializeFmod();
 		static void closeFmod();
diff --git a/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp b/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp
index 71caf42d8..093709e82 100644
--- a/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp
+++ b/libs/openFrameworks/sound/ofOpenALSoundPlayer.cpp
@@ -692,6 +692,11 @@ void ofOpenALSoundPlayer::update(ofEventArgs & args){
 	}
 }
 
+uint64_t ofOpenALSoundPlayer::getDurationMS() const{
+	return duration * 1000;
+}
+
+
 //------------------------------------------------------------
 void ofOpenALSoundPlayer::unload(){
 	stop();
diff --git a/libs/openFrameworks/sound/ofOpenALSoundPlayer.h b/libs/openFrameworks/sound/ofOpenALSoundPlayer.h
index 042f7b354..df09811ca 100644
--- a/libs/openFrameworks/sound/ofOpenALSoundPlayer.h
+++ b/libs/openFrameworks/sound/ofOpenALSoundPlayer.h
@@ -76,6 +76,8 @@ class ofOpenALSoundPlayer : public ofBaseSoundPlayer, public ofThread {
 		bool isPaused() const;
 		bool isLoaded() const;
 
+		uint64_t getDurationMS() const;
+
 		static void initialize();
 		static void close();
 
diff --git a/libs/openFrameworks/sound/ofSoundBaseTypes.h b/libs/openFrameworks/sound/ofSoundBaseTypes.h
index 3f2e1aa98..1b2a9b73b 100644
--- a/libs/openFrameworks/sound/ofSoundBaseTypes.h
+++ b/libs/openFrameworks/sound/ofSoundBaseTypes.h
@@ -3,6 +3,8 @@
 #include "ofConstants.h"
 #include <functional>
 
+#include "ofLog.h"
+
 class ofSoundBuffer;
 
 
@@ -189,4 +191,9 @@ public:
 	virtual bool isLoaded() const = 0;
 	virtual float getVolume() const = 0;
 
+	virtual uint64_t getDurationMS() const{
+		ofLogError("ofBaseSoundPlayer") << "getDurationMS not implemented for this platform";
+		return 0;
+	}
+
 };
diff --git a/libs/openFrameworks/sound/ofSoundPlayer.cpp b/libs/openFrameworks/sound/ofSoundPlayer.cpp
index 060b0daa2..9c914cbbe 100644
--- a/libs/openFrameworks/sound/ofSoundPlayer.cpp
+++ b/libs/openFrameworks/sound/ofSoundPlayer.cpp
@@ -237,3 +237,12 @@ float ofSoundPlayer::getVolume() const{
 		return 0;
 	}
 }
+
+//--------------------------------------------------------------------
+uint64_t ofSoundPlayer::getDurationMS() const{
+	if( player ){
+		return player->getDurationMS();
+	} else {
+		return 0;
+	}
+}
diff --git a/libs/openFrameworks/sound/ofSoundPlayer.h b/libs/openFrameworks/sound/ofSoundPlayer.h
index a24bfdcc5..358c81965 100644
--- a/libs/openFrameworks/sound/ofSoundPlayer.h
+++ b/libs/openFrameworks/sound/ofSoundPlayer.h
@@ -156,6 +156,10 @@ public:
     /// \return whether or not the player is ready to begin playback.
     bool isLoaded() const;
 
+    /// Returns the duration of the sound in ms.
+    uint64_t getDurationMS() const;
+
+
 protected:
     std::shared_ptr<ofBaseSoundPlayer> player;