]> Dogcows Code - chaz/yoink/commitdiff
improved new vorbisfile compatibility
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Thu, 24 Sep 2009 01:36:52 +0000 (19:36 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Thu, 24 Sep 2009 01:36:52 +0000 (19:36 -0600)
src/Character.cc
src/Moof/Sound.cc
src/Moof/Sound.hh

index 3a9559f003776ed32a813afd365b9fa0dfec7fab..c6ad2a049874d821befa4e90da831703ce2ec653 100644 (file)
@@ -66,7 +66,7 @@ void Character::update(Mf::Scalar t, Mf::Scalar dt)
        current.force += -20.0 * (mag - d) * (x / mag) - 2.0 * current.velocity;
        current.force += userForce;
        current.recalculate();
-       std::cout << "force: " << current.momentum << std::endl;
+       //std::cout << "force: " << current.momentum << std::endl;
 
        Mf::integrate<State,Derivative>(current, t, dt);
 
index 43714fe04872a93e968c0e44d0c7724f78b2d966..f912b318d153c2dfa13ecf1b991169f4e87751ee 100644 (file)
@@ -59,7 +59,6 @@ struct Sound::Impl
        
        class Buffer : public Mippleton<Buffer>
        {
-               FILE*                                   soundFile;
                OggVorbis_File                  oggStream;
                ALenum                                  audioFormat;
                ALsizei                                 audioFreq;
@@ -68,9 +67,9 @@ struct Sound::Impl
        public:
 
                Buffer(const std::string& name) :
-                       Mippleton<Buffer>(name),
-                       soundFile(0)
+                       Mippleton<Buffer>(name)
                {
+                       oggStream.datasource = 0;
                        openFile();
                }
 
@@ -82,7 +81,7 @@ struct Sound::Impl
                                objects.pop_back();
                        }
 
-                       if (soundFile)
+                       if (oggStream.datasource)
                        {
                                ov_clear(&oggStream);
                        }
@@ -91,30 +90,18 @@ struct Sound::Impl
 
                void openFile()
                {
-                       if (soundFile)
+                       if (oggStream.datasource)
                        {
                                ov_clear(&oggStream);
-                               soundFile = 0;
+                               oggStream.datasource = 0;
                        }
 
-                       //soundFile = Sound_NewSampleFromFile(soundFile::getPath(getName()).c_str(),
-                                       //0, BUFFER_SIZE);
-                       soundFile = fopen(Sound::getPath(getName()).c_str(), "rb");
-
-                       if (!soundFile)
-                       {
-                               logWarning("error while loading sound %s", getName().c_str());
-                               throw Exception(Exception::FILE_NOT_FOUND);
-                       }
-
-                       int result = ov_open(soundFile, &oggStream, NULL, 0);
+                       std::string filePath = Sound::getPath(getName());
+                       int result = ov_fopen((char*)filePath.c_str(), &oggStream);
 
                        if (result < 0)
                        {
-                               fclose(soundFile);
-                               soundFile = 0;
-
-                               logWarning("error while loading oggvorbis stream %s",
+                               logWarning("error while loading sound %s",
                                                getName().c_str());
                                throw Exception(Exception::BAD_AUDIO_FORMAT);
                        }
@@ -123,7 +110,6 @@ struct Sound::Impl
                        audioFormat = getAudioFormat(vorbisInfo);
                        audioFreq = vorbisInfo->rate;
 
-                       logDebug("    version: %d", vorbisInfo->version);
                        logDebug("   channels: %d", vorbisInfo->channels);
                        logDebug("  frequency: %d", vorbisInfo->rate);
                }
@@ -131,13 +117,12 @@ struct Sound::Impl
 
                void loadAll(ALuint source)
                {
-                       if (!soundFile) openFile();
-                       if (!soundFile) return;
+                       if (!oggStream.datasource) openFile();
+                       if (!oggStream.datasource) return;
 
                        char data[BUFFER_SIZE];
                        int size = 0;
 
-                       //unsigned decoded = Sound_DecodeAll(soundFile);
                        for (;;)
                        {
                                int section;
@@ -172,14 +157,14 @@ struct Sound::Impl
 
                        // don't need this anymore
                        ov_clear(&oggStream);
-                       soundFile = 0;
+                       oggStream.datasource = 0;
                }
 
 
                void beginStream(ALuint source, int nBuffers = 4)
                {
-                       if (!soundFile) openFile();
-                       if (!soundFile) return;
+                       if (!oggStream.datasource) openFile();
+                       if (!oggStream.datasource) return;
 
                        ALuint objs[nBuffers];
                        alGenBuffers(nBuffers, objs);
@@ -211,7 +196,6 @@ struct Sound::Impl
                        char data[BUFFER_SIZE];
                        int size = 0;
 
-                       //unsigned bytes = Sound_Decode(soundFile);
                        while (size < BUFFER_SIZE)
                        {
                                int section;
@@ -238,7 +222,7 @@ struct Sound::Impl
 
                inline void rewind()
                {
-                       if (!soundFile) openFile();
+                       if (!oggStream.datasource) openFile();
                        else ov_raw_seek(&oggStream, 0);
                }
 
index 4f655822100b5bdbb394c5ab101909127061b2b6..4953774f2cc7b8f02ddce060676620e112ac1225 100644 (file)
@@ -31,7 +31,7 @@
 
 /**
  * @file Sound.hh
- * Image-loading and OpenGL texture loading.
+ * Load and play sounds, current supports ogg vorbis.
  */
 
 #include <boost/shared_ptr.hpp>
This page took 0.027687 seconds and 4 git commands to generate.