]> git.tdb.fi Git - libs/al.git/blobdiff - source/oggdecoder.cpp
Fix sound file signature comparisons
[libs/al.git] / source / oggdecoder.cpp
index 5462b79bb4d8c6c0cdd0c3871cf9e91d1bafdb81..374cf0b5ba06966174270a96c1d193a511843bcb 100644 (file)
@@ -1,4 +1,7 @@
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-variable"
 #include <vorbis/vorbisfile.h>
+#pragma GCC diagnostic pop
 #include <msp/strings/format.h>
 #include "oggdecoder.h"
 
@@ -86,15 +89,9 @@ OggDecoder::OggDecoder(IO::Seekable &io):
 
        vorbis_info *info = ov_info(&priv->ovfile, -1);
        freq = info->rate;
+       format = create_format(2, info->channels);
 
-       size = ov_pcm_total(&priv->ovfile, 0)*info->channels*2;
-
-       switch(info->channels)
-       {
-       case 1: format = MONO16; break;
-       case 2: format = STEREO16; break;
-       default: throw unsupported_sound(Msp::format("%d channels", info->channels));
-       }
+       size = ov_pcm_total(&priv->ovfile, 0)*get_unit_size(format);
 }
 
 OggDecoder::~OggDecoder()
@@ -104,9 +101,18 @@ OggDecoder::~OggDecoder()
        delete priv;
 }
 
-void OggDecoder::rewind()
+bool OggDecoder::detect(const std::string &sig)
+{
+       static const char ogg_sig[] = { 'O', 'g', 'g', 'S' };
+       if(sig.size()<sizeof(ogg_sig))
+               return false;
+       return !sig.compare(0, sizeof(ogg_sig), ogg_sig, sizeof(ogg_sig));
+}
+
+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)