/*!\brief Base constructor.
 *
 * It sets default values for class attributes. It initializes the filter and applies it to a white noise to generate the final noise (#loadNoise).
 * \arg tStep = 0.01
 * \arg tDurAdd = 1.0
 * \arg tFirst = 5.0
 * \arg tLast = -20.0
 * \arg NoiseType = Filter 
 * \arg alpha coefficients of #NFilter = 0 (see Filter#alpha)
 * \arg beta parameter of #NFilter = 1 (see Filter#beta)
 * \arg NbDataStab parameter of #NFilter = 0 (see Filter#NbDataStab)
*/
NoiseTwoFilter::NoiseTwoFilter()
{
    tStep = 0.01;
    tDurAdd = 1.0;
    tFirst = 5.0;
    tLast = -20.0;
    /*! \todo Make a function to compute a int from a double. Is there a reason to no call rint ?*/
	NbData = (int)((tFirst-tLast)/tStep+100*PRECISION);
	vector< vector<double> > alpha_tmp(0);
	vector< vector<double> > beta_tmp(0);
	vector<double> TmpVect(1);
	TmpVect.push_back(1.0);
	beta_tmp.push_back(TmpVect);
	NFilter.init(alpha_tmp, beta_tmp, 0);
	NFilter_2.init(alpha_tmp, beta_tmp, 0);
	loadNoise();
	strcpy(NoiseType,"Filter");
}
/*! \brief Constructor.
 *
 * It sets class attributes including the noise filter. 
 * It applies the filter to a white noise to generate the final noise (see #loadNoise)).
 *  #NoiseType attribute is set to \p File.
 * \param tStep_n Value of #tStep. 
 * \param tDurAdd_n Value of #tDurAdd.
 * \param tFirst_n Value of #tFirst.
 * \param tLast_n Value of #tLast.
 * \param NFilter_n Filter for #NFilter.
 * \param NFilter_n2 Filter for #NFilter.
*/
NoiseTwoFilter::NoiseTwoFilter(	double tStep_n,
				double tDurAdd_n,
				double tFirst_n,
				double tLast_n,
				Filter NFilter_n,
				Filter NFilter_n2)
{
    //cout << "In Noise Filter" << endl;
	settStep(tStep_n);
	settDurAdd(tDurAdd_n);
	settFirst(tFirst_n);
	settLast(tLast_n);
	
	
	NbData = (int)((tFirst-tLast)/tStep+100*PRECISION);
	NFilter.Copy(NFilter_n);
	NFilter_2.Copy(NFilter_n2);
	loadNoise();
	strcpy(NoiseType,"NoiseTwoFilter"); // ?????
}
Ejemplo n.º 3
0
/**
 * Start speech
 * @remarks	Originally called 'parole'
 */
