X-Git-Url: http://git.tdb.fi/?p=libs%2Fal.git;a=blobdiff_plain;f=source%2Fmp3decoder.cpp;fp=source%2Fmp3decoder.cpp;h=34604e320339dc5bdb0dcae98125e78d160ceee1;hp=ec08be7f9a5969bfe2ee67ad81f4a1eb5adf6bbd;hb=d365c5394308740f478fbdfbb23e2c5d972f19f0;hpb=85914b1843bd89ca94a722cc26e572089dbd0774 diff --git a/source/mp3decoder.cpp b/source/mp3decoder.cpp index ec08be7..34604e3 100644 --- a/source/mp3decoder.cpp +++ b/source/mp3decoder.cpp @@ -87,9 +87,32 @@ bool Mp3Decoder::detect(const string &sig) return !sig.compare(0, sizeof(id3_sig), id3_sig); } -void Mp3Decoder::rewind() +void Mp3Decoder::seek(unsigned pos) { + unsigned unit = get_unit_size(format); + pos /= unit; + in.seek(0, IO::S_BEG); + mad_stream_buffer(&priv->stream, 0, 0); + fill_input(); + if(!pos) + { + priv->synth.pcm.length = 0; + return; + } + + while(decode(false)) + { + unsigned frame_len = 32*MAD_NSBSAMPLES(&priv->frame.header); + if(frame_len>pos) + { + decode(true); + read_pos = pos; + break; + } + + pos -= frame_len; + } } unsigned Mp3Decoder::read(char *buf, unsigned len)