]> git.tdb.fi Git - libs/al.git/blobdiff - source/sound.cpp
Update Build file with new builder features
[libs/al.git] / source / sound.cpp
index 947f6d17c1684fcab1f0422e26bf8978d90dcd84..fe2de5eb5c4b85faa6c05c25e64a0d30d44f775d 100644 (file)
@@ -1,5 +1,5 @@
 #include <cstring>
-#include <msp/core/except.h>
+#include <stdexcept>
 #include "sound.h"
 
 using namespace std;
@@ -18,7 +18,7 @@ struct MemorySource
 size_t memory_read(void *ptr, size_t size, size_t nmemb, void *src)
 {
        MemorySource &memsrc = *reinterpret_cast<MemorySource *>(src);
-       unsigned len = min(size*nmemb, memsrc.length-memsrc.pos);
+       unsigned len = min<unsigned>(size*nmemb, memsrc.length-memsrc.pos);
        memcpy(ptr, reinterpret_cast<const char *>(memsrc.data)+memsrc.pos, len);
        memsrc.pos += len;
 
@@ -81,9 +81,9 @@ Sound::~Sound()
 void Sound::open_file(const string &fn)
 {
        if(ovfile.datasource)
-               throw InvalidState("Sound has already been opened");
+               throw logic_error("Sound has already been opened");
        if(ov_fopen(const_cast<char *>(fn.c_str()), &ovfile)<0)
-               throw Exception("Could not open ogg vorbis file "+fn);
+               throw runtime_error("Could not open ogg vorbis file "+fn);
 
        open_common();
 }
@@ -91,22 +91,37 @@ void Sound::open_file(const string &fn)
 void Sound::open_memory(const void *d, unsigned len)
 {
        if(ovfile.datasource)
-               throw InvalidState("Sound has already been opened");
+               throw logic_error("Sound has already been opened");
 
        MemorySource *src = new MemorySource(d, len);
        if(ov_open_callbacks(src, &ovfile, 0, 0, memory_callbacks)<0)
        {
                delete src;
-               throw Exception("Could not open ogg vorbis memory block");
+               throw runtime_error("Could not open ogg vorbis memory block");
        }
 
        open_common();
 }
 
+void Sound::open_common()
+{
+       delete data;
+       data = 0;
+
+       vorbis_info *info = ov_info(&ovfile, -1);
+       freq = info->rate;
+       switch(info->channels)
+       {
+       case 1: format = MONO16; break;
+       case 2: format = STEREO16; break;
+       default: throw runtime_error("Unsupported number of channels");
+       }
+}
+
 void Sound::load_data()
 {
        if(data)
-               throw InvalidState("Data has already been loaded");
+               throw logic_error("Data has already been loaded");
 
        size = ov_pcm_total(&ovfile, 0)*4;
        char *dptr = new char[size];
@@ -160,36 +175,21 @@ unsigned Sound::read(char *buf, unsigned len)
                int section = 0;
                int res = ov_read(&ovfile, buf, len, 0, 2, 1, &section);
                if(res<0)
-                       throw Exception("Error reading ogg vorbis file");
+                       throw runtime_error("Error reading ogg vorbis file");
                else if(res==0)
                        eof_flag = true;
                return res;
        }
        else
-               throw InvalidState("No data available");
+               throw logic_error("No data available");
 }
 
 const char *Sound::get_data() const
 {
        if(!data)
-               throw InvalidState("Data has not been loaded");
+               throw logic_error("Data has not been loaded");
        return data;
 }
 
-void Sound::open_common()
-{
-       delete data;
-       data = 0;
-
-       vorbis_info *info = ov_info(&ovfile, -1);
-       freq = info->rate;
-       switch(info->channels)
-       {
-       case 1: format = MONO16; break;
-       case 2: format = STEREO16; break;
-       default: throw Exception("Unsupported number of channels");
-       }
-}
-
 } // namespace AL
 } // namespace Msp