void SpeechManager::startSpeech(int rep, int ht, int typ) {
	uint16 savph[501];
	int tempo;

	if (_vm->_soundOff)
		return;

	_phonemeNumb = rep;
	int haut = ht;
	_typlec = typ;
	if (_typlec != 0) {
		for (int i = 0; i <= 500; ++i)
			savph[i] = _cfiphBuffer[i];
		tempo = kTempoNoise;
	} else if (haut > 5)
		tempo = kTempoF;
	else
		tempo = kTempoM;
	_vm->_addFix = (float)((tempo - 8)) / 256;
	cctable(_tbi);
	switch (typ) {
	case 1:
		loadNoise();
		regenbruit();
		break;
	case 2:
		loadMusicSound();
		loadPhonemeSounds();
		break;
	default:
		break;
	}
	handlePhoneme();
	_vm->_soundManager.litph(_tbi, typ, tempo);
	if (_typlec != 0)
		for (int i = 0; i <= 500; ++i) {
			_cfiphBuffer[i] = savph[i];
			_mlec = _typlec;
		}
	_vm->setPal(_vm->_numpal);
}
Ejemplo n.º 4
0
int main()
{
	
	// SFML window that will host our OpenGL magic
	
    sf::Window window(sf::VideoMode(1920, 1080), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
    window.setVerticalSyncEnabled(true);
	window.setMouseCursorVisible(false);
	sf::View view;
	
	sf::Mouse::setPosition(sf::Vector2i(window.getSize().x / 2, window.getSize().y / 2),  window);
	
	glewInit();
	
	Player	player;
	programInit(shaderMap, modelMap, textureMap, normalMap);
	initPresetSystem(shaderMap, modelMap, textureMap, normalMap, presetMap);
	Editor editor(modelMap, shaderMap, textureMap, normalMap, presetMap);

	GLInit();
	
	// ---------------------- MODELS -------------------------------
	Model		sphereModel, unitSquareModel;
	generateSphere(&sphereModel, 50);						sphereModel.upload();
	myLoadObj("Models/unitSquare.obj", &unitSquareModel);	unitSquareModel.upload();

	loadNoise();

	// Add terrain information to earth
	cv::Mat earthBumpMap = cv::imread("Textures/earthBumpMap.jpg");
	earthBumpMap.convertTo(earthBumpMap, CV_32F);
	int height = earthBumpMap.rows;
	int width = earthBumpMap.cols;
	std::cout << "Dims: " << height << ", " << width << std::endl;
	std::cout << "Dims: " << *earthBumpMap.row(height-1).col(5).ptr<float>() << std::endl;

	// ---------------------- OBJECTS -------------------------------
	// Initiation of all objects in the program
	// ShaderParameters = (ambientCoeff, diffuseCoeff, specularCoeff, specularExponent)
	cv::Vec4f standardShaderParameters(0.2f, 0.5f, 0.8f, 10);

	Object squareNormalMap, squareSpecularityMap;
	GLuint earthNormalMap, earthSpecularityMap, earthTextureDay, earthTextureNight;
	GLuint normalMapShader, specularityMapShader;

	shaderInit(&phongNoTex, "Shaders/phongNoTex.vert", "Shaders/phongNoTex.frag");
	shaderInit(&normalMapShader, "Shaders/normalMap.vert", "Shaders/normalMap.frag");
	shaderInit(&specularityMapShader, "Shaders/specularityMap.vert", "Shaders/specularityMap.frag");
	
	LoadTGATextureSimple("Textures/earthTextureDay.tga", &earthTextureDay);
	LoadTGATextureSimple("Textures/earthTextureNight.tga", &earthTextureNight);
	LoadTGATextureSimple("Textures/earthNormalMap.tga", &earthNormalMap);
	LoadTGATextureSimple("Textures/earthSpecularityMap.tga", &earthSpecularityMap);

	//squareNormalMap.init(&unitSquareModel, phongNoTex, standardShaderParameters, 0, 0, 0, earthNormalMap);
	squareNormalMap.init(&unitSquareModel, normalMapShader, standardShaderParameters, 0, 0, 0, earthNormalMap);
	squareSpecularityMap.init(&unitSquareModel, specularityMapShader, standardShaderParameters, earthTextureDay, earthTextureNight, earthSpecularityMap, earthNormalMap);
	squareNormalMap.set(cv::Vec3f(100,0,0),  cv::Vec3f(50,50,100), cv::Vec3f(0, pi/2, -pi/2), cv::Vec3f(0,0,0), 1);
	squareSpecularityMap.set(cv::Vec3f(100,0,0),  cv::Vec3f(50,50,100), cv::Vec3f(0, pi/2, -pi/2), cv::Vec3f(0,0,0), 1);
	

	// ---------------------- SKYSPHERE -------------------------------
	Object skysphere;
	GLuint skysphereTexture, skyboxShader;
	LoadTGATextureSimple("Textures/spaceBox6.tga", &skysphereTexture);


	shaderInit(&skyboxShader, "Shaders/skybox.vert", "Shaders/skybox.frag");

	skysphere.init(&sphereModel, skyboxShader, standardShaderParameters, skysphereTexture);
	skysphere.set(player.position,  cv::Vec3f(1,1,1), cv::Vec3f(0,0,0), cv::Vec3f(0,0,0), 1);

	


	int item;

	// SFML built-in clock
	sf::Clock clock;
	states[RUNNING] = true;
    states[EDITOR] = true;
	states[STARTUP] = true;
	/*
	bool running = true;
    bool runningEditor = true;
	bool startup = true;
	bool selectObject = false;
	bool cooldown = false;
	*/
	Object* currentObject = NULL;
	Object* playerObject = NULL;
	

	while (states[RUNNING])
    {
		dt = clock.getElapsedTime().asSeconds();
		if(states[EDITOR])
		{
			window.setVisible(false);
			if(states[SELECTOBJECT])
			{
				solsystem.getObjects(&allObjects);
				currentObject = getSelectedObject(&allObjects, &player);
				allObjects.clear();
			}
			editor.edit(solsystem, states, currentObject);
			states[STARTUP] = false;
			sf::Mouse::setPosition(sf::Vector2i(window.getSize().x / 2, window.getSize().y / 2),  window);
			clock.restart();
			window.setActive();

			states[SELECTOBJECT] = false;
			currentObject = NULL;
			
			states[EDITOR] = false;
			window.setVisible(true);
		}

		else
		{
			clock.restart();
			if (playerObject != NULL)
			{
				std::cout << player.position << std::endl;
			
				player.move(playerObject->position);
				//player.position = playerObject->position;

				std::cout << playerObject->position << std::endl;
			}
			
			handleEvents(&window, states, &item, playerObject, &player, dt);
			player.lookAtUpdate(dt);

			// Plocka ut all planeters positioner
			std::list<Object*> allObjects;
			solsystem.getObjects(&allObjects);
			std::vector<cv::Vec3f> positionVector;
			std::vector<cv::Vec3f> radiusVector;
			

			std::list<Object*>::iterator i = allObjects.begin();

			for (i++ ; i != allObjects.end(); ++i)
			{
				positionVector.push_back((*i)->position);
				radiusVector.push_back((*i)->scale);
				//std::cout << "Scale: " << (*i)->scale << std::endl;
			}

			int numberOfPlanets = positionVector.size();

			GLfloat* positions = makeArray(positionVector);
			GLfloat* radius = makeArray(radiusVector);
			

			/////////////////////////////////   SKYBOX   /////////////////////////////////////////
			window.setActive();
			//drawSkybox(&player, &skyboxModel, skyboxShader, skyboxTexture);

			glDisable(GL_DEPTH_TEST);
			//skybox.set(player.position,  cv::Vec3f(5,5,5), cv::Vec3f(0,0,0), cv::Vec3f(0,0,0), 1);
			//skybox.draw(&player);
			skysphere.set(player.position,  cv::Vec3f(5,5,5), cv::Vec3f(0,0,0), cv::Vec3f(0,0,0), 1);
			skysphere.draw(&player, 0, dt);
			glEnable(GL_DEPTH_TEST);

			/////////////////////////////////   ALX   /////////////////////////////////////////

			if (states[NORMALMAP])
			{
				squareNormalMap.draw(&player, dt, numberOfPlanets, positions, radius);
			}
			if (states[SPECULARITYMAP])
			{
				squareSpecularityMap.draw(&player, dt, numberOfPlanets, positions, radius);
			}

			/////////////////////////////////   ALX   /////////////////////////////////////////




		
			if(!states[COOLDOWN] && item == 1)
			{
				Object* newItem = presetMap["Earth"]->clone();
				newItem->set(player.position,  cv::Vec3f(0.25,0.25,0.25), cv::Vec3f(0,0,0), 10*player.getLookAtDirection(), 1);
				solsystem.addItem(newItem);
				std::cout << 10*normalize(player.position - player.lookAtVector) << std::endl;
				states[COOLDOWN] = true;
			}
			item = 0;
			if(states[ENABLEGRAVITY] && playerObject == NULL)
			{
				playerObject = presetMap["Earth"]->clone();
				playerObject->set(player.position,  cv::Vec3f(1.25,1.25,1.25), cv::Vec3f(0,0,0), cv::Vec3f(0,0,0), 1);
				solsystem.addPlayerItem(playerObject);
				states[ENABLEGRAVITY] = false;
			}
			if(states[DISABLEGRAVITY] && playerObject != NULL)
			{
				solsystem.removePlayerItem();
				playerObject = NULL;
				states[DISABLEGRAVITY] = false;
			}

			solsystem.update(physEngine, dt*0.5);
			solsystem.draw(&player, accTime);
			accTime += dt;

			window.display();
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		}

		cv::waitKey(0);
	}
    // release resources...
	glDeleteVertexArrays(1, &sphereModel.VAO);
	//glDeleteVertexArrays(1, &skyboxModel.VAO);
	//glDeleteVertexArrays(1, &unitSquareModel.VAO);
	//glDeleteVertexArrays(1, &groundModel.VAO);
	
	return 0;
}
Ejemplo n.º 5
0
NoiseOof::NoiseOof(	double tStep_n,		// IN : Time step
					double tDurAdd_n,	// IN : Time add for each adding of noise
					double tFirst_n,	// IN : Time of the first bin (>0)
					double tLast_n,		// IN : Time of the last bin (<0)
					double fmin_n,		// IN : Minimal frequency for the range where the filter have the good shape
					double fmax_n,		// IN : Maximal frequency for the range where the filter have the good shape
					double alpha_n,		// IN : Power of f  --> Shape : f^alpha
					int Nb_Ageing_n	    // IN : Number of events before stabilization. 
					)
{
    settStep(tStep_n);
    settDurAdd(tDurAdd_n);
    settFirst(tFirst_n);
    settLast(tLast_n);
	fmin = fmin_n;
	fmax = fmax_n;
	alpha = alpha_n;
	Nb_Ageing = Nb_Ageing_n;
/*
	cout << "fmin  = " << fmin << endl;
	cout << "fmax  = " << fmax << endl;
	cout << "alpha = " << alpha << endl;
*/
	
    /*! \todo Make a function to compute a int from a double. Is there a reason to no call rint ?*/
	NbData = (int)((tFirst-tLast)/tStep+100*PRECISION);

	
	
	vector< vector<double> > alpha_tmp(0);
	vector< vector<double> > beta_tmp(0);
	
	//  Calcul des poles.
	
	double w0,w1,wmax,wmin;
	double p0,z0,dp;
	double p,z,pcourant,zcourant,dpcourant,den,tStep_inv;
	int nproc;
	
	w0   = 2*M_PI*fmin;
	w1   = 2*M_PI*fmax;
	wmax = log10(w1);
	wmin = log10(w0);

	//printf(" w0 = %f , w1 = %f ,  wmax = %f, wmin = %f, tStep = %f  \n", w0,w1, wmax,wmin,tStep);	

	tStep_inv = 1./tStep;

	nproc = (int)((wmax-wmin)*2.+log10(tStep_inv));  // Nombres de poles.


	alpha_tmp.resize(nproc);
	beta_tmp.resize(nproc);
		
	dp = (wmax-wmin)/nproc;
	p0 = wmin+(1+alpha/2)/2*dp;
	z0 = p0-alpha/2*dp;
	pcourant = p0;
	zcourant = z0;
	dpcourant = 0.;

	for(int i=0;i<nproc;i++)
	{ 
		p = pcourant+dpcourant;
		dpcourant =	(wmax-wmin)/nproc;
		z = p-alpha/2*dp;
		w0 = (pow(10,p)/2)*tStep;
		w1 = (pow(10,z)/2)*tStep;
		pcourant = p;
		zcourant = z;
		den = 1+w0;
		alpha_tmp[i].resize(1);
		beta_tmp[i].resize(2);
		alpha_tmp[i][0]=(1-w0)/den;
		beta_tmp[i][0]=(1+w1)/den;
		beta_tmp[i][1]=-(1-w1)/den;


		//printf(" filtre %d : alpha0 = %f , beta0 = %f ,  beta1 = %f \n", i, alpha_tmp[i][0], beta_tmp[i][0], beta_tmp[i][1]);

		
	} 
		
		
	NFilter.init(alpha_tmp, beta_tmp, Nb_Ageing);
	
	//NFilter.init(alpha_tmp, beta_tmp, 0);
    loadNoise();
    ///cout << "  - WhiteData size = " << WhiteData.size() << endl;
    ///cout << "  - NoiseData size = " << NoiseData.size() << endl;
    ///for(int i=0; i<10; i++)
    ///	cout << "    WhiteData[i] = " << WhiteData[i] << "  -    NoiseData[i] = " << NoiseData[i] << endl;
	strcpy(NoiseType,"Oof");
}