Esempio n. 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_loadPlayWithFade()
 {
     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();
             
             xtime_get(&xt, boost::TIME_UTC);
             xt.sec += 10;
             thread::sleep(xt);
             
             channel->stop();
             
             xtime_get(&xt, boost::TIME_UTC);
             xt.sec += 5;
             thread::sleep(xt);
         }            
     }
     
     CPPUNIT_ASSERT(true);
 }
Esempio n. 3
0
void SoundDevice::releaseAllChannels()
{
   while(m_activeChannels.size() > 0)
   {
      SoundChannel* channel = m_activeChannels.back();
      channel->stop();
      delete channel;
      m_activeChannels.pop_back();
   }
}
/**
 * @author JoSch
 * @date 03-11-2005
 */   
SoundObject::~SoundObject()
{
    if (mMovableObject)
    {
        SoundChannel *sc = dynamic_cast<SoundChannel*>(mMovableObject);
        if (sc)
        {
            sc->stop();
        }
        delete mMovableObject;
    }
}
void SoundPool::stop(int channelID)
{
    ALOGV("stop(%d)", channelID);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->stop();
    } else {
        channel = findNextChannel(channelID);
        if (channel)
            channel->clearNextEvent();
    }
}
int SoundPool::run()
{
    mRestartLock.lock();
    while (!mQuit) {
        mCondition.wait(mRestartLock);
        ALOGV("awake");
        if (mQuit) break;

        while (!mStop.empty()) {
            SoundChannel* channel;
            ALOGV("Getting channel from stop list");
            List<SoundChannel* >::iterator iter = mStop.begin();
            channel = *iter;
            mStop.erase(iter);
            mRestartLock.unlock();
            if (channel != 0) {
                Mutex::Autolock lock(&mLock);
                channel->stop();
            }
            mRestartLock.lock();
            if (mQuit) break;
        }

        while (!mRestart.empty()) {
            SoundChannel* channel;
            ALOGV("Getting channel from list");
            List<SoundChannel*>::iterator iter = mRestart.begin();
            channel = *iter;
            mRestart.erase(iter);
            mRestartLock.unlock();
            if (channel != 0) {
                Mutex::Autolock lock(&mLock);
                channel->nextEvent();
            }
            mRestartLock.lock();
            if (mQuit) break;
        }
    }

    mStop.clear();
    mRestart.clear();
    mCondition.signal();
    mRestartLock.unlock();
    ALOGV("goodbye");
    return 0;
}