static const char id3_sig[] = { 'I', 'D', '3' };
if(sig.size()<sizeof(id3_sig))
return false;
- return !sig.compare(0, sizeof(id3_sig), id3_sig);
+ return !sig.compare(0, sizeof(id3_sig), id3_sig, sizeof(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)