Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6842 in orxonox.OLD


Ignore:
Timestamp:
Jan 30, 2006, 1:39:57 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: ogg-player does not segfault, when no sources are availiable

Location:
trunk/src/lib/sound
Files:
3 edited

Legend:

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

    r6828 r6842  
    3535  this->setClassID(CL_SOUND_OGG_PLAYER, "OggPlayer");
    3636
     37  this->trackLoaded = false;
    3738  this->source = 0;
     39  this->buffers[0] = 0;
     40  this->buffers[1] = 0;
    3841
    3942  if (fileName != NULL)
    4043  {
    41     this->open(fileName);
    42     this->setName(fileName);
     44    if (this->open(fileName))
     45      this->setName(fileName);
    4346  }
    4447}
     
    4851 * @param fileName the file to open
    4952 */
    50 void OggPlayer::open(const char* fileName)
    51 {
     53bool OggPlayer::open(const char* fileName)
     54{
     55  if (this->buffers[0] == 0)
     56    alGenBuffers(2, this->buffers);
     57  SoundEngine::checkError("Allocating Buffers", __LINE__);
     58
     59  if (this->source == 0)
     60    SoundEngine::getInstance()->popALSource(this->source);
     61  if (this->source == 0)
     62  {
     63    this->trackLoaded = false;
     64    return false;
     65  }
     66  printf("OK\n");
     67
    5268  int result;
    5369
     
    6985  else
    7086    format = AL_FORMAT_STEREO16;
    71 
    72 
    73   alGenBuffers(2, buffers);
    74   check();
    75   SoundEngine::getInstance()->popALSource(this->source);
    76   check();
    7787
    7888  alSource3f(source, AL_POSITION,        0.0, 0.0, 0.0);
     
    8292  alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE      );
    8393  alSourcef (source, AL_GAIN,            SoundEngine::getInstance()->getMusicVolume());
     94
     95  this->trackLoaded = true;
     96  return true;
    8497}
    8598
     
    92105  empty();
    93106  SoundEngine::getInstance()->pushALSource(source);
     107  this->source = 0;
    94108  check();
    95   alDeleteBuffers(1, buffers);
     109  alDeleteBuffers(2, buffers);
     110  this->buffers[0] = 0;
     111  this->buffers[1] = 0;
    96112  check();
    97113
    98114  ov_clear(&oggStream);
     115  this->trackLoaded = false;
    99116}
    100117
     
    106123bool OggPlayer::playback()
    107124{
     125  if (!this->trackLoaded)
     126    return false;
     127
    108128  if(playing())
    109129    return true;
     
    127147bool OggPlayer::playing()
    128148{
     149  if (!this->trackLoaded)
     150    return false;
    129151  ALenum state;
    130152
     
    140162bool OggPlayer::update()
    141163{
     164  if (!this->trackLoaded)
     165    return false;
     166
    142167  int processed;
    143168  bool active = true;
     
    233258{
    234259  cout
    235       << "version         " << vorbisInfo->version         << "\n"
    236       << "channels        " << vorbisInfo->channels        << "\n"
    237       << "rate (hz)       " << vorbisInfo->rate            << "\n"
    238       << "bitrate upper   " << vorbisInfo->bitrate_upper   << "\n"
    239       << "bitrate nominal " << vorbisInfo->bitrate_nominal << "\n"
    240       << "bitrate lower   " << vorbisInfo->bitrate_lower   << "\n"
    241       << "bitrate window  " << vorbisInfo->bitrate_window  << "\n"
    242       << "\n"
    243       << "vendor " << vorbisComment->vendor << "\n";
     260  << "version         " << vorbisInfo->version         << "\n"
     261  << "channels        " << vorbisInfo->channels        << "\n"
     262  << "rate (hz)       " << vorbisInfo->rate            << "\n"
     263  << "bitrate upper   " << vorbisInfo->bitrate_upper   << "\n"
     264  << "bitrate nominal " << vorbisInfo->bitrate_nominal << "\n"
     265  << "bitrate lower   " << vorbisInfo->bitrate_lower   << "\n"
     266  << "bitrate window  " << vorbisInfo->bitrate_window  << "\n"
     267  << "\n"
     268  << "vendor " << vorbisComment->vendor << "\n";
    244269
    245270  for(int i = 0; i < vorbisComment->comments; i++)
  • trunk/src/lib/sound/ogg_player.h

    r6828 r6842  
    2929    OggPlayer(const char* fileName = NULL);
    3030
    31     void open(const char* fileName);
     31    bool open(const char* fileName);
    3232    void release();
    3333    void debug();
     
    5353    ALuint              source;               //!< The source we play back on
    5454    ALenum              format;               //!< The format we play back
     55    bool                trackLoaded;          //!< If a Track has been loaded.
    5556  };
    5657
  • trunk/src/lib/sound/sound_engine.cc

    r6840 r6842  
    337337
    338338    alGenSources(1, &source);
    339     printf("%d %d\n", i, source);
    340339    this->checkError("allocate Source", __LINE__);
     340    if (!alIsSource(source))
     341    {
     342      PRINTF(2)("not allocated Source\n");
     343      continue;
     344    }
    341345
    342346    alSourcef (source, AL_PITCH,    1.0      );
Note: See TracChangeset for help on using the changeset viewer.