]> git.tdb.fi Git - libs/al.git/blobdiff - source/mp3decoder.cpp
Fix sound file signature comparisons
[libs/al.git] / source / mp3decoder.cpp
index ec08be7f9a5969bfe2ee67ad81f4a1eb5adf6bbd..cc3235683db098cc5782ef11ba2b7094678f9bb1 100644 (file)
@@ -84,12 +84,35 @@ bool Mp3Decoder::detect(const string &sig)
        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)