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);
 }
Ejemplo n.º 2
0
SoundInstance * Sound::Play()
{
	if(TYPE_STREAMED == type && soundInstances.size())
	{
		return soundInstances.front();
	}

	SoundChannel * ch = SoundSystem::Instance()->FindChannel(priority);
	if(!ch)
	{
		return 0;
	}

	if(TYPE_STREAMED == type)
	{
		provider->Init();
		provider->Rewind();
		PrepareDynamicBuffers();
	}

	SoundInstance * inst = new SoundInstance();
	inst->buddyChannel = ch;
	AddSoundInstance(inst);
	ch->SetVolume(volume);
	ch->Play(this, looping);
	return inst;
}
Ejemplo n.º 3
0
SoundChannel * SoundSystem::FindChannel(int32 priority)
{
	Deque<SoundChannel*>::iterator it;
	Deque<SoundChannel*>::iterator itEnd = channelsPool.end();
	for(it = channelsPool.begin(); it != itEnd; ++it)
	{
		SoundChannel * ch = *it;
		if(SoundChannel::STATE_FREE == ch->GetState())
		{
			return ch;
		}
	}

	for(it = channelsPool.begin(); it != itEnd; ++it)
	{
		SoundChannel * ch = *it;
		if(ch->GetProirity() < priority)
		{
			ch->Stop();
			return ch;
		}
	}

	return 0;
}
Ejemplo n.º 4
0
void SoundSystem::Update()
{
	Deque<SoundChannel*>::iterator it;
	Deque<SoundChannel*>::iterator itEnd = channelsPool.end();
	for(it = channelsPool.begin(); it != itEnd; ++it)
	{
		SoundChannel * ch = *it;
		if(SoundChannel::STATE_FREE != ch->GetState())
		{
			ch->Update();
		}
	}

	List<SoundInstance*>::iterator sit = soundInstances.begin();
	List<SoundInstance*>::iterator sEnd = soundInstances.end();
	while(sit != sEnd)
	{
		if(!(*sit)->Update())
		{
			sit = soundInstances.begin();
			continue;
		}
		++sit;
	}
}
Ejemplo n.º 5
0
SoundChannel* SoundPool::allocateChannel_l(int priority)
{
    List<SoundChannel*>::iterator iter;
    SoundChannel* channel = NULL;

    // allocate a channel
    if (!mChannels.empty()) {
        iter = mChannels.begin();
        if (priority >= (*iter)->priority()) {
            channel = *iter;
            mChannels.erase(iter);
            ALOGV("Allocated active channel");
        }
    }

    // update priority and put it back in the list
    if (channel) {
        channel->setPriority(priority);
        for (iter = mChannels.begin(); iter != mChannels.end(); ++iter) {
            if (priority < (*iter)->priority()) {
                break;
            }
        }
        mChannels.insert(iter, channel);
    }
    return channel;
}
int SoundPool::run()
{
    mRestartLock.lock();
    while (!mQuit) {
        mCondition.wait(mRestartLock);
        LOGV("awake");
        if (mQuit) break;

        while (!mRestart.empty()) {
            SoundChannel* channel;
            LOGV("Getting channel from list");
            List<SoundChannel*>::iterator iter = mRestart.begin();
            channel = *iter;
            mRestart.erase(iter);
            if (channel) channel->nextEvent();
            if (mQuit) break;
        }
    }

    mRestart.clear();
    mCondition.signal();
    mRestartLock.unlock();
    LOGV("goodbye");
    return 0;
}
    void test_PlayLoop()
    {
        xtime xt;
        
/*        Ogre::ResourceManager::ResourceMapIterator it =
            SoundManager::getSingleton().getResourceIterator();
        while (it.hasMoreElements()) */
        {
            SoundSample *sound = new SoundSample("test.ogg");
            sound->setLooping(true);
            sound->load();
            SoundChannel *channel = new SoundChannel(sound, sound->getName());
            if (channel)
            {
                channel->play();
                
                xtime_get(&xt, TIME_UTC);
                xt.sec+=10;
                thread::sleep(xt);
                
                delete sound;
            }            
        }
        CPPUNIT_ASSERT(true);
    }
