From 5250c138b1a692e4e893a8f424d2856e519fd652 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Wed, 23 Sep 2009 01:06:44 -0600 Subject: [PATCH] moving from SDL_sound to libvorbisfile --- configure.ac | 24 ++++---- doc/yoink.6.in | 12 ++-- extra/yoink.ebuild | 6 +- extra/yoink.spec.in | 4 +- src/Character.cc | 8 ++- src/Moof/Engine.cc | 7 --- src/Moof/Sound.cc | 140 ++++++++++++++++++++++++++++++-------------- src/YoinkApp.cc | 4 +- 8 files changed, 125 insertions(+), 80 deletions(-) diff --git a/configure.ac b/configure.ac index a14508d..82ebaa0 100644 --- a/configure.ac +++ b/configure.ac @@ -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.])]) diff --git a/doc/yoink.6.in b/doc/yoink.6.in index 03274d0..99c48fa 100644 --- a/doc/yoink.6.in +++ b/doc/yoink.6.in @@ -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 diff --git a/extra/yoink.ebuild b/extra/yoink.ebuild index 0f90316..f4730c1 100644 --- a/extra/yoink.ebuild +++ b/extra/yoink.ebuild @@ -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" \ diff --git a/extra/yoink.spec.in b/extra/yoink.spec.in index 6c39987..ace7081 100644 --- a/extra/yoink.spec.in +++ b/extra/yoink.spec.in @@ -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 diff --git a/src/Character.cc b/src/Character.cc index ac5f8bc..3a9559f 100644 --- a/src/Character.cc +++ b/src/Character.cc @@ -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); diff --git a/src/Moof/Engine.cc b/src/Moof/Engine.cc index 51a3af0..80a203e 100644 --- a/src/Moof/Engine.cc +++ b/src/Moof/Engine.cc @@ -31,7 +31,6 @@ #include #include "fastevents.h" -#include #include #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(); } diff --git a/src/Moof/Sound.cc b/src/Moof/Sound.cc index 110dc4b..43714fe 100644 --- a/src/Moof/Sound.cc +++ b/src/Moof/Sound.cc @@ -26,13 +26,14 @@ *******************************************************************************/ +#include #include #include #include -#include -#include #include +#include +#include #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 { - Sound_Sample* sound; + FILE* soundFile; + OggVorbis_File oggStream; + ALenum audioFormat; + ALsizei audioFreq; std::vector objects; public: Buffer(const std::string& name) : Mippleton(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, §ion); + + 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, §ion); + + 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); } diff --git a/src/YoinkApp.cc b/src/YoinkApp.cc index 597a74f..77f5c73 100644 --- a/src/YoinkApp.cc +++ b/src/YoinkApp.cc @@ -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); -- 2.45.2