Commits

Bart van Strien  committed 0848b1b

Fix seek and tell on streaming sounds (bugs #250 and #251)

  • Participants
  • Parent commits dc0eb4e

Comments (0)

Files changed (2)

File src/modules/audio/openal/Source.cpp

 			switch (*((Source::Unit*) unit)) {
 				case Source::UNIT_SAMPLES:
 					if (type == TYPE_STREAM) {
+						offsetSamples = offset;
 						ALint buffer;
 						alGetSourcei(source, AL_BUFFER, &buffer);
 						int freq;
 						alGetBufferi(buffer, AL_FREQUENCY, &freq);
 						offset /= freq;
+						offsetSeconds = offset;
 						decoder->seek(offset);
 					} else {
 						alSourcef(source, AL_SAMPLE_OFFSET, offset);
 				case Source::UNIT_SECONDS:	
 				default:
 					if (type == TYPE_STREAM) {
+						offsetSeconds = offset;
 						decoder->seek(offset);
+						ALint buffer;
+						alGetSourcei(source, AL_BUFFER, &buffer);
+						int freq;
+						alGetBufferi(buffer, AL_FREQUENCY, &freq);
+						offsetSamples = offset*freq;
 					} else {
 						alSourcef(source, AL_SEC_OFFSET, offset);
 					}
 					break;
 			}
+			if (type == TYPE_STREAM)
+			{
+				// Because we still have old data
+				// from before the seek in the buffers
+				// let's empty them.
+				stopAtomic(false);
+				playAtomic();
+			}
 		}
 	}
 
 		//but this prevents a horrible, horrible bug
 	}
 
-	void Source::stopAtomic()
+	void Source::stopAtomic(bool rewind)
 	{
 		if(valid)
 		{
 
 			alSourcei(source, AL_BUFFER, AL_NONE);
 		}
-		rewindAtomic();
+		if (rewind)
+			rewindAtomic();
 		valid = false;
 	}
 

File src/modules/audio/openal/Source.h

 		bool isStatic() const;
 
 		void playAtomic();
-		void stopAtomic();
+		void stopAtomic(bool rewind = true);
 		void pauseAtomic();
 		void resumeAtomic();
 		void rewindAtomic();