Ejemplo n.º 8
0
void SoundPool::setVolume(int channelID, float leftVolume, float rightVolume)
{
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setVolume(leftVolume, rightVolume);
    }
}
void SoundPool::pause(int channelID)
{
    LOGV("pause(%d)", channelID);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->pause();
    }
}
Ejemplo n.º 10
0
void SoundPool::setLoop(int channelID, int loop)
{
    ALOGV("setLoop(%d, %d)", channelID, loop);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setLoop(loop);
    }
}
Ejemplo n.º 11
0
void SoundPool::setPriority(int channelID, int priority)
{
    ALOGV("setPriority(%d, %d)", channelID, priority);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setPriority(priority);
    }
}
Ejemplo n.º 12
0
void SoundPool::resume(int channelID)
{
    ALOGV("resume(%d)", channelID);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->resume();
    }
}
Ejemplo n.º 13
0
void SoundPool::autoResume()
{
    ALOGV("autoResume()");
    Mutex::Autolock lock(&mLock);
    for (int i = 0; i < mMaxChannels; ++i) {
        SoundChannel* channel = &mChannelPool[i];
        channel->autoResume();
    }
}
Ejemplo n.º 14
0
void SoundPool::setRate(int channelID, float rate)
{
    ALOGV("setRate(%d, %f)", channelID, rate);
    Mutex::Autolock lock(&mLock);
    SoundChannel* channel = findChannel(channelID);
    if (channel) {
        channel->setRate(rate);
    }
}
Ejemplo n.º 15
0
void SoundDevice::releaseAllChannels()
{
   while(m_activeChannels.size() > 0)
   {
      SoundChannel* channel = m_activeChannels.back();
      channel->stop();
      delete channel;
      m_activeChannels.pop_back();
   }
}
void SoundChannel::callback(int event, void* user, void *info)
{
    unsigned long toggle = (unsigned long)user & 1;
    SoundChannel* channel = static_cast<SoundChannel*>((void *)((unsigned long)user & ~1));
    
    if (channel->mToggle != toggle) {
        LOGV("callback with wrong toggle");
        return;
    }
    channel->process(event, info);
}
Ejemplo n.º 17
0
SoundInstance * Sound::Play()
{
#ifdef __DAVAENGINE_ANDROID__
    SLresult result;
    
    if(TYPE_STATIC == type)
    {
        result = (*playerBufferQueue)->Clear(playerBufferQueue);
        DVASSERT(SL_RESULT_SUCCESS == result);
        
        buffer->FullFill(provider, playerBufferQueue);
    }
    
    if(TYPE_STREAMED == type)
    {
        result = (*playerSeek)->SetPosition(playerSeek, 0, SL_SEEKMODE_FAST);
        DVASSERT(SL_RESULT_SUCCESS == result);
    }

    result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING);
    DVASSERT(SL_RESULT_SUCCESS == result);
    
    soundInstances.clear();
    
    SoundInstance * inst = new SoundInstance(this);
    AddSoundInstance(inst);
    
    return soundInstances.front();
#else
    
	if(TYPE_STREAMED == type && soundInstances.size())
	{
		return soundInstances.front();
	}

	SoundChannel * ch = SoundSystem::Instance()->FindChannel(priority);
	if(!ch)
	{
		return 0;
	}

	if(TYPE_STREAMED == type)
	{
		PrepareDynamicBuffers();
	}

	SoundInstance * inst = new SoundInstance();
	inst->buddyChannel = ch;
	AddSoundInstance(inst);
	ch->SetVolume(volume);
	ch->Play(this, looping);
	return inst;
#endif //#ifdef __DAVAENGINE_ANDROID__
}
Ejemplo n.º 18
0
/**
 * @author JoSch
 * @date 03-11-2005
 */   
SoundObject::~SoundObject()
{
    if (mMovableObject)
    {
        SoundChannel *sc = dynamic_cast<SoundChannel*>(mMovableObject);
        if (sc)
        {
            sc->stop();
        }
        delete mMovableObject;
    }
}
Ejemplo n.º 19
0
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();
    }
}
Ejemplo n.º 20
0
void SoundSystem::Suspend()
{
	Deque<SoundChannel*>::iterator it;
	Deque<SoundChannel*>::iterator itEnd = channelsPool.end();
	for(it = channelsPool.begin(); it != itEnd; ++it)
	{
		SoundChannel * ch = *it;
		if(SoundChannel::STATE_PLAYING == ch->GetState())
		{
			ch->Pause(true);
		}
	}
#ifdef __DAVASOUND_AL__
	alcSuspendContext(context);
#endif
}
Ejemplo n.º 21
0
void SoundSystem::Resume()
{
#ifdef __DAVASOUND_AL__
	alcProcessContext(context);
	Deque<SoundChannel*>::iterator it;
	Deque<SoundChannel*>::iterator itEnd = channelsPool.end();
	for(it = channelsPool.begin(); it != itEnd; ++it)
	{
		SoundChannel * ch = *it;
		if(SoundChannel::STATE_PAUSED == ch->GetState())
		{
			ch->Pause(false);
		}
	}
#endif
}
Ejemplo n.º 22
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;
      }
   }
}
Ejemplo n.º 23
0
/**
 * @author JoSch
 * @date 03-11-2005
 */   
