(speed 0.500000)
)
(spawnpoint (name "main") (x 96) (y 160))
- (ambient_sound (x 128) (y 800) (distance_factor 0.1)
+ (ambient_sound (x 128) (y 800) (distance_factor 1)
(distance_bias 200) (sample "waterfall"))
(infoblock (x 128) (y 800)
(message (_ "-Info
#include <sstream>
#include "audio/sound_manager.h"
+
#include "audio/musicref.h"
#include "moving_object.h"
#include "resources.h"
sounds.clear();
}
-void
-SoundManager::play_sound(const std::string& name)
-{
- if(!audio_device || !m_sound_enabled)
- return;
-
- Mix_Chunk* chunk = preload_sound(name);
- if(chunk == 0) {
- std::cerr << "Sound '" << name << "' not found.\n";
- return;
- }
- Mix_PlayChannel(-1, chunk, 0);
-}
-
int
SoundManager::play_sound(const std::string& name,int loops)
{
return Mix_PlayChannel(-1, chunk, loops);
}
+
void
SoundManager::play_sound(const std::string& sound, const MovingObject* object,
const Vector& pos)
Mix_SetPanning(chan, 24, 230);
}
+/*
+
+ok, i was stupid. We won't need this now.
+
// Register a sound effect function - basti_
void
// Adjust the Volume of a channel "on line". Needs sizeof(float) static data.
-#define __ATYPE__ signed short int
-
void
SoundManager::volume_adjust(int chan, void *stream, int len, void *udata) {
+
+ typedef signed short int atype;
+
((float *)udata)[1]=((float *)udata)[1]*0.95+
(((float *)udata)[0]-
((float *)udata)[1])*0.05; // decay towards [0] - declick
float vol=((float*)udata)[1];
for (int i=0;i<len/2;i++)
- ((__ATYPE__ *)stream)[i]=
- ((__ATYPE__)(((signed short int *)stream)[i]*vol));
+ ((atype *)stream)[i]=
+ ((atype)(((atype *)stream)[i]*vol));
// FIXME: This should be audio-type dependant - how to do this correctly?
chan=0; // -Werror sucks
}
-
+*/
MusicRef
SoundManager();
~SoundManager();
- /// Play sound.
- void play_sound(const std::string& sound);
-
- /// Play sound looping, return channel number - basti_
- int play_sound(const std::string& sound,int loops);
+ /// Play sound (maybe looping), return channel number (or -1 on error)
+ int play_sound(const std::string& sound,int loops=0);
/// Play sound relative to two Vectors.
void play_sound(const std::string& sound, const Vector& pos,
#include "lisp/lisp.h"
#include "sector.h"
-/***
- * Ambient Sound Source, beta version. Features:
- *
- * - "disc" like structure. Full volume up to some distance
- * (distance_bias) to the source, then fading proportional to
- * inverse square distance
- *
- * This is experimental, clicks sometimes and still leaks mem
- *
- * basti_
- */
-
AmbientSound::AmbientSound(const lisp::Lisp& lisp)
{
- // position=pos;
- lisp.get("x", position.x);
- lisp.get("y", position.y);
+ position.x=0;
+ position.y=0;
+ distance_factor=0;
+ distance_bias=0;
+ sample="";
+
+ if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) {
+ std::cerr << "No Position in ambient_sound" << std::endl;
+ }
lisp.get("distance_factor",distance_factor);
lisp.get("distance_bias" ,distance_bias );
lisp.get("sample" ,sample );
else
silence_distance = distance_factor*10e2;
- volume_ptr=NULL;
playing=0;
startPlaying();
}
AmbientSound::startPlaying()
{
playing=sound_manager->play_sound(sample,-1);
- volume_ptr=new float[2];
- volume_ptr[0]=0;
- volume_ptr[1]=0;
- sound_manager->register_effect(playing,&SoundManager::volume_adjust,
- NULL,(void *)volume_ptr);
+ Mix_Volume(playing,0);
+ currentvolume=targetvolume=1e-20;
}
void
if (distance<0)
distance=0;
- volume_ptr[0]=1/(1+distance*distance_factor); // inverse square of distance
+ targetvolume=1/(1+distance*distance_factor);
+ float rise=targetvolume/currentvolume;
+ currentvolume*=pow(rise,.05);
+ currentvolume += 1e-30;
+ // std::cout << currentvolume << " " << targetvolume << std::endl;
+ Mix_Volume(playing,(int)(currentvolume*MIX_MAX_VOLUME));
}
void
-AmbientSound::draw(DrawingContext &dc)
+AmbientSound::draw(DrawingContext &)
{
- return;
- sprite->draw(dc,position,1);
-
}
IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
+/**
+ * Ambient Sound Source, beta version. Features:
+ *
+ * - "disc" like structure. Full volume up to some distance
+ * (distance_bias) to the source, then fading proportional to
+ * inverse square distance
+ *
+ * This is experimental and clicks a little. It is not possible to
+ * get the clicks out without sample-granular volume adjustment.
+ *
+ * basti_
+ */
+
#ifndef __AMBIENT_SOUND_H__
#define __AMBIENT_SOUND_H__
#include "game_object.h"
#include "resources.h"
#include "player.h"
+#include "SDL_mixer.h"
class AmbientSound : public GameObject
{
virtual void startPlaying();
private:
Vector position;
- Sprite *sprite;
std::string sample;
int playing;
- float distance_factor;
- float distance_bias;
- float silence_distance;
+ float distance_factor; /// distance scaling
+ float distance_bias; /// 100% volume disc radius
+ float silence_distance; /// not implemented yet
+
+ float targetvolume; /// how loud we want to be
+ float currentvolume; /// how loud we are
- float * volume_ptr; // this will be used by the volume adjustment effect.
+ float * volume_ptr; /// this will be used by the volume adjustment effect.
};
#endif