Ejemplo n.º 1
0
	virtual SoundInstanceId play(SoundResource* sr, bool loop, float volume, const Vector3& pos)
	{
		SoundInstance instance;
		instance.create(sr, pos);
		SoundInstanceId id = id_array::create(m_playing_sounds, instance);
		id_array::get(m_playing_sounds, id).m_id = id;
		instance.play(loop, volume);
		return id;
	}
Ejemplo n.º 2
0
void Button::playPressedSound()
{
	if(getEngine()->getSoundEnvironment() != NULL)
	{
		if(SystemManager::settingExists("config/sound"))
		{
			Sound* sound = getEngine()->getSoundEnvironment()->getSound("selectMenuSound");
			if( sound != NULL )
			{
				SoundInstance* inst = new SoundInstance(sound);
				inst->setLocalPosition( getContainer()->get3dSettings().position );
				inst->play();
			}
		}
	}
}
Ejemplo n.º 3
0
	SoundTest()
	{
		//soundManager = new SoundManager();
		//soundManager->connectToServer("localhost",57120);
		
		// More concise method of above two lines
		soundManager = new SoundManager("localhost",57120);

		soundManager->showDebugInfo(true);

		// Get default sound environment
		env = soundManager->getSoundEnvironment();

		
		while( !soundManager->isSoundServerRunning() )
		{
			soundManager->startSoundServer();
		}

		// Load sound assets
		//env->setAssetDirectory("menu_sounds");

		showMenuSound = env->loadSoundFromFile("showMenuSound","menu_sounds/menu_load.wav");
		hideMenuSound = env->loadSoundFromFile("hideMenuSound","menu_sounds/menu_closed.wav");
		scrollMenuSound = env->loadSoundFromFile("scrollMenuSound","menu_sounds/menu_scroll.wav");
		selectMenuSound = env->loadSoundFromFile("selectMenuSound","menu_sounds/menu_select.wav");
		soundLoop = env->loadSoundFromFile("mus","Omega4Relay.wav");

		SoundInstance* soundInstance = new SoundInstance(showMenuSound);
		soundInstance->setReverb( 1.0, 1.0 );
		soundInstance->setVolume(1.0);
		soundInstance->setPosition( Vector3f(0,1,0) );
		soundInstance->play();

		rewindingSoundInstance = new SoundInstance(showMenuSound);
	}
