Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/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
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_SOUND
17
18#include "sound_source.h"
19#include "sound_engine.h"
20#include "alincl.h"
21#include "compiler.h"
22
23using namespace std;
24
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");
31
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
50/**
51 *  deletes a SoundSource
52 */
53SoundSource::~SoundSource()
54{
55  //SoundEngine::getInstance()->removeSource(this);
56  alDeleteSources(1, &this->sourceID);
57}
58
59/**
60 *  Plays back a SoundSource
61 */
62void SoundSource::play()
63{
64  alSourcePlay(this->sourceID);
65}
66
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());
79}
80
81/**
82 *  Stops playback of a SoundSource
83 */
84void SoundSource::stop()
85{
86  alSourceStop(this->sourceID);
87}
88
89/**
90 *  Pauses Playback of a SoundSource
91 */
92void SoundSource::pause()
93{
94  alSourcePause(this->sourceID);
95}
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.