void SoundObject::_update()
{
    ActorControlledObject::_update();
    SoundChannel *channel = getSoundChannel();
    Actor *actor = getActor();
    if (!channel || !actor) // Einer ist Null
    {
        return;
    }
    if (!channel->isValid())
    {
        return;
    }
    channel->setPosition(actor->getPosition());
    Vector3 *temp1 = new Vector3();
    Vector3 *temp2 = new Vector3(actor->getPosition());
    Real length = temp2->normalise();
    actor->getOrientation().ToAxes(temp1);
    *temp1 += *temp2;
    *temp1 *= length;
    channel->setDirection(*temp1); 
}
Ejemplo n.º 24
0
int SoundPool::play(int sampleID, float leftVolume, float rightVolume,
        int priority, int loop, float rate)
{
    ALOGV("play sampleID=%d, leftVolume=%f, rightVolume=%f, priority=%d, loop=%d, rate=%f",
            sampleID, leftVolume, rightVolume, priority, loop, rate);
    sp<Sample> sample;
    SoundChannel* channel;
    int channelID;

    Mutex::Autolock lock(&mLock);

    if (mQuit) {
        return 0;
    }
    // is sample ready?
    sample = findSample(sampleID);
    if ((sample == 0) || (sample->state() != Sample::READY)) {
        ALOGW("  sample %d not READY", sampleID);
        return 0;
    }

    dump();

    // allocate a channel
    channel = allocateChannel_l(priority);

    // no channel allocated - return 0
    if (!channel) {
        ALOGV("No channel allocated");
        return 0;
    }

    channelID = ++mNextChannelID;

    ALOGV("play channel %p state = %d", channel, channel->state());
    channel->play(sample, channelID, leftVolume, rightVolume, priority, loop, rate);
    return channelID;
}
Ejemplo n.º 25
0
    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;
            }            
        }        
    }
Ejemplo n.º 26
0
void Ambient::applySounds(uint32 fadeOutDelay) {
	// Reset the random sounds
	_cueStartTick = 0;
	if (!_cueSheet.id) {
		_vm->_sound->stopCue(fadeOutDelay);
	}

	// Age all sounds
	_vm->_sound->age();

	// Setup the selected sounds
	for (uint i = 0; i < _sounds.size(); i++) {
		const AmbientSound &sound = _sounds[i];

		bool existingChannel;
		SoundChannel *channel = _vm->_sound->getChannelForSound(sound.id, kAmbient, &existingChannel);

		// The sound was already playing
		if (!existingChannel) {
			uint volume = 0;
//			if (sound.volumeFlag) // TODO: Used in the original
				volume = sound.volume;

			channel->play(sound.id, volume, sound.heading, sound.headingAngle, true, kAmbient);
		}

		if (channel->_playing) {
			channel->fade(sound.volume, sound.heading, sound.headingAngle, fadeOutDelay);
			channel->_age = 0;
			channel->_ambientFadeOutDelay = sound.fadeOutDelay;
		}
	}

	// Fade out old playing ambient sounds
	_vm->_sound->fadeOutOldSounds(fadeOutDelay);
}
Ejemplo n.º 27
0
void Sound::playEffect(uint32 id, uint32 volume, uint16 heading, uint16 attenuation) {
	id = _vm->_state->valueOrVarValue(id);

	SoundChannel *channel = getChannelForSound(id, kEffect);
	channel->play(id, volume, heading, attenuation, 0, 0, 0, kEffect);
}
Ejemplo n.º 28
0
void SoundChannel::callback(int event, void* user, void *info)
{
    SoundChannel* channel = static_cast<SoundChannel*>((void *)((unsigned long)user & ~1));

    channel->process(event, info, (unsigned long)user & 1);
}