Пример #1
0
//---------------------------------------------------------------------
//  Init sound object
//---------------------------------------------------------------------
void  CSoundOBJ::Init(Tag t, SVector &pos)
{ CAudioManager *snd = globals->snd;
  sEnd    = 0;
  idn     = t;
  sPlay   = 0;
  gain    = 1;
  pitch   = 1;
  loop    = false;
  offset  = 0;
  for (int k=0; k<8; k++) sounds[k] = 0;
  alGenSources (1, &alSRC);
  snd->Check();
  snd->IncSRC();
  alSource3f(alSRC,AL_POSITION,pos.x,pos.y,pos.z);
  alSourcef (alSRC,AL_REFERENCE_DISTANCE,8.0f);
  snd->Check();
	for (int k=0; k<ENGINE_MAX_SOUND; k++) sounds[k] = 0;
}
Пример #2
0
//---------------------------------------------------------------------
//  Play a sound
//---------------------------------------------------------------------
void  CSoundSRC::Play(CSoundBUF *sbf)
{ CAudioManager *snd = globals->snd;
  //---Stop current sound if any ----------------
  alSourceStop(alSRC);
  alSourcei (alSRC, AL_BUFFER, 0);
  sPlay = sbf;
  //-- Play the current sound -------------------
  if (0 == sbf)     return;
  ALint buf = sPlay->GetBuffer();
  alSourcei(alSRC,AL_BUFFER,buf);
  alSourcei(alSRC,AL_LOOPING,loop);
  alSourcePlay(alSRC);
  snd->Check();
  return;
}
Пример #3
0
//---------------------------------------------------------------------
//  Loop current sound from offset position
//---------------------------------------------------------------------
void CSoundOBJ::PlayFromOffset(int No)
{ CAudioManager *snd = globals->snd;
  ALint state;
  alGetSourcei (alSRC, AL_SOURCE_STATE, &state);
  if ((sPlay == sounds[No]) && (state == AL_PLAYING)) return;
  sPlay     = sounds[No];
  if (0 == sPlay)       return;
  offset    = sPlay->GetOffset();
  alSourcei(alSRC,AL_BUFFER, sPlay->GetBuffer());
  alSourcei(alSRC,AL_SAMPLE_OFFSET,offset);
  alSourcei(alSRC,AL_LOOPING,false);
  alSourcef(alSRC,AL_PITCH,pitch);
  alSourcePlay(alSRC);
  snd->Check();
  return;
}
Пример #4
0
//=====================================================================================
//  JS: Sound Buffer:  An AL buffer dedicated to one sound
//  SoundBUF are managed by CAudioManager in a buffer cache.  Do not delete them.
//=====================================================================================
CSoundBUF::CSoundBUF(Tag t, char *nf)
{ CAudioManager *snd = globals->snd;
  user    = 1;
  idn     = t;
  offset  = 0;
  nfile   = 0;
  alSRC   = 0;
  TagToString(itag,t);
  ALuint  buf;
  alGenBuffers(1,&buf);
  alBUF   = buf;
  snd->Check();
  snd->LoadFile(this,nf);
  snd->IncBUF();
  gain    = 1;
  pMin    = 1;
  pMax    = 1;
}
Пример #5
0
//---------------------------------------------------------------------
//  Play the requested sound in the indicated mode
//  NOTE: Same sound request does nothing.  Use changeMode to 
//        change playing conditions
//  TODO:  Check if same sound is playing 
//---------------------------------------------------------------------
void  CSoundOBJ::Play(int No)
{ CAudioManager *snd = globals->snd;
  ALint state;
  alGetSourcei (alSRC, AL_SOURCE_STATE, &state);
  if ((sPlay == sounds[No]) && (state == AL_PLAYING)) return;
  //---Stop current sound if any ----------------
  StopSound();
  //-- Play the current sound -------------------
  sPlay = sounds[No];
  if (0 == sPlay)     return;
  offset    = sPlay->GetOffset();
  ALint buf = sPlay->GetBuffer();
  alSourcei(alSRC,AL_BUFFER,buf);
  alSourcei(alSRC,AL_LOOPING,false);
  alSourcef(alSRC,AL_GAIN,gain);
  alSourcef(alSRC,AL_PITCH,pitch);
  alSourcei(alSRC,AL_SAMPLE_OFFSET,offset);
  alSourcePlay(alSRC);
  snd->Check();
}