[Orxonox-commit 3316] r8005 - in code/branches/usability: . src/orxonox src/orxonox/sound src/orxonox/weaponsystem
rgrieder at orxonox.net
rgrieder at orxonox.net
Tue Mar 1 05:10:29 CET 2011
Author: rgrieder
Date: 2011-03-01 05:10:29 +0100 (Tue, 01 Mar 2011)
New Revision: 8005
Added:
code/branches/usability/src/orxonox/sound/SoundPrereqs.h
Modified:
code/branches/usability/
code/branches/usability/src/orxonox/MoodManager.h
code/branches/usability/src/orxonox/sound/AmbientSound.cc
code/branches/usability/src/orxonox/sound/AmbientSound.h
code/branches/usability/src/orxonox/sound/BaseSound.cc
code/branches/usability/src/orxonox/sound/BaseSound.h
code/branches/usability/src/orxonox/sound/SoundBuffer.h
code/branches/usability/src/orxonox/sound/SoundManager.cc
code/branches/usability/src/orxonox/sound/SoundManager.h
code/branches/usability/src/orxonox/sound/SoundStreamer.cc
code/branches/usability/src/orxonox/sound/SoundStreamer.h
code/branches/usability/src/orxonox/sound/WorldSound.h
code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc
code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h
Log:
Merged sound5 into sound6 branch.
Property changes on: code/branches/usability
___________________________________________________________________
Modified: svn:mergeinfo
- /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7975-7977
/code/branches/lastmanstanding:7479-7644
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
/code/trunk:7952-7955
+ /code/branches/ai:6592-7033
/code/branches/buildsystem:1874-2276,2278-2400
/code/branches/buildsystem2:2506-2658
/code/branches/buildsystem3:2662-2708
/code/branches/ceguilua:1802-1808
/code/branches/chat:6527-6797
/code/branches/chat2:6836-6910
/code/branches/console:5941-6104
/code/branches/consolecommands2:6451-7178
/code/branches/consolecommands3:7178-7283
/code/branches/core3:1572-1739
/code/branches/core4:3221-3224,3227,3234-3238,3242,3244-3250,3252-3254,3256,3259-3261,3264-3265,3268-3275,3277-3278,3280,3284-3285,3287,3289-3294,3305,3309-3310
/code/branches/core5:5768-5928,6009
/code/branches/data_cleanup:7537-7686
/code/branches/doc:7290-7400
/code/branches/dynamicmatch:6584-7030
/code/branches/fps:6591-7072
/code/branches/gamestate:6430-6572,6621-6661
/code/branches/gamestates2:6594-6745
/code/branches/gametypes:2826-3031
/code/branches/gcc43:1580
/code/branches/gui:1635-1723,2795-2894
/code/branches/hudelements:6584-6941
/code/branches/ingamemenu:6000-6023
/code/branches/input:1629-1636
/code/branches/ipv6:7293-7458
/code/branches/kicklib:7975-7977
/code/branches/lastmanstanding:7479-7644
/code/branches/libraries:5612-5692
/code/branches/libraries2:5703-5737
/code/branches/lod:6586-6911
/code/branches/lodfinal:2372-2411
/code/branches/map:2801-3086,3089
/code/branches/masterserver:7502-7738
/code/branches/menu:5941-6146,6148,7536-7687
/code/branches/miniprojects:2754-2824
/code/branches/netp2:2835-2988
/code/branches/netp3:2988-3082
/code/branches/netp6:3214-3302
/code/branches/network:2356
/code/branches/network2:6434-6465
/code/branches/network3:7196-7344
/code/branches/network4:7497-7755
/code/branches/network5:7757-7781
/code/branches/network64:2210-2355
/code/branches/notifications:7314-7401
/code/branches/objecthierarchy:1911-2085,2100,2110-2169
/code/branches/objecthierarchy2:2171-2479
/code/branches/overlay:2117-2385
/code/branches/particles:2829-3085
/code/branches/particles2:6050-6106,6109
/code/branches/pch:3113-3194
/code/branches/physics:1912-2055,2107-2439
/code/branches/physics_merge:2436-2457
/code/branches/pickup2:5942-6405
/code/branches/pickup3:6418-6523
/code/branches/pickup4:6594-6710
/code/branches/pickups:1926-2086,2127,2827-2915
/code/branches/pickups2:2107-2497,2915-3071
/code/branches/png2:7262-7263
/code/branches/ppspickups1:6552-6708
/code/branches/ppspickups2:6527-6532,6554-6709
/code/branches/ppspickups3:6757-6997
/code/branches/ppspickups4:7003-7089
/code/branches/presentation:2369-2652,2654-2660,7736-7786
/code/branches/presentation2:6106-6416,7787-7800
/code/branches/presentation3:6913-7162
/code/branches/questsystem:1894-2088
/code/branches/questsystem2:2107-2259
/code/branches/questsystem5:2776-2905
/code/branches/releasetodo:7614-7647
/code/branches/resource:3327-3366
/code/branches/resource2:3372-5694
/code/branches/rocket:6523-6950
/code/branches/rocket2:6953-6970
/code/branches/script_trigger:1295-1953,1955
/code/branches/skybox2:6559-6989
/code/branches/sound:2829-3010
/code/branches/sound3:5941-6102
/code/branches/sound4:6435-6504
/code/branches/sound5:6505-7720
/code/branches/steering:5949-6091
/code/branches/weapon:1925-2094
/code/branches/weapon2:2107-2488
/code/branches/weapons:2897-3051
/code/branches/weaponsystem:2742-2890
/code/trunk:7952-7955
Modified: code/branches/usability/src/orxonox/MoodManager.h
===================================================================
--- code/branches/usability/src/orxonox/MoodManager.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/MoodManager.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -58,10 +58,13 @@
static std::string mood_s;
};
- /*
- @brief
- The MoodManager class serves to allow for different musical themes in the game.
- */
+ /**
+ * The MoodManager class enables the game to set different themes, i.e. audio themes, each
+ * with a set of different audio files. A theme (called mood) is set by the server and applies to
+ * all clients. Existing moods are currently hard-coded in function checkMoodValidity(). Each mood
+ * needs to have a folder with its name in "data_extern/audo/ambient/" containing sound files named like
+ * the ones in mood "default".
+ */
class _OrxonoxExport MoodManager : public Singleton<MoodManager>, public OrxonoxClass
{
friend class Singleton<MoodManager>;
Modified: code/branches/usability/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/AmbientSound.cc 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/AmbientSound.cc 2011-03-01 04:10:29 UTC (rev 8005)
@@ -22,7 +22,7 @@
* Author:
* Reto Grieder
* Co-authors:
- * ...
+ * Kevin Young
*
*/
@@ -32,16 +32,25 @@
#include "core/GameMode.h"
#include "core/Resource.h"
#include "SoundManager.h"
+#include "SoundStreamer.h"
+#include "util/Sleep.h"
+#include <AL/alut.h>
+
namespace orxonox
{
+ // vorbis callbacks
+ size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource);
+ int seekVorbis(void* datasource, ogg_int64_t offset, int whence);
+ long tellVorbis(void* datasource);
+
AmbientSound::AmbientSound()
: bPlayOnLoad_(false)
{
RegisterObject(AmbientSound);
// Ambient sounds always fade in
- this->setVolume(0);
+ //this->setVolume(0);
}
void AmbientSound::preDestroy()
@@ -50,6 +59,7 @@
{
// Smoothly fade out by keeping a SmartPtr
SoundManager::getInstance().unregisterAmbientSound(this);
+ this->soundstreamthread_.interrupt();
}
}
@@ -61,7 +71,7 @@
bool AmbientSound::stop()
{
- if (GameMode::playsSound())
+ if (GameMode::playsSound())
SoundManager::getInstance().unregisterAmbientSound(this);
return false; // sound source not (yet) destroyed - return false
}
@@ -91,7 +101,7 @@
const std::string& path = "ambient/" + MoodManager::getInstance().getMood() + '/' + this->ambientSource_;
shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(path);
if (fileInfo != NULL)
- this->setSource(path);
+ this->setStreamSource(path);
else
COUT(3) << "Sound: " << this->ambientSource_ << ": Not a valid name! Ambient sound will not change." << std::endl;
}
@@ -103,4 +113,142 @@
if (val)
this->play();
}
+
+ // hacky solution for file streaming
+ void AmbientSound::setStreamSource(const std::string& source)
+ {
+ if (!GameMode::playsSound())
+ {
+ this->source_ = source;
+ return;
+ }
+
+ if(!alIsSource(this->audioSource_))
+ this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
+
+ if (this->source_ == source)
+ {
+ return;
+ }
+
+ this->source_ = source;
+ // Don't load ""
+ if (source_.empty())
+ return;
+
+ if (this->soundstreamthread_.get_id() != boost::thread::id())
+ {
+ this->soundstreamthread_.interrupt(); // terminate an old thread if necessary
+ }
+
+ // queue some init buffers
+ COUT(4) << "Sound: Creating thread for " << source << std::endl;
+ // Get resource info
+ shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
+ if (fileInfo == NULL)
+ {
+ COUT(2) << "Sound: Warning: Sound file '" << source << "' not found" << std::endl;
+ return;
+ }
+ // Open data stream
+ DataStreamPtr dataStream = Resource::open(fileInfo);
+
+ alSourcei(this->audioSource_, AL_BUFFER, 0);
+
+ // Open file with custom streaming
+ ov_callbacks vorbisCallbacks;
+ vorbisCallbacks.read_func = &readVorbis;
+ vorbisCallbacks.seek_func = &seekVorbis;
+ vorbisCallbacks.tell_func = &tellVorbis;
+ vorbisCallbacks.close_func = NULL;
+
+ OggVorbis_File* vf = new OggVorbis_File();
+ int ret = ov_open_callbacks(dataStream.get(), vf, NULL, 0, vorbisCallbacks);
+ if (ret < 0)
+ {
+ COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
+ ov_clear(vf);
+ return;
+ }
+ vorbis_info* vorbisInfo;
+ vorbisInfo = ov_info(vf, -1);
+ ALenum format;
+ if (vorbisInfo->channels == 1)
+ format = AL_FORMAT_MONO16;
+ else
+ format = AL_FORMAT_STEREO16;
+
+ char inbuffer[4096];
+ ALuint initbuffers[10];
+ alGenBuffers(10, initbuffers);
+ if (ALint error = alGetError()) {
+ COUT(2) << "Sound: Streamer: Could not generate buffer:" << getALErrorString(error) << std::endl;
+ return;
+ }
+ int current_section;
+
+ for(int i = 0; i < 10; i++)
+ {
+ long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);
+ if (ret == 0)
+ {
+ break;
+ }
+ else if (ret < 0)
+ {
+ COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
+ ov_clear(vf);
+ return;
+ }
+
+ alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
+ if(ALint error = alGetError()) {
+ COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
+ break;
+ }
+ alSourceQueueBuffers(this->audioSource_, 1, &initbuffers[i]);
+ if (ALint error = alGetError()) {
+ COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+ }
+ }
+
+ this->soundstreamthread_ = boost::thread(SoundStreamer(), this->audioSource_, dataStream, vf, current_section);
+ if(this->soundstreamthread_ == boost::thread())
+ COUT(2) << "Sound: Failed to create thread." << std::endl;
+ //SoundStreamer streamer;
+ //streamer(this->audioSource_, dataStream);
+
+ alSource3f(this->audioSource_, AL_POSITION, 0, 0, 0);
+ alSource3f(this->audioSource_, AL_VELOCITY, 0, 0, 0);
+ alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
+ if (ALint error = alGetError())
+ COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
+ }
+
+ bool AmbientSound::doStop()
+ {
+ bool result = BaseSound::doStop();
+ this->soundstreamthread_.interrupt();
+ return result;
+ }
+
+ void AmbientSound::doPlay()
+ {
+ BaseSound::doPlay();
+
+ if(GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
+ {
+ if(!alIsSource(this->audioSource_))
+ {
+ this->audioSource_ = SoundManager::getInstance().getSoundSource(this);
+ if(!alIsSource(this->audioSource_))
+ return;
+ this->initialiseSource();
+ }
+
+ alSourcePlay(this->audioSource_);
+ if(int error = alGetError())
+ COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
+ }
+ }
}
Modified: code/branches/usability/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/branches/usability/src/orxonox/sound/AmbientSound.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/AmbientSound.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -21,25 +21,30 @@
*
* Author:
* Reto Grieder
+ *
+ * Co-authors:
* Kevin Young
- * Co-authors:
- * ...
*
*/
#ifndef _AmbientSound_H__
#define _AmbientSound_H__
-#include "OrxonoxPrereqs.h"
+#include <boost/thread.hpp>
+#include "sound/SoundPrereqs.h"
+
#include "BaseSound.h"
#include "MoodManager.h"
namespace orxonox
{
/**
- * The AmbientSound class is used to play background music. It can not be placed
- * directly in a level file, use WorldAmbientSound instead.
+ * The AmbientSound class implements the non-3D sound, i.e. sound files that are used for atmospheric
+ * highlighting.
+ * It interfaces with BaseSound and is controllable by MoodManager.
+ * Ambient sounds are always cross-faded. New sounds are registered and activated/deactivated as needed.
+ *
*/
class _OrxonoxExport AmbientSound : public BaseSound, public MoodListener
{
@@ -64,6 +69,9 @@
protected:
~AmbientSound() { }
+ bool doStop();
+ void doPlay();
+
private:
void preDestroy();
float getRealVolume();
@@ -75,6 +83,9 @@
std::string ambientSource_; //!< Analogous to source_, but mood independent
bool bPlayOnLoad_; //!< Play the sound immediately when loaded
+
+ boost::thread soundstreamthread_; // hacky solution for streaming
+ void setStreamSource(const std::string& source);
};
}
Modified: code/branches/usability/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/BaseSound.cc 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/BaseSound.cc 2011-03-01 04:10:29 UTC (rev 8005)
@@ -91,7 +91,7 @@
alSourcePlay(this->audioSource_);
if (int error = alGetError())
- COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
}
}
@@ -144,19 +144,19 @@
alSource3f(this->audioSource_, AL_VELOCITY, 0, 0, 0);
alSource3f(this->audioSource_, AL_DIRECTION, 0, 0, 0);
if (ALint error = alGetError())
- COUT(2) << "Sound Warning: Setting source parameters to 0 failed: "
- << SoundManager::getALErrorString(error) << std::endl;
- assert(this->soundBuffer_ != NULL);
- alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
+ COUT(2) << "Sound: Warning: Setting source parameters to 0 failed: " << getALErrorString(error) << std::endl;
+ if(this->soundBuffer_ != NULL) {
+ alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
+ }
if (ALuint error = alGetError())
- COUT(1) << "Sound Error: Could not set buffer \"" << this->source_ << "\": " << SoundManager::getALErrorString(error) << std::endl;
+ COUT(1) << "Sound: Error: Could not set buffer \"" << this->source_ << "\": " << getALErrorString(error) << std::endl;
}
void BaseSound::setVolume(float vol)
{
this->volume_ = clamp(vol, 0.0f, 1.0f);
if (this->volume_ != vol)
- COUT(2) << "Sound warning: volume out of range, clamping value." << std::endl;
+ COUT(2) << "Sound: Warning: volume out of range, clamping value." << std::endl;
this->updateVolume();
}
@@ -167,8 +167,7 @@
float volume = this->volume_ * this->getRealVolume();
alSourcef(this->audioSource_, AL_GAIN, volume);
if (int error = alGetError())
- COUT(2) << "Sound: Error setting volume to " << volume
- << ": " << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Error setting volume to " << volume << ": " << getALErrorString(error) << std::endl;
}
}
@@ -183,7 +182,7 @@
{
if (pitch > 2 || pitch < 0.5f)
{
- COUT(2) << "Sound warning: pitch out of range, cropping value." << std::endl;
+ COUT(2) << "Sound: Warning: pitch out of range, cropping value." << std::endl;
pitch = pitch > 2.0f ? 2.0f : pitch;
pitch = pitch < 0.5f ? 0.5f : pitch;
}
@@ -192,7 +191,7 @@
{
alSourcef(this->audioSource_, AL_PITCH, pitch);
if (int error = alGetError())
- COUT(2) << "Sound: Error setting pitch: " << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Error setting pitch: " << getALErrorString(error) << std::endl;
}
}
@@ -237,7 +236,7 @@
alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
if (ALuint error = alGetError())
{
- COUT(1) << "Sound Error: Could not set buffer \"" << source << "\": " << SoundManager::getALErrorString(error) << std::endl;
+ COUT(1) << "Sound: Error: Could not set buffer \"" << source << "\": " << getALErrorString(error) << std::endl;
return;
}
@@ -245,7 +244,7 @@
assert(this->isPlaying() || this->isPaused());
alSourcePlay(this->audioSource_);
if (int error = alGetError())
- COUT(2) << "Sound: Error playing sound: " << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Error playing sound: " << getALErrorString(error) << std::endl;
if (this->isPaused())
alSourcePause(this->audioSource_);
}
Modified: code/branches/usability/src/orxonox/sound/BaseSound.h
===================================================================
--- code/branches/usability/src/orxonox/sound/BaseSound.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/BaseSound.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -29,7 +29,7 @@
#ifndef _BaseSound_H__
#define _BaseSound_H__
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
#include <string>
#include <boost/shared_ptr.hpp>
@@ -84,9 +84,9 @@
virtual ~BaseSound();
- void doPlay();
- bool doStop(); // returns true if the sound source was destroyed
- void doPause();
+ virtual void doPlay();
+ virtual bool doStop(); // returns true if the sound source was destroyed
+ virtual void doPause();
// network callbacks
inline void pitchChanged()
Modified: code/branches/usability/src/orxonox/sound/SoundBuffer.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundBuffer.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/SoundBuffer.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -29,7 +29,7 @@
#ifndef _SoundBuffer_H__
#define _SoundBuffer_H__
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
#include <list>
#include <boost/shared_ptr.hpp>
Modified: code/branches/usability/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundManager.cc 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/SoundManager.cc 2011-03-01 04:10:29 UTC (rev 8005)
@@ -21,10 +21,10 @@
*
* Author:
* Erwin 'vaiursch' Herrsche
+ *
+ * Co-authors:
* Kevin Young
* Reto Grieder
- * Co-authors:
- * ...
*
*/
@@ -51,7 +51,8 @@
{
ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
- std::string SoundManager::getALErrorString(ALenum code)
+ // From SoundPrereqs.h
+ std::string getALErrorString(ALenum code)
{
switch (code)
{
@@ -79,7 +80,7 @@
ThrowException(InitialisationAborted, "Sound: Not loading at all");
if (!alutInitWithoutContext(NULL, NULL))
- ThrowException(InitialisationFailed, "Sound Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
+ ThrowException(InitialisationFailed, "Sound: Error: ALUT initialisation failed: " << alutGetErrorString(alutGetError()));
Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
/*
@@ -111,17 +112,18 @@
#ifdef ORXONOX_PLATFORM_WINDOWS
COUT(1) << "Sound: Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
#endif
- ThrowException(InitialisationFailed, "Sound Error: Could not open sound device.");
+ ThrowException(InitialisationFailed, "Sound: Error: Could not open sound device.");
}
Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
// Create sound context and make it the currently used one
- this->context_ = alcCreateContext(this->device_, NULL);
+ const ALint contattr[] = {ALC_SYNC, 1, 0};
+ this->context_ = alcCreateContext(this->device_, contattr);
if (this->context_ == NULL)
- ThrowException(InitialisationFailed, "Sound Error: Could not create ALC context");
+ ThrowException(InitialisationFailed, "Sound: Error: Could not create ALC context");
Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
if (!alcMakeContextCurrent(this->context_))
- ThrowException(InitialisationFailed, "Sound Error: Could not use ALC context");
+ ThrowException(InitialisationFailed, "Sound: Error: Could not use ALC context");
GameMode::setPlaysSound(true);
Loki::ScopeGuard resetPlaysSoundGuard = Loki::MakeGuard(&GameMode::setPlaysSound, false);
@@ -134,7 +136,7 @@
if (const char* types = alutGetMIMETypes(ALUT_LOADER_BUFFER))
COUT(4) << "Sound: --- Supported MIME Types: " << types << std::endl;
else
- COUT(2) << "Sound Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
+ COUT(2) << "Sound: Warning: MIME Type retrieval failed: " << alutGetErrorString(alutGetError()) << std::endl;
this->mute_[SoundType::All] = 1.0f;
this->mute_[SoundType::Music] = 1.0f;
@@ -148,7 +150,7 @@
if (!alGetError() && alIsSource(source))
this->availableSoundSources_.push_back(source);
else
- ThrowException(InitialisationFailed, "Sound Error: Could not create even a single source");
+ ThrowException(InitialisationFailed, "Sound: Error: Could not create even a single source");
// Create a few initial sources
this->createSoundSources(this->minSources_ - 1);
@@ -170,14 +172,14 @@
// If there are still used buffers around, well, that's just very bad...
if (this->soundBuffers_.size() != this->effectsPool_.size())
- COUT(1) << "Sound Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
+ COUT(1) << "Sound: Error: Some sound buffers are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
// Empty buffer pool and buffer list
this->effectsPool_.clear();
this->soundBuffers_.clear();
// There should not be any sources in use anymore
if (!this->usedSoundSources_.empty())
- COUT(1) << "Sound Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
+ COUT(1) << "Sound: Error: Some sound sources are still in use but OpenAL is about to shut down. Fix this!" << std::endl;
while (!this->availableSoundSources_.empty())
{
alDeleteSources(1, &this->availableSoundSources_.back());
@@ -188,23 +190,23 @@
// Relieve context to destroy it
if (!alcMakeContextCurrent(NULL))
- COUT(1) << "Sound Error: Could not unset ALC context" << std::endl;
+ COUT(1) << "Sound: Error: Could not unset ALC context" << std::endl;
alcDestroyContext(this->context_);
if (ALCenum error = alcGetError(this->device_))
{
if (error == AL_INVALID_OPERATION)
- COUT(1) << "Sound Error: Could not destroy ALC context because it is the current one" << std::endl;
+ COUT(1) << "Sound: Error: Could not destroy ALC context because it is the current one" << std::endl;
else
- COUT(1) << "Sound Error: Could not destroy ALC context because it is invalid" << std::endl;
+ COUT(1) << "Sound: Error: Could not destroy ALC context because it is invalid" << std::endl;
}
#ifdef AL_VERSION_1_1
if (!alcCloseDevice(this->device_))
- COUT(1) << "Sound Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
+ COUT(1) << "Sound: Error: Could not destroy ALC device. This might be because there are still buffers in use!" << std::endl;
#else
alcCloseDevice(this->device_);
#endif
if (!alutExit())
- COUT(1) << "Sound Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
+ COUT(1) << "Sound: Error: Closing ALUT failed: " << alutGetErrorString(alutGetError()) << std::endl;
}
void SoundManager::setConfigValues()
@@ -250,7 +252,7 @@
{
if (crossFadeStep_ <= 0.0 || crossFadeStep_ >= 1.0 )
{
- COUT(2) << "Sound warning: fade step out of range, ignoring change." << std::endl;
+ COUT(2) << "Sound: Warning: fade step out of range, ignoring change." << std::endl;
ResetConfigValue(crossFadeStep_);
}
}
@@ -259,7 +261,7 @@
{
float clampedVolume = clamp(this->volume_[type], 0.0f, 1.0f);
if (clampedVolume != this->volume_[type])
- COUT(2) << "Sound warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
+ COUT(2) << "Sound: Warning: Volume setting (" << type << ") out of range, clamping." << std::endl;
this->updateVolume(type);
}
@@ -351,7 +353,7 @@
{
if (it->first == newAmbient)
{
- COUT(2) << "Sound warning: Will not play an AmbientSound twice." << std::endl;
+ COUT(2) << "Sound: Warning: Will not play an AmbientSound twice." << std::endl;
return;
}
}
@@ -619,7 +621,7 @@
{
alDeleteSources(1, &this->availableSoundSources_.back());
if (alGetError())
- COUT(1) << "Sound Error: Failed to delete a source --> lost forever" << std::endl;
+ COUT(1) << "Sound: Error: Failed to delete a source --> lost forever" << std::endl;
this->availableSoundSources_.pop_back();
}
}
Modified: code/branches/usability/src/orxonox/sound/SoundManager.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundManager.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/SoundManager.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -21,16 +21,16 @@
*
* Author:
* Erwin 'vaiursch' Herrsche
+ *
+ * Co-authors:
* Kevin Young
* Reto Grieder
- * Co-authors:
- * ...
*/
#ifndef _SoundManager_H__
#define _SoundManager_H__
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
#include <list>
#include <map>
@@ -98,8 +98,6 @@
ALuint getSoundSource(BaseSound* object);
void releaseSoundSource(ALuint source);
- static std::string getALErrorString(ALenum error);
-
private:
void processCrossFading(float dt);
void fadeIn(const SmartPtr<AmbientSound>& sound);
Copied: code/branches/usability/src/orxonox/sound/SoundPrereqs.h (from rev 7720, code/branches/sound5/src/orxonox/sound/SoundPrereqs.h)
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundPrereqs.h (rev 0)
+++ code/branches/usability/src/orxonox/sound/SoundPrereqs.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -0,0 +1,70 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ at file
+ at brief
+ Enums, constants, functions and forward declarations for the sound files.
+*/
+
+#ifndef _SoundPrereqs_H__
+#define _SoundPrereqs_H__
+
+#include "OrxonoxPrereqs.h"
+
+//-----------------------------------------------------------------------
+// Forward declarations
+//-----------------------------------------------------------------------
+
+namespace orxonox
+{
+ class AmbientSound;
+ class BaseSound;
+ class SoundBuffer;
+ class SoundManager;
+ class SoundStreamer;
+ class WorldSound;
+}
+
+typedef struct ALCcontext_struct ALCcontext;
+typedef struct ALCdevice_struct ALCdevice;
+typedef unsigned int ALuint;
+typedef int ALint;
+typedef int ALenum;
+
+//-----------------------------------------------------------------------
+// Helper functions
+//-----------------------------------------------------------------------
+
+namespace orxonox
+{
+ //! Returns an error string for an AL error code
+ _OrxonoxExport std::string getALErrorString(ALenum error);
+}
+
+#endif /* _SoundPrereqs_H__ */
Modified: code/branches/usability/src/orxonox/sound/SoundStreamer.cc
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundStreamer.cc 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/SoundStreamer.cc 2011-03-01 04:10:29 UTC (rev 8005)
@@ -26,9 +26,12 @@
*/
#include "SoundStreamer.h"
-#include <al.h>
+#include <boost/thread.hpp>
+#include <AL/al.h>
+#include <AL/alc.h>
#include <vorbis/vorbisfile.h>
#include "SoundManager.h"
+#include "util/Sleep.h"
namespace orxonox
{
@@ -37,91 +40,101 @@
int seekVorbis(void* datasource, ogg_int64_t offset, int whence);
long tellVorbis(void* datasource);
- void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream)
+ void orxonox::SoundStreamer::operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section)
{
- // Open file with custom streaming
- ov_callbacks vorbisCallbacks;
- vorbisCallbacks.read_func = &readVorbis;
- vorbisCallbacks.seek_func = &seekVorbis;
- vorbisCallbacks.tell_func = &tellVorbis;
- vorbisCallbacks.close_func = NULL;
-
- OggVorbis_File vf;
- int ret = ov_open_callbacks(dataStream.get(), &vf, NULL, 0, vorbisCallbacks);
- if (ret < 0)
- {
- COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
- ov_clear(&vf);
- return;
- }
+ char inbuffer[4096];
vorbis_info* vorbisInfo;
- vorbisInfo = ov_info(&vf, -1);
+ vorbisInfo = ov_info(vf, -1);
ALenum format;
if (vorbisInfo->channels == 1)
format = AL_FORMAT_MONO16;
else
format = AL_FORMAT_STEREO16;
- char inbuffer[256*1024];
- ALuint initbuffers[4];
- alGenBuffers(4, initbuffers);
- int current_section;
+ while(true) // Stream forever, control through thread control
+ {
- for(int i = 0; i < 4; i++)
- {
- long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);
- if (ret == 0)
+ int info;
+ alGetSourcei(audioSource, AL_SOURCE_STATE, &info);
+ if(info == AL_PLAYING)
+ COUT(4) << "Sound: " << dataStream->getName() << " is playing." << std::endl;
+ else
{
- return;
+ COUT(4) << "Sound: " << dataStream->getName() << " is not playing." << std::endl;
}
- else if (ret < 0)
+
+ if(alcGetCurrentContext() == NULL)
{
- COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
- ov_clear(&vf);
+ COUT(2) << "Sound: There is no context, terminating thread for " << dataStream->getName() << std::endl;
return;
}
- alBufferData(initbuffers[i], format, &inbuffer, ret, vorbisInfo->rate);
- }
- alSourceQueueBuffers(audioSource, 4, initbuffers);
-
- while(true) // Stream forever, control through thread control
- {
int processed;
alGetSourcei(audioSource, AL_BUFFERS_PROCESSED, &processed);
if (ALint error = alGetError())
- COUT(2) << "Sound Warning: Couldn't get number of processed buffers: "
- << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Warning: Couldn't get number of processed buffers: " << getALErrorString(error) << std::endl;
+ COUT(4) << "Sound: processed buffers: " << processed << std::endl;
+
if(processed > 0)
{
ALuint* buffers = new ALuint[processed];
alSourceUnqueueBuffers(audioSource, processed, buffers);
if (ALint error = alGetError())
- COUT(2) << "Sound Warning: Couldn't unqueue buffers: "
- << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
+
+ int queued;
+ alGetSourcei(audioSource, AL_BUFFERS_QUEUED, &queued);
+ if (ALint error = alGetError())
+ COUT(2) << "Sound: Warning: Couldn't get number of queued buffers: " << getALErrorString(error) << std::endl;
+ COUT(4) << "Sound: queued buffers: " << queued << std::endl;
for(int i = 0; i < processed; i++)
{
- long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);
+ long ret = ov_read(vf, inbuffer, sizeof(inbuffer), 0, 2, 1, ¤t_section);
if (ret == 0)
{
+ COUT(4) << "Sound: End of file " << dataStream->getName() << ", terminating thread" << std::endl;
return;
}
else if (ret < 0)
{
- COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
- ov_clear(&vf);
+ COUT(2) << "Sound: libvorbisfile: error reading the file " << dataStream->getName() << std::endl;
+ ov_clear(vf);
return;
}
alBufferData(buffers[i], format, &inbuffer, ret, vorbisInfo->rate);
+ if(ALint error = alGetError()) {
+ COUT(2) << "Sound: Could not fill buffer: " << getALErrorString(error) << std::endl;
+ break;
+ }
+ alSourceQueueBuffers(audioSource, 1, &buffers[i]);
+ if (ALint error = alGetError()) {
+ COUT(2) << "Sound: Warning: Couldn't queue buffers: " << getALErrorString(error) << std::endl;
+ }
}
+ }
+ else
+ {
+ msleep(10); // perhaps another value here is better
+ }
- alSourceQueueBuffers(audioSource, processed, buffers);
+ try {
+ boost::this_thread::interruption_point();
+ }
+ catch(boost::thread_interrupted) {
+ COUT(4) << "Sound: Catched interruption. Terminating thread for " << dataStream->getName() << std::endl;
+ ALuint* buffers = new ALuint[5];
+ alSourceUnqueueBuffers(audioSource, 5, buffers);
if (ALint error = alGetError())
- COUT(2) << "Sound Warning: Couldn't queue buffers: "
- << SoundManager::getALErrorString(error) << std::endl;
+ COUT(2) << "Sound: Warning: Couldn't unqueue buffers: " << getALErrorString(error) << std::endl;
+
+ alDeleteBuffers(5, buffers);
+ if (ALint error = alGetError())
+ COUT(2) << "Sound: Warning: Couldn't delete buffers: " << getALErrorString(error) << std::endl;
+
+ return;
}
}
}
Modified: code/branches/usability/src/orxonox/sound/SoundStreamer.h
===================================================================
--- code/branches/usability/src/orxonox/sound/SoundStreamer.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/SoundStreamer.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -28,9 +28,10 @@
#ifndef _SoundStreamer_H__
#define _SoundStreamer_H__
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
#include <string>
+#include <vorbis/vorbisfile.h>
#include <OgreDataStream.h>
#include "core/CorePrereqs.h"
@@ -39,7 +40,7 @@
class _OrxonoxExport SoundStreamer // class for stream threads
{
public:
- void operator()(ALuint audioSource, DataStreamPtr dataStream);
+ void operator()(ALuint audioSource, DataStreamPtr dataStream, OggVorbis_File* vf, int current_section);
};
}
Modified: code/branches/usability/src/orxonox/sound/WorldSound.h
===================================================================
--- code/branches/usability/src/orxonox/sound/WorldSound.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/sound/WorldSound.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -29,7 +29,7 @@
#ifndef _WorldSound_H__
#define _WorldSound_H__
-#include "OrxonoxPrereqs.h"
+#include "sound/SoundPrereqs.h"
#include "tools/interfaces/Tickable.h"
#include "sound/BaseSound.h"
Modified: code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc
===================================================================
--- code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/weaponsystem/WeaponMode.cc 2011-03-01 04:10:29 UTC (rev 8005)
@@ -23,7 +23,7 @@
* Martin Polak
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Kevin Young
*
*/
Modified: code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h
===================================================================
--- code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h 2011-03-01 04:09:27 UTC (rev 8004)
+++ code/branches/usability/src/orxonox/weaponsystem/WeaponMode.h 2011-03-01 04:10:29 UTC (rev 8005)
@@ -23,7 +23,7 @@
* Martin Polak
* Fabian 'x3n' Landau
* Co-authors:
- * ...
+ * Kevin Young
*
*/
@@ -40,6 +40,11 @@
namespace orxonox
{
+ /**
+ * The WeaponMode class enables the developer, amongst other things, to attach a sound file
+ * to the firing event of a weapon. The default firing sound is chosen by each weapon (ex.
+ * HsW01), hard-coded for now.
+ */
class _OrxonoxExport WeaponMode : public BaseObject
{
public:
More information about the Orxonox-commit
mailing list