[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" |
---|
[5917] | 20 | |
---|
[5386] | 21 | #include "alincl.h" |
---|
| 22 | #include "compiler.h" |
---|
[1853] | 23 | |
---|
[1856] | 24 | using namespace std; |
---|
[1853] | 25 | |
---|
[5386] | 26 | /** |
---|
| 27 | * creates a SoundSource at position sourceNode with the SoundBuffer buffer |
---|
| 28 | */ |
---|
| 29 | SoundSource::SoundSource(const PNode* sourceNode, const SoundBuffer* buffer) |
---|
| 30 | { |
---|
| 31 | this->setClassID(CL_SOUND_SOURCE, "SoundSource"); |
---|
[1856] | 32 | |
---|
[5386] | 33 | ALenum result; |
---|
| 34 | |
---|
| 35 | // adding the Source to the SourcesList of the SoundEngine |
---|
| 36 | SoundEngine::getInstance()->addSource(this); |
---|
| 37 | |
---|
| 38 | this->buffer = buffer; |
---|
| 39 | this->sourceNode = sourceNode; |
---|
| 40 | |
---|
| 41 | alGenSources(1, &this->sourceID); |
---|
| 42 | if ((result = alGetError()) != AL_NO_ERROR) |
---|
| 43 | SoundEngine::PrintALErrorString(result); |
---|
| 44 | if (this->buffer != NULL) |
---|
| 45 | alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID()); |
---|
| 46 | alSourcef (this->sourceID, AL_PITCH, 1.0 ); |
---|
| 47 | alSourcef (this->sourceID, AL_GAIN, SoundEngine::getInstance()->getEffectsVolume() ); |
---|
| 48 | alSourcei (sourceID, AL_LOOPING, AL_FALSE ); |
---|
| 49 | } |
---|
| 50 | |
---|
[3245] | 51 | /** |
---|
[5386] | 52 | * deletes a SoundSource |
---|
| 53 | */ |
---|
| 54 | SoundSource::~SoundSource() |
---|
[3365] | 55 | { |
---|
[5386] | 56 | //SoundEngine::getInstance()->removeSource(this); |
---|
| 57 | alDeleteSources(1, &this->sourceID); |
---|
| 58 | } |
---|
[4320] | 59 | |
---|
[5386] | 60 | /** |
---|
| 61 | * Plays back a SoundSource |
---|
| 62 | */ |
---|
| 63 | void SoundSource::play() |
---|
| 64 | { |
---|
| 65 | alSourcePlay(this->sourceID); |
---|
| 66 | } |
---|
[4320] | 67 | |
---|
[5386] | 68 | /** |
---|
| 69 | * Plays back buffer on this Source |
---|
| 70 | * @param buffer the buffer to play back on this Source |
---|
| 71 | */ |
---|
| 72 | void SoundSource::play(const SoundBuffer* buffer) |
---|
| 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()); |
---|
[3365] | 80 | } |
---|
[1853] | 81 | |
---|
[5386] | 82 | /** |
---|
| 83 | * Stops playback of a SoundSource |
---|
| 84 | */ |
---|
| 85 | void SoundSource::stop() |
---|
| 86 | { |
---|
| 87 | alSourceStop(this->sourceID); |
---|
| 88 | } |
---|
[1853] | 89 | |
---|
[3245] | 90 | /** |
---|
[5386] | 91 | * Pauses Playback of a SoundSource |
---|
| 92 | */ |
---|
| 93 | void SoundSource::pause() |
---|
[3543] | 94 | { |
---|
[5386] | 95 | alSourcePause(this->sourceID); |
---|
[3543] | 96 | } |
---|
[5386] | 97 | |
---|
| 98 | /** |
---|
| 99 | * Rewinds Playback of a SoundSource |
---|
| 100 | */ |
---|
| 101 | void SoundSource::rewind() |
---|
| 102 | { |
---|
| 103 | alSourceRewind(this->sourceID); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /** |
---|
| 107 | * sets the RolloffFactor of the Sound emitted from the SoundSource |
---|
| 108 | * @param rolloffFactor The Factor described |
---|
| 109 | |
---|
| 110 | this tells openAL how fast the Sounds decay outward from the Source |
---|
| 111 | */ |
---|
| 112 | void SoundSource::setRolloffFactor(ALfloat rolloffFactor) |
---|
| 113 | { |
---|
| 114 | alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor); |
---|
| 115 | } |
---|
| 116 | |
---|