Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more debug

File size: 2.9 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
21#include "alincl.h"
22#include "compiler.h"
23
24using namespace std;
25
26/**
27 *  creates a SoundSource at position sourceNode with the SoundBuffer buffer
28 */
29SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer)
30{
31  this->setClassID(CL_SOUND_SOURCE, "SoundSource");
32
33  ALenum result;
34
35  // adding the Source to the SourcesList of the SoundEngine
36  this->buffer = buffer;
37  this->sourceNode = sourceNode;
38
39  this->sourceID = 0;
40  this->bPlay = false;
41}
42
43/**
44 *  deletes a SoundSource
45 */
46SoundSource::~SoundSource()
47{
48  SoundEngine::getInstance()->pushALSource(this->sourceID);
49}
50
51/**
52 *  Plays back a SoundSource
53 */
54void SoundSource::play()
55{
56  if (this->sourceID == 0)
57    SoundEngine::getInstance()->popALSource(this->sourceID);
58  alSourcePlay(this->sourceID);
59  if (DEBUG >= 3)
60    SoundEngine::checkError("Play Source", __LINE__);
61  this->bPlay = true;
62}
63
64/**
65 * Plays back buffer on this Source
66 * @param buffer the buffer to play back on this Source
67 */
68void SoundSource::play(const SoundBuffer* buffer)
69{
70  if (unlikely(this->sourceID == 0))
71    SoundEngine::getInstance()->popALSource(this->sourceID);
72//  assert (this->sourceID != 0);
73
74  alSourceStop(this->sourceID);
75  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
76  alSourcePlay(this->sourceID);
77
78  if (unlikely(this->buffer != NULL))
79    alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
80  this->bPlay = true;
81
82  if (DEBUG >= 3)
83    SoundEngine::checkError("Play Source", __LINE__);
84}
85
86/**
87 *  Stops playback of a SoundSource
88 */
89void SoundSource::stop()
90{
91  this->bPlay = false;
92  alSourceStop(this->sourceID);
93  SoundEngine::getInstance()->pushALSource(this->sourceID);
94}
95
96/**
97 *  Pauses Playback of a SoundSource
98 */
99void SoundSource::pause()
100{
101  alSourcePause(this->sourceID);
102  if (DEBUG >= 3)
103    SoundEngine::checkError("Pause Source", __LINE__);
104}
105
106/**
107 *  Rewinds Playback of a SoundSource
108 */
109void SoundSource::rewind()
110{
111  alSourceRewind(this->sourceID);
112
113  if (DEBUG >= 3)
114    SoundEngine::checkError("Rewind Source", __LINE__);
115}
116
117/**
118 *  sets the RolloffFactor of the Sound emitted from the SoundSource
119 * @param rolloffFactor The Factor described
120
121   this tells openAL how fast the Sounds decay outward from the Source
122 */
123void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
124{
125  alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
126
127  if (DEBUG >= 3)
128    SoundEngine::checkError("Set Source Rolloff-factor", __LINE__);
129}
130
Note: See TracBrowser for help on using the repository browser.