Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/lib/sound/sound_source.cc @ 6133

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

branches/powerups: merged the trunk to branches/powerup
merged with commandsvn merge ../trunk/ powerups/ -r5848:HEAD
conflicts resolved in favor of the trunk

File size: 2.5 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"
[5955]20
[5386]21#include "alincl.h"
22#include "compiler.h"
[1853]23
[1856]24using namespace std;
[1853]25
[5386]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");
[1856]32
[5386]33  ALenum result;
34
35  // adding the Source to the SourcesList of the SoundEngine
36  this->buffer = buffer;
37  this->sourceNode = sourceNode;
38
[5955]39  this->sourceID = 0;
40  this->bPlay = false;
[5386]41}
42
[3245]43/**
[5386]44 *  deletes a SoundSource
45 */
46SoundSource::~SoundSource()
[3365]47{
[5955]48  SoundEngine::getInstance()->pushALSource(this->sourceID);
[5386]49}
[4320]50
[5386]51/**
52 *  Plays back a SoundSource
53 */
54void SoundSource::play()
55{
[5955]56  if (this->sourceID == 0)
57    SoundEngine::getInstance()->popALSource(this->sourceID);
[5386]58  alSourcePlay(this->sourceID);
[5955]59  this->bPlay = true;
[5386]60}
[4320]61
[5386]62/**
63 * Plays back buffer on this Source
64 * @param buffer the buffer to play back on this Source
65 */
66void SoundSource::play(const SoundBuffer* buffer)
67{
[5955]68  if (unlikely(this->sourceID == 0))
69    SoundEngine::getInstance()->popALSource(this->sourceID);
70
71  printf("%d\n",sourceID);
[5386]72  alSourceStop(this->sourceID);
73  alSourcei (this->sourceID, AL_BUFFER, buffer->getID());
74  alSourcePlay(this->sourceID);
75
76  if (unlikely(this->buffer != NULL))
77    alSourcei (this->sourceID, AL_BUFFER, this->buffer->getID());
[5955]78  this->bPlay = true;
[3365]79}
[1853]80
[5386]81/**
82 *  Stops playback of a SoundSource
83 */
84void SoundSource::stop()
85{
[5955]86  this->bPlay = false;
[5386]87  alSourceStop(this->sourceID);
[5955]88  SoundEngine::getInstance()->pushALSource(this->sourceID);
[5386]89}
[1853]90
[3245]91/**
[5386]92 *  Pauses Playback of a SoundSource
93 */
94void SoundSource::pause()
[3543]95{
[5386]96  alSourcePause(this->sourceID);
[3543]97}
[5386]98
99/**
100 *  Rewinds Playback of a SoundSource
101 */
102void SoundSource::rewind()
103{
104  alSourceRewind(this->sourceID);
105}
106
107/**
108 *  sets the RolloffFactor of the Sound emitted from the SoundSource
109 * @param rolloffFactor The Factor described
110
111   this tells openAL how fast the Sounds decay outward from the Source
112 */
113void SoundSource::setRolloffFactor(ALfloat rolloffFactor)
114{
115  alSourcef(this->sourceID, AL_ROLLOFF_FACTOR, rolloffFactor);
116}
117
Note: See TracBrowser for help on using the repository browser.