Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/sound/sound_source.cc @ 5846

Last change on this file since 5846 was 5386, checked in by bensch, 19 years ago

orxonox/trunk: split open the soundengine into
sound_engine: the Handler
sound_source: the sources
sound_buffers: playback-buffers

File size: 2.6 KB
RevLine 
[4744]1/*
[1853]2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
[1855]10
11   ### File Specific:
[5386]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5386]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
[1853]17
[5386]18#include "sound_source.h"
19#include "sound_engine.h"
20#include "alincl.h"
21#include "compiler.h"
[1853]22
[1856]23using namespace std;
[1853]24
[5386]25/**
26 *  creates a SoundSource at position sourceNode with the SoundBuffer buffer
27 */
28SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
29{
30  this->setClassID(CL_SOUND_SOURCE, "SoundSource");
[1856]31
[5386]32  ALenum result;
33
34  // adding the Source to the SourcesList of the SoundEngine
35  SoundEngine::getInstance()->addSource(this);
36
37  this->buffer = buffer;
38  this->sourceNode = sourceNode;
39
40  alGenSources(1, &this->sourceID);
41  if ((result = alGetError()) != AL_NO_ERROR)
42    SoundEngine::PrintALErrorString(result);
43  if (this->buffer != NULL)
44    alSourcei (this->sourceID, AL_BUFFER,   this->buffer->getID());
45  alSourcef (this->sourceID, AL_PITCH,    1.0      );
46  alSourcef (this->sourceID, AL_GAIN,     SoundEngine::getInstance()->getEffectsVolume() );
47  alSourcei (sourceID, AL_LOOPING,  AL_FALSE     );
48}
49
[3245]50/**
[5386]51 *  deletes a SoundSource
52 */
53SoundSource::~SoundSource()
[3365]54{
[5386]55  //SoundEngine::getInstance()->removeSource(this);
56  alDeleteSources(1, &this->sourceID);
57}
[4320]58
[5386]59/**
60 *  Plays back a SoundSource
61 */
62void SoundSource::play()
63{
64  alSourcePlay(this->sourceID);
65}
[4320]66
[5386]67/**
68 * Plays back buffer on this Source
69 * @param buffer the buffer to play back on this Source
70 */
71void SoundSource::play(const SoundBuffer* buffer)
72{
73  alSourceStop(this->sourceID);
74  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
75  alSourcePlay(this->sourceID);
76
77  if (unlikely(this->buffer != NULL))
78    alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
[3365]79}
[1853]80
[5386]81/**
82 *  Stops playback of a SoundSource
83 */
84void SoundSource::stop()
85{
86  alSourceStop(this->sourceID);
87}
[1853]88
[3245]89/**
[5386]90 *  Pauses Playback of a SoundSource
91 */
92void SoundSource::pause()
[3543]93{
[5386]94  alSourcePause(this->sourceID);
[3543]95}
[5386]96
97/**
98 *  Rewinds Playback of a SoundSource
99 */
100void SoundSource::rewind()
101{
102  alSourceRewind(this->sourceID);
103}
104
105/**
106 *  sets the RolloffFactor of the Sound emitted from the SoundSource
107 * @param rolloffFactor The Factor described
108
109   this tells openAL how fast the Sounds decay outward from the Source
110 */
111void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
112{
113  alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
114}
115
Note: See TracBrowser for help on using the repository browser.