]> Dogcows Code - chaz/yoink/commitdiff
moving from SDL_sound to libvorbisfile
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Wed, 23 Sep 2009 07:06:44 +0000 (01:06 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Wed, 23 Sep 2009 07:06:44 +0000 (01:06 -0600)
configure.ac
doc/yoink.6.in
extra/yoink.ebuild
extra/yoink.spec.in
src/Character.cc
src/Moof/Engine.cc
src/Moof/Sound.cc
src/YoinkApp.cc

index a14508d30e49c59230659740f66be1c03947048e..82ebaa0baa87f8eade714dd2afaf5ab86bce618e 100644 (file)
@@ -6,7 +6,7 @@
 
 AC_PREREQ([2.60])
 
-AC_INIT([Yoink], [0.1], [chaz@dogcows.com], [yoink])
+AC_INIT([Yoink], [0.1], [onefriedrice@brokenzipper.com], [yoink])
 
 AC_CANONICAL_TARGET
 
@@ -194,8 +194,8 @@ AC_CHECK_HEADERS([AL/al.h AL/alut.h],,
 AC_CHECK_HEADERS([SDL/SDL_image.h],,
                                 [missing="$missing SDL_image"])
 
-AC_CHECK_HEADERS([SDL/SDL_sound.h],,
-                                [missing="$missing SDL_sound"])
+AC_CHECK_HEADERS([vorbis/codec.h vorbis/vorbisfile.h],,
+                                [missing="$missing libvorbis"])
 
 if test "x$missing" != x
 then
@@ -212,31 +212,31 @@ fi
 # Checks for libraries.
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-AC_SEARCH_LIBS([IMG_Load], [SDL_image],,
-                          [missing="$missing SDL_image"])
-
-AC_SEARCH_LIBS([Sound_Init], [SDL_sound],,
-                          [missing="$missing SDL_sound"])
-
 if test x$WIN32 == xyes
 then
 # autoconf library search macro doesn't find opengl32 on windows because it uses
 # different name hashing, but it links fine; assume it's there
        LIBS="$LIBS -lglu32 -lopengl32"
 else
-       AC_SEARCH_LIBS([gluPerspective], [GLU MesaGLU],,
+       AC_SEARCH_LIBS([gluDisk], [GLU MesaGLU],,
                                   [missing="$missing GLU"])
 
-       AC_SEARCH_LIBS([glBegin], [GL MesaGL],,
+       AC_SEARCH_LIBS([glEnable], [GL MesaGL],,
                                   [missing="$missing OpenGL"])
 fi
 
-AC_SEARCH_LIBS([alGenBuffers], [openal openal32],,
+AC_SEARCH_LIBS([alEnable], [openal openal32],,
                           [missing="$missing OpenAL"])
 
 AC_SEARCH_LIBS([alutInit], [alut],,
                           [missing="$missing ALUT"])
 
+AC_SEARCH_LIBS([IMG_Load], [SDL_image],,
+                          [missing="$missing SDL_image"])
+
+AC_SEARCH_LIBS([ov_open], [vorbisfile],,
+                          [missing="$missing libvorbis"])
+
 AC_SEARCH_LIBS([clock_gettime], [rt],
                           [AC_DEFINE([HAVE_CLOCK_GETTIME], 1,
                                                  [Define to 1 if you have the 'clock_gettime' function.])])
index 03274d04549d112eb7285c07e0bb3db4d0424983..99c48fad90b93224c8df4139aae0fe8a15f6ae6f 100644 (file)
@@ -28,7 +28,7 @@
 .SH NAME
 Yoink \- An alien-smashing action game.
 .SH SYNOPSIS
-.B yoink [-h|--help] [-v|--version] [OPTION=VALUE]...
+.B yoink [-h|--help] [OPTION=VALUE]...
 .br
 .SH DESCRIPTION
 .PP
@@ -43,9 +43,6 @@ action.  Basic arguments include:
 .TP
 .B -h, --help
 display this help and exit
-.TP
-.B -v, --version
-output version information and exit
 .br
 .SH TIPS
 .PP
@@ -105,9 +102,10 @@ temporary setting which you do not intend to retain.  Keep in mind that if you
 edit and save options in-game, any options you have passed as arguments during
 the invocation of the game will be saved to the
 .I $HOME/.yoinkrc
-configuration file.  You may have to go into that file and remove any options
-you didn't intend to set.  When passing options as arguments, you must use the
-fully qualified name of the option if it exists in a subgroup.  For example:
+configuration file.  If this is not what you intended, you may have to go into
+that file and remove any options you didn't intend to set.  When passing options
+as arguments, you must use the fully qualified name of the option if it exists
+in a subgroup.  For example:
 .PP
 .TP
 yoink video.fullscreen=true
index 0f903162617648c920c0dc6aaed6a9e2be6c2162..f4730c18b1a4fc6b73dd7cb43b8c3f5fbbf1e9da 100644 (file)
@@ -18,16 +18,14 @@ IUSE="debug profile"
 
 RDEPEND="media-libs/freealut
        media-libs/libsdl[opengl]
-       media-libs/sdl-image[png]
-       media-libs/sdl-sound[vorbis]
+       media-libs/libvorbis
        media-libs/openal
+       media-libs/sdl-image[png]
        virtual/opengl"
 DEPEND="${RDEPEND}
        dev-libs/boost
        dev-util/pkgconfig"
 
-RESTRICT="mirror"
-
 src_prepare() {
        sed -i \
                -e "s/-Werror//g" \
index 6c39987660e80e224f2c35d80c83281b4032ddab..ace7081e8a8efcf5a4b81caabf4cdc59c60b02e7 100644 (file)
@@ -9,13 +9,13 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
 BuildRequires: boost-devel
 BuildRequires: SDL-devel
 BuildRequires: SDL_image-devel
-BuildRequires: SDL_sound-devel
+BuildRequires: libvorbis-devel
 BuildRequires: mesa-libGL-devel
 BuildRequires: openal-devel
 BuildRequires: freealut-devel
 Requires: SDL
 Requires: SDL_image
-Requires: SDL_sound
+Requires: libvorbis
 Requires: openal
 Requires: freealut
 %description
index ac5f8bcb6693349b44679613279465f36fdd7546..3a9559f003776ed32a813afd365b9fa0dfec7fab 100644 (file)
@@ -61,8 +61,10 @@ void Character::update(Mf::Scalar t, Mf::Scalar dt)
        Mf::Scalar mag = x.length();
        Mf::Scalar d = 50.0;
 
-       current.force = -5 * (current.position - Mf::Vector2(500.0, 200.0))
-               - 2.0 * current.velocity;
+       current.force = Mf::Vector2(0.0, -2000.0);
+       //current.force += -15.0 * x - 1.5 * current.velocity;
+       current.force += -20.0 * (mag - d) * (x / mag) - 2.0 * current.velocity;
+       current.force += userForce;
        current.recalculate();
        std::cout << "force: " << current.momentum << std::endl;
 
@@ -85,7 +87,7 @@ void Character::handleEvent(const Mf::Event& event)
 {
        // really just for heroine...
        
-       Mf::Scalar force = 500.0;
+       Mf::Scalar force = 4000.0;
        
        Mf::Vector2 left = Mf::Vector2(-force, 0.0);
        Mf::Vector2 right = Mf::Vector2(force, 0.0);
index 51a3af0f5bfb6d75d71cdaed34cb7bdd9518c3ac..80a203e6989b368a86cb12c0790568fef0bc7b6c 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <SDL/SDL.h>
 #include "fastevents.h"
-#include <SDL/SDL_sound.h>
 #include <AL/alut.h>
 
 #include "Dispatcher.hh"
@@ -68,11 +67,6 @@ public:
                        logError("fast events error: %s", FE_GetError());
                        throw Exception(Exception::SDL_ERROR);
                }
-               if (Sound_Init() == 0)
-               {
-                       logError("sound initialization failed: %s", Sound_GetError());
-                       throw Exception(Exception::SDL_ERROR);
-               }
                alutInit(&argc, argv);
 
                Settings& settings = Settings::getInstance();
@@ -104,7 +98,6 @@ public:
                video.reset();
 
                alutExit();
-               Sound_Quit();
                FE_Quit();
                SDL_Quit();
        }
index 110dc4ba0416e03c268147097bd8e4c7f44821ee..43714fe04872a93e968c0e44d0c7724f78b2d966 100644 (file)
 
 *******************************************************************************/
 
+#include <cstdio>
 #include <string>
 #include <queue>
 #include <vector>
 
-#include <SDL/SDL.h>
-#include <SDL/SDL_sound.h>
 #include <AL/al.h>
+#include <vorbis/codec.h>
+#include <vorbis/vorbisfile.h>
 
 #include "Log.hh"
 #include "Mippleton.hh"
@@ -47,18 +48,10 @@ namespace Mf {
 struct Sound::Impl
 {
 
-       static ALenum getAudioFormat(const Sound_AudioInfo& audioInfo)
+       static ALenum getAudioFormat(const vorbis_info* audioInfo)
        {
-               if (audioInfo.format == AUDIO_U8 || audioInfo.format == AUDIO_S8)
-               {
-                       if (audioInfo.channels == 1) return AL_FORMAT_MONO8;
-                       else                         return AL_FORMAT_STEREO8;
-               }
-               else
-               {
-                       if (audioInfo.channels == 1) return AL_FORMAT_MONO16;
-                       else                         return AL_FORMAT_STEREO16;
-               }
+               if (audioInfo->channels == 1) return AL_FORMAT_MONO16;
+               else                                              return AL_FORMAT_STEREO16;
        }
        
        class Buffer;
@@ -66,14 +59,17 @@ struct Sound::Impl
        
        class Buffer : public Mippleton<Buffer>
        {
-               Sound_Sample*                   sound;
+               FILE*                                   soundFile;
+               OggVorbis_File                  oggStream;
+               ALenum                                  audioFormat;
+               ALsizei                                 audioFreq;
                std::vector<ALuint>             objects;
 
        public:
 
                Buffer(const std::string& name) :
                        Mippleton<Buffer>(name),
-                       sound(0)
+                       soundFile(0)
                {
                        openFile();
                }
@@ -86,38 +82,79 @@ struct Sound::Impl
                                objects.pop_back();
                        }
 
-                       if (sound) Sound_FreeSample(sound);
+                       if (soundFile)
+                       {
+                               ov_clear(&oggStream);
+                       }
                }
 
 
                void openFile()
                {
-                       if (sound) Sound_FreeSample(sound);
+                       if (soundFile)
+                       {
+                               ov_clear(&oggStream);
+                               soundFile = 0;
+                       }
 
-                       sound = Sound_NewSampleFromFile(Sound::getPath(getName()).c_str(),
-                                       0, BUFFER_SIZE);
+                       //soundFile = Sound_NewSampleFromFile(soundFile::getPath(getName()).c_str(),
+                                       //0, BUFFER_SIZE);
+                       soundFile = fopen(Sound::getPath(getName()).c_str(), "rb");
 
-                       if (!sound)
+                       if (!soundFile)
                        {
-                               logWarning("error while loading sound %s: %s",
-                                               getName().c_str(), Sound_GetError());
+                               logWarning("error while loading sound %s", getName().c_str());
                                throw Exception(Exception::FILE_NOT_FOUND);
                        }
 
-                       logDebug("buffer size: %d", sound->buffer_size);
-                       logDebug("   channels: %d", sound->actual.channels);
-                       logDebug("     format: %d", sound->actual.format);
-                       logDebug("  frequency: %d", sound->actual.rate);
+                       int result = ov_open(soundFile, &oggStream, NULL, 0);
+
+                       if (result < 0)
+                       {
+                               fclose(soundFile);
+                               soundFile = 0;
+
+                               logWarning("error while loading oggvorbis stream %s",
+                                               getName().c_str());
+                               throw Exception(Exception::BAD_AUDIO_FORMAT);
+                       }
+
+                       vorbis_info* vorbisInfo = ov_info(&oggStream, -1);
+                       audioFormat = getAudioFormat(vorbisInfo);
+                       audioFreq = vorbisInfo->rate;
+
+                       logDebug("    version: %d", vorbisInfo->version);
+                       logDebug("   channels: %d", vorbisInfo->channels);
+                       logDebug("  frequency: %d", vorbisInfo->rate);
                }
 
 
                void loadAll(ALuint source)
                {
-                       if (!sound) openFile();
-                       if (!sound) return;
+                       if (!soundFile) openFile();
+                       if (!soundFile) return;
+
+                       char data[BUFFER_SIZE];
+                       int size = 0;
 
-                       unsigned decoded = Sound_DecodeAll(sound);
-                       if (decoded == 0)
+                       //unsigned decoded = Sound_DecodeAll(soundFile);
+                       for (;;)
+                       {
+                               int section;
+                               int result = ov_read(&oggStream, data + size,
+                                               BUFFER_SIZE - size, 0, 2, 1, &section);
+
+                               if (result > 0)
+                               {
+                                       size += result;
+                               }
+                               else
+                               {
+                                       if (result < 0) logWarning("vorbis playback error");
+                                       break;
+                               }
+                       }
+                       if (size == 0)
                        {
                                logWarning("decoded no bytes from %s", getName().c_str());
                                //throw Exception(Exception::FILE_NOT_FOUND);
@@ -127,23 +164,22 @@ struct Sound::Impl
                        ALuint obj;
                        alGenBuffers(1, &obj);
 
-                       alBufferData(obj, getAudioFormat(sound->actual), sound->buffer,
-                                       sound->buffer_size, sound->actual.rate);
+                       alBufferData(obj, audioFormat, data, size, audioFreq);
 
                        objects.push_back(obj);
 
                        alSourcei(source, AL_BUFFER, obj);
 
-                       // don't need t his anymore
-                       Sound_FreeSample(sound);
-                       sound = 0;
+                       // don't need this anymore
+                       ov_clear(&oggStream);
+                       soundFile = 0;
                }
 
 
                void beginStream(ALuint source, int nBuffers = 4)
                {
-                       if (!sound) openFile();
-                       if (!sound) return;
+                       if (!soundFile) openFile();
+                       if (!soundFile) return;
 
                        ALuint objs[nBuffers];
                        alGenBuffers(nBuffers, objs);
@@ -172,20 +208,38 @@ struct Sound::Impl
                        // that buffer doesn't belong to us
                        if (it == objects.end()) return STREAM_WRONG;
 
-                       unsigned bytes = Sound_Decode(sound);
+                       char data[BUFFER_SIZE];
+                       int size = 0;
+
+                       //unsigned bytes = Sound_Decode(soundFile);
+                       while (size < BUFFER_SIZE)
+                       {
+                               int section;
+                               int result = ov_read(&oggStream, data + size,
+                                               BUFFER_SIZE - size, 0, 2, 1, &section);
+
+                               if (result > 0)
+                               {
+                                       size += result;
+                               }
+                               else
+                               {
+                                       if (result < 0) logWarning("vorbis playback error");
+                                       break;
+                               }
+                       }
 
-                       if (bytes == 0) return STREAM_EOF;
+                       if (size == 0) return STREAM_EOF;
 
-                       alBufferData(buffer, getAudioFormat(sound->actual), sound->buffer,
-                                       bytes, sound->actual.rate);
+                       alBufferData(buffer, audioFormat, data, size, audioFreq);
 
                        return STREAM_OK;
                }
 
                inline void rewind()
                {
-                       if (!sound) openFile();
-                       else Sound_Rewind(sound);
+                       if (!soundFile) openFile();
+                       else ov_raw_seek(&oggStream, 0);
                }
 
 
index 597a74ff79d24b11a7bf54d7dc91e5dfc6758ed1..77f5c7318d0a9b8f7676e305f020c4d492ae2b7a 100644 (file)
@@ -102,7 +102,7 @@ static std::string iconFile()
 
 YoinkApp::YoinkApp(int argc, char* argv[]) :
        Mf::Engine(argc, argv, configFiles(), PACKAGE_STRING, iconFile()),
-       music("BeatTheCube"),
+       music("NightFusionIntro"),
        punchSound("RobotPunch")
 {
        Mf::dispatcher::addHandler("video.context_recreated",
@@ -174,7 +174,7 @@ void YoinkApp::contextRecreated(const Mf::Notification* note)
 
 void YoinkApp::update(Mf::Scalar t, Mf::Scalar dt)
 {
-       dt *= 0.7;
+       //dt *= 0.7;
 
        music.update(t, dt);
        fadeIn.update(dt);
This page took 0.044381 seconds and 4 git commands to generate.