Ver Fonte

Sound duration and position getters

Ivan Safrin há 13 anos atrás
pai
commit
b7bfa86c25

+ 5 - 0
Core/Contents/Include/PolySound.h

@@ -96,6 +96,11 @@ namespace Polycode {
 		*/
 		void setOffset(int off);
 		
+		
+		Number getPlaybackDuration();
+		
+		Number getPlaybackTime();
+		
 		/**
 		* Returns the current sample offset (playback progress) of this sound.
 		* @return The sample offset if it is known, -1 otherwise.

+ 27 - 0
Core/Contents/Source/PolySound.cpp

@@ -153,6 +153,33 @@ void Sound::setOffset(int off) {
 	alSourcei(soundSource, AL_SAMPLE_OFFSET, off);
 }
 
+
+Number Sound::getPlaybackTime() {
+	float result = 0.0;
+	alGetSourcef(soundSource, AL_SEC_OFFSET, &result);
+	return result;
+}
+
+Number Sound::getPlaybackDuration() {
+	ALint sizeInBytes;
+	ALint channels;
+	ALint bits;
+	ALint bufferID;
+	alGetSourcei(soundSource, AL_BUFFER, &bufferID);
+	
+	alGetBufferi(bufferID, AL_SIZE, &sizeInBytes);
+	alGetBufferi(bufferID, AL_CHANNELS, &channels);
+	alGetBufferi(bufferID, AL_BITS, &bits);
+
+	int lengthInSamples = sizeInBytes * 8 / (channels * bits);
+
+	ALint frequency;
+	alGetBufferi(bufferID, AL_FREQUENCY, &frequency);
+	Number durationInSeconds = (float)lengthInSamples / (float)frequency;
+	
+	return durationInSeconds;
+}
+		
 int Sound::getOffset() {
 	ALint off = -1;
 	alGetSourcei(soundSource, AL_SAMPLE_OFFSET, &off);

+ 1 - 1
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -314,7 +314,7 @@ void PhysicsScreen::setVelocityY(ScreenEntity *ent, Number fy) {
 
 PhysicsScreenEntity *PhysicsScreen::addCollisionChild(ScreenEntity *newEntity, int entType) {
 	PhysicsScreenEntity *ret;
-	ret = addPhysicsChild(newEntity, entType, false, 0,0.1,0, true);
+	ret = addPhysicsChild(newEntity, entType, false, 0,0.0,0, true);
 	ret->collisionOnly = true; 
 	return ret;
 }