Exemplo n.º 1
0
	virtual void initialize()
	{
		env = getEngine()->getSoundEnvironment();
		env->setAssetDirectory("/Users/evldemo/sounds/");
		
		// All sound files should be in .wav format
		// For positional sounds, file should be mono.
		// Rest of important sound code is in handleEvent()
		sound = env->loadSoundFromFile("beep", "/menu_sounds/menu_select.wav");
		music = env->loadSoundFromFile("music", "/music/filmic.wav");
		sound1 = env->loadSoundFromFile("tricorder", "/arthur/TOS-tricorder.wav");

		// 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();

		changeCubeColor = false;
	}
Exemplo n.º 2
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;
		}
	}
}