Browse Source

Fixed seeking. In theory.

rude 15 years ago
parent
commit
eb138f92f2

+ 12 - 2
src/modules/sound/lullaby/Mpg123Decoder.cpp

@@ -150,9 +150,19 @@ namespace lullaby
 
 	bool Mpg123Decoder::seek(float s)
 	{
-		off_t r = mpg123_seek(handle, (off_t)(s*1000.0f), SEEK_SET);
+		off_t offset = mpg123_timeframe(handle, s);
 
-		return (r >= 0);
+		if(offset < 0)
+			return false;
+
+		if(mpg123_feedseek(handle, 0, SEEK_SET, &offset) >= 0)
+		{
+			data_offset = offset;
+			eof = false;
+			return true;
+		}
+		else
+			return false;
 	}
 
 	bool Mpg123Decoder::rewind()

+ 12 - 20
src/modules/sound/lullaby/VorbisDecoder.cpp

@@ -206,26 +206,12 @@ namespace lullaby
 
 	bool VorbisDecoder::seek(float s)
 	{
-		eof = false;
-		int result = ov_time_seek(&handle, (int)(s*1000.0f) / 100);
+		int result = ov_time_seek(&handle, s);
 
 		if(result == 0)
-			return true;
-		
-		switch(result)
 		{
-		case OV_ENOSEEK:
-			throw love::Exception("Vorbis seek: Bitstream is unseekable");
-		case OV_EINVAL:
-			throw love::Exception("Vorbis seek: Invalid argument value");
-		case OV_EREAD:
-			throw love::Exception("Vorbis seek: Read from media");
-		case OV_EFAULT:
-			throw love::Exception("Vorbis seek: Internal logic fault (bug or heap/stack corruption)");
-		case OV_EBADLINK:
-			throw love::Exception("Vorbis seek: Invalid stream section supplied or link is corrupt");
-		default:
-			throw love::Exception("Vorbis seek: Unknown error");
+			eof = false;
+			return true;
 		}
 
 		return false;
@@ -233,9 +219,15 @@ namespace lullaby
 
 	bool VorbisDecoder::rewind()
 	{
-		eof = false;
-		ov_pcm_seek(&handle, 0);
-		return true;
+		int result = ov_pcm_seek(&handle, 0);
+
+		if(result == 0)
+		{
+			eof = false;
+			return true;
+		}
+
+		return false;
 	}
 
 	bool VorbisDecoder::isSeekable()