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);
    }
 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);
 }
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;
}
    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;
            }            
        }        
    }
예제 #5
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);
}
예제 #6
0
파일: sound.cpp 프로젝트: agharbi/residual
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);
}