From eb138f92f27d476f378f7c3e8ff7baf368f1c2fa Mon Sep 17 00:00:00 2001 From: rude Date: Sun, 31 Jan 2010 16:30:30 +0100 Subject: [PATCH] Fixed seeking. In theory. --- src/modules/sound/lullaby/Mpg123Decoder.cpp | 14 +++++++-- src/modules/sound/lullaby/VorbisDecoder.cpp | 32 ++++++++------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/modules/sound/lullaby/Mpg123Decoder.cpp b/src/modules/sound/lullaby/Mpg123Decoder.cpp index de4c5d95e..917e84d27 100644 --- a/src/modules/sound/lullaby/Mpg123Decoder.cpp +++ b/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() diff --git a/src/modules/sound/lullaby/VorbisDecoder.cpp b/src/modules/sound/lullaby/VorbisDecoder.cpp index 6acdf1e9d..a270e825d 100644 --- a/src/modules/sound/lullaby/VorbisDecoder.cpp +++ b/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()