Ejemplo n.º 4
0
void HelloApplication::handleEvent(const Event& evt)
{
	if(evt.getServiceType() == Service::Wand)
	{
				
		xPos = evt.getPosition().x();
		yPos = evt.getPosition().y();
		zPos = evt.getPosition().z();
		
		if( soundLoopInst != NULL )
			soundLoopInst->setPosition( evt.getPosition() );
	
		if( evt.getType() == Event::Down )
		{
			if( evt.getFlags() == Event::Button3 ) // Wand cross button
			{
				// playStereo() is for ambient music.
				// Currently available functions:
				//	 setVolume(float) - amplitude from (0.0 - 1.0)
				//	 setLoop(bool)
				//	 stop() - this means this instance is finished and a new
				//			  sound instance will need to be created to play
				SoundInstance* musicInst = new SoundInstance(music);
				musicInst->setVolume(0.2f);
				musicInst->playStereo();
			}
			else if( evt.getFlags() == Event::Button5 ) // Wand L1
			{
				env->getSoundManager()->stopAllSounds();
			}
			else if( evt.getFlags() == Event::ButtonLeft ) // DPad
			{
				SoundInstance* soundInst = new SoundInstance(sound);
				soundInst->setPosition( evt.getPosition() );
				soundInst->play();
				changeCubeColor = true;
			}
			else if( evt.getFlags() == Event::ButtonRight ) // DPad
			{
				if( soundLoopInst != NULL || !soundLoopInst->isPlaying() )
				{
					// Positional sounds use play()
					// Currently available functions:
					//	 stop() - this means this instance is finished and a new
					//			  sound instance will need to be created to play
					//	 setPosition(Vector3f) 
					//	 setVolume(float) - amplitude from (0.0 - 1.0)
					//	 setLoop(bool)
					//	 setMix(float) - wetness of sound (0.0 - 1.0)
					//	 setReverb(float) - room size / reverb amount (0.0 - 1.0)
					//	 setWidth(int) - number of speakers to spread sound across (1-20)
					//			This will eventually be replaced with a sound radius
					soundLoopInst = new SoundInstance(sound1);
					soundLoopInst->setPosition( evt.getPosition() );
					soundLoopInst->setLoop(true);
					soundLoopInst->setVolume(0.2f);
					soundLoopInst->setWidth(3);
					soundLoopInst->play();
				}
				else if( soundLoopInst != NULL )
				{
					soundLoopInst->stop();
				}
				
				changeCubeColor = true;
			}
			else
			{
				SoundInstance* soundInst = new SoundInstance(sound);
				soundInst->setPosition( evt.getPosition() );
				soundInst->setRoomSize(1.0);
				soundInst->setWetness(1.0);
				//soundInst->setVolume(0.5);
				soundInst->play();
				changeCubeColor = true;
			}
			
			
		}
		else if( evt.getType() == Event::Up )
		{
			changeCubeColor = false;
		}
	}
}
Ejemplo n.º 5
0
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Checks the type of event. If a valid event, creates an event packet and returns true. Else return false.
	virtual bool handleEvent(const Event& evt)
	{
		
		float leftRightAnalog;
		float upDownAnalog;
		float zeroTolerence = 0.008f;
		float xPos;
		float yPos;
		float zPos;

		switch(evt.getServiceType())
		{
			case Service::Wand:
				leftRightAnalog = evt.getExtraDataFloat(0);
				upDownAnalog = evt.getExtraDataFloat(1);

				volume = evt.getExtraDataFloat(4);
				
				if( soundLoopInstance != NULL )
				{
					soundLoopInstance->setVolume(volume);
				}

				if( evt.getType() == Event::Down ){

					if( evt.getFlags() & Event::Button3){ // Cross
						
						soundLoopInstance->setEnvironmentSound( true );
						soundLoopInstance->setLoop( true );
						
						soundLoopInstance->playStereo();
					}
					if( evt.getFlags() & Event::Button2){ // Circle
						soundLoopInstance->stop();
					}
					
					if( evt.getFlags() & Event::Button5){ // L1
						soundLoopInstance = new SoundInstance(soundLoop);
					}

					if( evt.getFlags() & Event::ButtonRight){
						
						rewindingSoundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						rewindingSoundInstance->setReverb( upDownAnalog, upDownAnalog );
						rewindingSoundInstance->play();
					}
					if( evt.getFlags() & Event::ButtonLeft){
						SoundInstance* soundInstance = new SoundInstance(hideMenuSound);
						soundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						soundInstance->setReverb( upDownAnalog, upDownAnalog );
						soundInstance->play();
					}
					if( evt.getFlags() & Event::ButtonUp){
						SoundInstance* soundInstance = new SoundInstance(selectMenuSound);
						soundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						soundInstance->setReverb( upDownAnalog, upDownAnalog );
						soundInstance->play();
					}
					if( evt.getFlags() & Event::ButtonDown){
						SoundInstance* soundInstance = new SoundInstance(scrollMenuSound);
						soundInstance->setPosition( Vector3f(leftRightAnalog,1,0) );
						soundInstance->setReverb( upDownAnalog, upDownAnalog );
						soundInstance->play();
					}
					//printf("%d \n", evt.getFlags() );
				}
				
				if( (leftRightAnalog > zeroTolerence || leftRightAnalog < -zeroTolerence) &&
					(upDownAnalog > zeroTolerence || upDownAnalog < -zeroTolerence)
					){
					position[0] = leftRightAnalog;
					position[1] = upDownAnalog;
					printf("Analog Stick: %f %f\n", position[0], position[1]);
				}
				if( volume > 0 )
					printf("Analog Trigger (L2): %f\n", volume);
				return true;
				break;

			case Service::Mocap:
				//if( evt.getSourceId() == 0 )
				//	soundManager->setListenerPosition( evt.getPosition() );
				//env->setListenerPosition( Vector3f(0,0,0) );
				//else if( instanceCreated && evt.getSourceId() == 1 )
				//	soundInstance->setPosition( evt.getPosition() );
				//printf("ID: %d Pos: %f %f %f\n", evt.getSourceId(), evt.getPosition(0), evt.getPosition(1), evt.getPosition(2) );
				break;
		}
		
		return false;
	}