Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7317 in orxonox.OLD for trunk/src/lib/sound/sound_source.cc


Ignore:
Timestamp:
Apr 17, 2006, 2:25:27 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: retrieve Source is better now (more modular)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/sound/sound_source.cc

    r7299 r7317  
    3434  this->buffer = buffer;
    3535  this->sourceNode = sourceNode;
     36  this->resident = false;
    3637
    3738  this->sourceID = 0;
    3839  this->bPlay = false;
    3940}
     41
    4042
    4143/**
     
    5355  this->buffer = source.buffer;
    5456  this->sourceNode = source.sourceNode;
     57  this->resident = source.resident;
    5558
    5659  this->sourceID = 0;
     
    6366    this->bPlay = false;
    6467}
     68
    6569
    6670/**
     
    7478  this->buffer = source.buffer;
    7579  this->sourceNode = sourceNode;
     80  this->resident = source.resident;
    7681
    7782  if (source.bPlay)
     
    8186}
    8287
     88
    8389/**
    8490 * @brief compares two Sources with each other.
     
    94100}
    95101
     102
    96103/**
    97104 * @brief deletes a SoundSource
     
    100107{
    101108  this->stop();
    102 }
     109  if (this->sourceID != 0)
     110    SoundEngine::getInstance()->pushALSource(this->sourceID);
     111}
     112
    103113
    104114/**
     
    107117void SoundSource::play()
    108118{
    109   if (this->sourceID == 0)
    110     SoundEngine::getInstance()->popALSource(this->sourceID);
    111   alSourcePlay(this->sourceID);
    112   if (DEBUG >= 3)
    113     SoundEngine::checkError("Play Source", __LINE__);
    114   this->bPlay = true;
    115 }
    116 
    117 /**
    118  * Plays back buffer on this Source
     119  if (this->retrieveSource())
     120  {
     121    alSourcePlay(this->sourceID);
     122    if (DEBUG >= 3)
     123      SoundEngine::checkError("Play Source", __LINE__);
     124    this->bPlay = true;
     125  }
     126}
     127
     128
     129/**
     130 * @brief Plays back buffer on this Source
    119131 * @param buffer the buffer to play back on this Source
    120132 */
    121133void SoundSource::play(const SoundBuffer* buffer)
    122134{
    123   if (unlikely(this->sourceID == 0))
    124   {
    125     SoundEngine::getInstance()->popALSource(this->sourceID);
    126     if (sourceID == 0)
    127     {
    128       PRINTF(2)("No more Free source\n");
    129       return;
    130     }
    131   }
    132   //  assert (this->sourceID != 0);
     135  if (!this->retrieveSource())
     136  {
     137    PRINTF(2)("No more Free sources (You might consider raising the Source-Count).\n");
     138    return;
     139  }
    133140
    134141  alSourceStop(this->sourceID);
     
    143150    SoundEngine::checkError("Play Source", __LINE__);
    144151}
     152
    145153
    146154/**
     
    156164      SoundEngine::checkError("StopSource", __LINE__);
    157165    alSourcei(this->sourceID, AL_BUFFER, 0);
    158     SoundEngine::getInstance()->pushALSource(this->sourceID);
     166    if (!this->resident)
     167      SoundEngine::getInstance()->pushALSource(this->sourceID);
    159168    this->sourceID = 0;
    160169  }
    161170}
    162171
     172
    163173/**
    164174 * @brief Pauses Playback of a SoundSource
     
    171181}
    172182
     183
    173184/**
    174185 * @brief Rewinds Playback of a SoundSource
     
    181192    SoundEngine::checkError("Rewind Source", __LINE__);
    182193}
     194
    183195
    184196/**
     
    196208}
    197209
     210
     211/**
     212 * @brief sets the Positional this Source should be attached to.
     213 * @param sourceNode the Source this is attached to.
     214 * If sourceNode == NULL then the Source will be centered, and Audio will be played on all channels.
     215 */
     216void SoundSource::setSourceNode(const PNode* sourceNode)
     217{
     218  this->sourceNode = sourceNode;
     219}
     220
     221/**
     222 * @brief retrieve a Source.
     223 */
     224bool SoundSource::retrieveSource()
     225{
     226  if (this->sourceID != 0)
     227    return true;
     228  else
     229  {
     230    SoundEngine::getInstance()->popALSource(this->sourceID);
     231    if (this->sourceID != 0)
     232    {
     233      if (unlikely(this->sourceNode == NULL))
     234        resetSource(this->sourceID);
     235      return true;
     236    }
     237  }
     238  return false;
     239}
     240
     241
     242/**
     243 * @brief reset an alSource to its default Values.
     244 */
     245void SoundSource::resetSource(ALuint sourceID)
     246{
     247  alSource3f(sourceID, AL_POSITION,        0.0, 0.0, 0.0);
     248  alSource3f(sourceID, AL_VELOCITY,        0.0, 0.0, 0.0);
     249  alSource3f(sourceID, AL_DIRECTION,       0.0, 0.0, 0.0);
     250  alSourcef (sourceID, AL_ROLLOFF_FACTOR,  0.0          );
     251  alSourcei (sourceID, AL_SOURCE_RELATIVE, AL_TRUE      );
     252  alSourcef (sourceID, AL_GAIN,            SoundEngine::getInstance()->getEffectsVolume());
     253}
Note: See TracChangeset for help on using the changeset viewer.