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)
static bool detect(const std::string &);
- virtual void rewind();
+ virtual void seek(unsigned);
virtual unsigned read(char *, unsigned);
private:
return !sig.compare(0, sizeof(ogg_sig), ogg_sig);
}
-void OggDecoder::rewind()
+void OggDecoder::seek(unsigned pos)
{
- ov_pcm_seek(&priv->ovfile, 0);
+ pos /= get_unit_size(format);
+ ov_pcm_seek(&priv->ovfile, pos);
}
unsigned OggDecoder::read(char *buf, unsigned len)
static bool detect(const std::string &);
- virtual void rewind();
+ virtual void seek(unsigned);
virtual unsigned read(char *, unsigned);
};
static SoundDecoder *open_file(const std::string &);
static SoundDecoder *open_io(IO::Seekable &);
- virtual void rewind() = 0;
+ virtual void rewind() { seek(0); }
+ virtual void seek(unsigned) = 0;
virtual unsigned read(char *, unsigned) = 0;
bool eof() const { return eof_flag; }