예제 #1
0
void SoundDevice::update(float timeElapsed)
{
   std::vector<SoundChannel*>::iterator it = m_activeChannels.begin();
   while(it != m_activeChannels.end())
   {
      SoundChannel* channel = *it;
      if (channel->isPlaying() == false) 
      {
         ++it; 
         continue;
      }

      channel->update();
      if (channel->getActiveBuffersCount() < m_numBuffersUsed) 
      {
         channel->loadNextSample();
      }
      if (channel->getActiveBuffersCount() == 0)
      {
         channel->stop();
         it = m_activeChannels.erase(it);
         delete channel;
      }
      else
      {
         ++it;
      }
   }
}
    void test_playWith3D()
    {
        xtime xt;
        
        Ogre::ResourceManager::ResourceMapIterator it =
            SoundManager::getSingleton().getResourceIterator();

        while (it.hasMoreElements())
        {
            SoundResourcePtr soundres = it.getNext();
            SoundStream *sound = new SoundStream(soundres);
            SoundChannel *channel = new SoundChannel(sound, soundres->getName());
            if (channel)
            {
                channel->play();
                float angle = 0.0f;
                
                xtime_get(&xt, TIME_UTC);
                xt.sec++;
                thread::sleep(xt);
                while (channel->isPlaying()) {
                    xtime_get(&xt, TIME_UTC);
                    xt.nsec+=100000;
                    thread::sleep(xt);
                    Vector3 pos(1.0f*sinf(angle), 20.0f*cosf(angle), 0.0f);
                    channel->setPosition(pos);
                    angle += 0.005;
                    if (angle > 2 * M_PI)
                    {
                        angle = 0.0f;
                    }
                    FSOUND_Update();
                }
                
                delete channel;
            }            
        }        
    }