コード例 #1
0
ファイル: music.hpp プロジェクト: 20k/SwordFight
    static void tick()
    {
        if(currently_playing.getStatus() == sf::SoundSource::Stopped)
        {
            current_song++;

            swap_to_song_type(ROUND_GENERAL);
        }
    }
コード例 #2
0
ファイル: VisualNovel.cpp プロジェクト: rmxhaha/phantasia
	void HandleSound(){
		/* Handle sound_queue and music */

		if( SoundFx.getStatus() == 0 ){ //status : STOPPED
			if( !sound_queue.empty() ){
				SoundFx.openFromFile( *sound_queue.front() );
				SoundFx.play();

				sound_queue.pop();
			}
		}

		if( ::SoundMusic.getStatus() == 0 && now_log -> music_path.size() != 0 ){
			::SoundMusic.play();
		}
	}
コード例 #3
0
ファイル: music.hpp プロジェクト: 20k/SwordFight
    static void swap_to_song_type(music_purpose new_purpose)
    {
        if(new_purpose == NONE)
        {
            currently_playing.stop();
            current_song = -1;
            return;
        }

        ///at the moment do shit
        int new_song = -1;

        for(int i=0; i<(int)file_names.size(); i++)
        {
            int song_offset = (i + current_song) % file_names.size();

            music_purpose current_purpose = (music_purpose)purpose[song_offset];

            if((current_purpose & new_purpose) > 0)
            {
                new_song = song_offset;
                break;
            }
        }

        if(new_song == -1)
            return;

        if(new_song == current_song && currently_playing.getStatus() != sf::SoundSource::Stopped)
            return;

        currently_playing.stop();

        currently_playing.openFromFile("res/" + file_names[new_song]);

        currently_playing.play();

        current_song = new_song;
    }
コード例 #4
0
ファイル: ambiance.cpp プロジェクト: Sebbish/Lucid
void ambiance::tick(int madness)
{
	ambMadness = 101-madness;
	ambMaxVolume = 100;

	// SO THE ENGINE BEGINS //

		// IF NOT PLAYING AA ///////////////////////////////////////////////////
		
		if (ALLambAA[ambAARandom].getStatus() == 0)
		{
			// FILE SELECTOR //
			ambAARandom = rand()% ARRAY_SIZE(ambAAFile);
			//ALLambAA[ambAARandom].openFromFile(ambAAFile[ambAARandom]);

			// VOLUME RESET //
			ALLambAA[ambAARandom].setVolume(0);
			ambAAVolume = 0;
			ambAADynamics = 100000;

			// LENGTH //
			ambAALength = rand() % 60 + 40;
			ambAASecCounter = 0;

			// FADE //
			ambAAFadeSpeed = rand()% 2 + 3;
			ambAAFadeOut = false;

			// PITCH //
			ambAAPitch = rand() % 100;
			ambAAPitch = ambAAPitch/200+0.75;
			ALLambAA[ambAARandom].setPitch(ambAAPitch);
				
			// PLAY //
			ALLambAA[ambAARandom].play();
		}

		// IF NOT PLAYING AB /////////////////////////////////////////////////////////

		if (ALLambAB[ambABRandom].getStatus() == 0)
		{
			// FILE SELECTOR //
			ambABRandom = rand()% ARRAY_SIZE(ambABFile);
			//ALLambAB[ambABRandom].openFromFile(ambABFile[ambABRandom]);

			// VOLUME RESET //
			ALLambAB[ambABRandom].setVolume(0);
			ambABVolume = 0;
			ambABDynamics = 100000;

			// LENGTH //
			ambABLength = rand() % 30 + 30;
			ambABSecCounter = 0;

			// FADE //
			ambABFadeSpeed = rand()% 2 + 3;
			ambABFadeOut = false;

			// PITCH //
			ambABPitch = rand() % 100;
			ambABPitch = ambABPitch/200+0.75;
			ALLambAB[ambABRandom].setPitch(ambABPitch);
				
			// PLAY //
			ALLambAB[ambABRandom].play();
		}
		
		// FADE AA ////////////////////////////////////////////////////////////////
		
		// COUNTERS //

		ambAAFrameCounter++;

		if (ambAAFrameCounter>60)
		{
			ambAAFrameCounter = 0;
			ambAASecCounter++;
		}

		// FADE //

		if (ALLambAB[ambABRandom].getStatus() == 2)
		{
			ambAADynamics = 10000*(ambMadness*0.25/100) + 2500;

			// FADE VOLUME UP //

			if (ambAAVolume + ambAAFadeSpeed < ambAADynamics && ambAAFadeOut == false)
			{
				ambAAVolume = ambAAVolume + ambAAFadeSpeed;

				ambAAIntToFloat = ambAAVolume;
				ALLambAA[ambAARandom].setVolume(ambAAIntToFloat/100*(ambMaxVolume/100));
			}

			// FADE VOLUME DOWN //

			else if (ambAAVolume > ambAADynamics && ambAAFadeOut == false)
			{
				ambAAVolume = ambAAVolume - ambAAFadeSpeed*2;

				ambAAIntToFloat = ambAAVolume;
				ALLambAA[ambAARandom].setVolume(ambAAIntToFloat/100*(ambMaxVolume/100));
			}

			// FADE OUT //

			if (ambAASecCounter > ambAALength && ambABFadeOut == false)
			{
				ambAAFadeOut = true;

				if (ambAAVolume > ambAAFadeSpeed)
				{
					ambAAVolume = ambAAVolume - ambAAFadeSpeed;

					ambAAIntToFloat = ambAAVolume;
					ALLambAA[ambAARandom].setVolume(ambAAIntToFloat/100*(ambMaxVolume/100));
				}

				// STOP //

				if (ambAAVolume <= ambAAFadeSpeed*2)
				{
					ambAAVolume = 0;
					ambAAFadeOut = false;
					ALLambAA[ambAARandom].setVolume(0);
					ALLambAA[ambAARandom].stop();
				}
			}
		}

		// FADE AB ////////////////////////////////////////////////////////////////
		
		// COUNTERS //

		ambABFrameCounter++;

		if (ambABFrameCounter>60)
		{
			ambABFrameCounter = 0;
			ambABSecCounter++;
		}

		// FADE //

		if (ALLambAB[ambABRandom].getStatus() == 2)
		{
			ambABDynamics = 10000*(ambMadness*0.4/100) + 1000;

			// FADE VOLUME UP //

			if (ambABVolume + ambABFadeSpeed < ambABDynamics && ambABFadeOut == false)
			{
				ambABVolume = ambABVolume + ambABFadeSpeed;

				ambABIntToFloat = ambABVolume;
				ALLambAB[ambABRandom].setVolume(ambABIntToFloat/100*(ambMaxVolume/100));
			}

			// FADE VOLUME DOWN //

			else if (ambABVolume > ambABDynamics && ambABFadeOut == false)
			{
				ambABVolume = ambABVolume - ambABFadeSpeed*2;

				ambABIntToFloat = ambABVolume;
				ALLambAB[ambABRandom].setVolume(ambABIntToFloat/100*(ambMaxVolume/100));
			}

			// FADE OUT //

			if (ambABSecCounter > ambABLength && ambAAFadeOut == false)
			{
				ambABFadeOut = true;

				if (ambABVolume > ambABFadeSpeed)
				{
					ambABVolume = ambABVolume - ambABFadeSpeed;

					ambABIntToFloat = ambABVolume;
					ALLambAB[ambABRandom].setVolume(ambABIntToFloat/100*(ambMaxVolume/100));
				}

				// STOP //

				if (ambABVolume <= ambABFadeSpeed*2)
				{
					ambABVolume = 0;
					ambABFadeOut = false;
					ALLambAB[ambABRandom].setVolume(0);
					ALLambAB[ambABRandom].stop();
				}
			}
		}

		// IF NOT PLAYING BA /////////////////////////////////////////////////////////
		
		if (ALLambBA[ambBARandom].getStatus() == 0 && ambMadness > ambBATriggerLevel)
		{
			// FILE SELECTOR //
			ambBARandom = rand()% ARRAY_SIZE(ambBAFile);
			//ALLambBA[ambBARandom].openFromFile(ambBAFile[ambBARandom]);

			// RESETS //
			ALLambBA[ambBARandom].setVolume(0);
			ambBAUpDown = 0;
			ambBAOffOn = 0;

			// PLAY //
			ALLambBA[ambBARandom].play();
		}

		// IF NOT PLAYING BB /////////////////////////////////////////////////////////
		
		if (ALLambBB[ambBBRandom].getStatus() == 0 && ambMadness > ambBBTriggerLevel)
		{
			// FILE SELECTOR //
			ambBBRandom = rand()% ARRAY_SIZE(ambBBFile);
			//ALLambBB[ambBBRandom].openFromFile(ambBBFile[ambBBRandom]);

			// RESETS //
			ALLambBB[ambBBRandom].setVolume(0);
			ambBBUpDown = 0;
			ambBBOffOn = 0;

			// PLAY //
			ALLambBB[ambBBRandom].play();
		}

		// IF NOT PLAYING BC /////////////////////////////////////////////////////////
		
		if (ALLambBC[ambBCRandom].getStatus() == 0 && ambMadness > ambBCTriggerLevel)
		{
			// FILE SELECTOR //
			ambBCRandom = rand()% ARRAY_SIZE(ambBCFile);
			//ALLambBC[ambBCRandom].openFromFile(ambBCFile[ambBCRandom]);

			// RESETS //
			ALLambBC[ambBCRandom].setVolume(0);
			ambBCUpDown = 0;
			ambBCOffOn = 0;

			// PLAY //
			ALLambBC[ambBCRandom].play();
		}
		
		// FADE BA ////////////////////////////////////////////////////////////////
		
		if (ALLambBA[ambBARandom].getStatus() == 2)
		{
			// TRIGGER //

			ambBAFrameCounter++;

			if (ambBAOffOn == 0 && ambBAFrameCounter-300 + (ambMadness-ambBATriggerLevel)*7 + rand()% 200 > 500)
			{
				ambBAOffOn = 1;

				ambBAFadeInSpeed = 300 + (ambMadness-ambBATriggerLevel)*5 + rand()% 200;
				ambBAFadeOutSpeed = 20 + (ambMadness-ambBATriggerLevel)/2 + rand()% 30;

				ambBAPitch = rand() % 100;
				ambBAPitch = ambBAPitch/200+0.75;
				ALLambBA[ambBARandom].setPitch(ambBAPitch*(ambMadness/200)+0.5);
			}

			// FADE IN //

			if (ambBAOffOn == 1 && ambBAUpDown == 0)
			{
				ambBAVolume = ambBAVolume + ambBAFadeInSpeed;

				ambBAIntToFloat = ambBAVolume;
				ambBAIntToFloat = ambBAIntToFloat/100;
				ALLambBA[ambBARandom].setVolume(100*(ambBAIntToFloat*ambBAIntToFloat/100*((ambMadness-40)/100)/100)*(ambMaxVolume/100));

				if (ambBAVolume > 10000)
				{
					ambBAUpDown = 1;
				}
			}

			// FADE OUT //

			else if (ambBAUpDown == 1)
			{
				ambBAVolume = ambBAVolume - ambBAFadeOutSpeed;

				ambBAIntToFloat = ambBAVolume;
				ambBAIntToFloat = ambBAIntToFloat/100;
				ALLambBA[ambBARandom].setVolume(100*(ambBAIntToFloat*ambBAIntToFloat/100*((ambMadness-40)/100)/100)*(ambMaxVolume/100));

				if (ambBAVolume <= ambBAFadeOutSpeed*2)
				{
					ambBAUpDown = 0;
					ambBAOffOn = 0;
					ambBAFrameCounter = 0;
					ambBAVolume = 0;
					ambBAIntToFloat = 0;
					ALLambBA[ambBARandom].setVolume(0);
				}
			}

			// STOP //

			if (ambMadness < ambBATriggerLevel && ALLambBA[ambBARandom].getVolume() == 0)
			{
				ambBAUpDown = 0;
				ambBAOffOn = 0;
				ambBAFrameCounter = 0;
				ambBAVolume = 0;
				ambBAIntToFloat = 0;
				ALLambBA[ambBARandom].setVolume(0);
				ALLambBA[ambBARandom].stop();
			}
		}

		// FADE BB ////////////////////////////////////////////////////////////////
		
		if (ALLambBB[ambBBRandom].getStatus() == 2)
		{
			// TRIGGER //

			ambBBFrameCounter++;

			if (ambBBOffOn == 0 && ambBBFrameCounter-200 + (ambMadness-ambBBTriggerLevel)*7 + rand()% 200 > 400)
			{
				ambBBOffOn = 1;

				ambBBFadeInSpeed = 300 + (ambMadness-ambBBTriggerLevel)*5 + rand()% 200;
				ambBBFadeOutSpeed = 20 + (ambMadness-ambBBTriggerLevel)/2 + rand()% 30;

				ambBBPitch = rand() % 100;
				ambBBPitch = ambBBPitch/200+0.75;
				ALLambBB[ambBBRandom].setPitch(ambBBPitch*(ambMadness/200)+0.5);
			}

			// FADE IN //

			if (ambBBOffOn == 1 && ambBBUpDown == 0)
			{
				ambBBVolume = ambBBVolume + ambBBFadeInSpeed;

				ambBBIntToFloat = ambBBVolume;
				ambBBIntToFloat = ambBBIntToFloat/100;
				ALLambBB[ambBBRandom].setVolume(100*(ambBBIntToFloat*ambBBIntToFloat/100*((ambMadness-40)/100)/100)*(ambMaxVolume/100));

				if (ambBBVolume > 10000)
				{
					ambBBUpDown = 1;
				}
			}

			// FADE OUT //

			else if (ambBBUpDown == 1)
			{
				ambBBVolume = ambBBVolume - ambBBFadeOutSpeed;

				ambBBIntToFloat = ambBBVolume;
				ambBBIntToFloat = ambBBIntToFloat/100;
				ALLambBB[ambBBRandom].setVolume(100*(ambBBIntToFloat*ambBBIntToFloat/100*((ambMadness-40)/100)/100)*(ambMaxVolume/100));

				if (ambBBVolume <= ambBBFadeOutSpeed*2)
				{
					ambBBUpDown = 0;
					ambBBOffOn = 0;
					ambBBFrameCounter = 0;
					ambBBVolume = 0;
					ambBBIntToFloat = 0;
					ALLambBB[ambBBRandom].setVolume(0); 
				}
			}

			// STOP //

			if (ambMadness < ambBBTriggerLevel && ALLambBB[ambBBRandom].getVolume() == 0)
			{
				ambBBUpDown = 0;
				ambBBOffOn = 0;
				ambBBFrameCounter = 0;
				ambBBVolume = 0;
				ambBBIntToFloat = 0;
				ALLambBB[ambBBRandom].setVolume(0);
				ALLambBB[ambBBRandom].stop();
			}
		}

		// FADE BC ////////////////////////////////////////////////////////////////
		
		if (ALLambBC[ambBCRandom].getStatus() == 2)
		{
			// TRIGGER //

			ambBCFrameCounter++;

			if (ambBCOffOn == 0 && ambBCFrameCounter-100 + (ambMadness-ambBCTriggerLevel)*7 + rand()% 200 > 300)
			{
				ambBCOffOn = 1;

				ambBCFadeInSpeed = 300 + (ambMadness-ambBCTriggerLevel)*5 + rand()% 200;
				ambBCFadeOutSpeed = 20 + (ambMadness-ambBCTriggerLevel)/2 + rand()% 30;

				ambBCPitch = rand() % 100;
				ambBCPitch = ambBCPitch/200+0.75;
				ALLambBC[ambBCRandom].setPitch(ambBCPitch*(ambMadness/200)+0.5);
			}

			// FADE IN //

			if (ambBCOffOn == 1 && ambBCUpDown == 0)
			{
				ambBCVolume = ambBCVolume + ambBCFadeInSpeed;

				ambBCIntToFloat = ambBCVolume;
				ambBCIntToFloat = ambBCIntToFloat/100;
				ALLambBC[ambBCRandom].setVolume(100*(ambBCIntToFloat*ambBCIntToFloat/100*((ambMadness-40)/100)/100)*(ambMaxVolume/100));

				if (ambBCVolume > 10000)
				{
					ambBCUpDown = 1;
				}
			}

			// FADE OUT //

			else if (ambBCUpDown == 1)
			{
				ambBCVolume = ambBCVolume - ambBCFadeOutSpeed;

				ambBCIntToFloat = ambBCVolume;
				ambBCIntToFloat = ambBCIntToFloat/100;
				ALLambBC[ambBCRandom].setVolume(100*(ambBCIntToFloat*ambBCIntToFloat/100*((ambMadness-40)/100)/100)*(ambMaxVolume/100));

				if (ambBCVolume <= ambBCFadeOutSpeed*2)
				{
					ambBCUpDown = 0;
					ambBCOffOn = 0;
					ambBCFrameCounter = 0;
					ambBCVolume = 0;
					ambBCIntToFloat = 0;
					ALLambBC[ambBCRandom].setVolume(0);
				}
			}

			// STOP //

			if (ambMadness < ambBCTriggerLevel && ALLambBC[ambBCRandom].getVolume() == 0)
			{
				ambBCUpDown = 0;
				ambBCOffOn = 0;
				ambBCFrameCounter = 0;
				ambBCVolume = 0;
				ambBCIntToFloat = 0;
				ALLambBC[ambBCRandom].setVolume(0);
				ALLambBC[ambBCRandom].stop();
			}
		}

		// IF NOT PLAYING CA /////////////////////////////////////////////////////////
		
		if (ambMadness > ambCATriggerLevel && ALLambCA[ambCARandom].getStatus() == 0)
		{
			// FILE SELECTOR //
			ambCARandom = rand()% ARRAY_SIZE(ambCAFile);
			//ALLambCA[ambCARandom].openFromFile(ambCAFile[ambCARandom]);

			// VOLUME RESET //
			ALLambCA[ambCARandom].setVolume(0);

			// PITCH //
			ambCAPitch = rand() % 100;
			ambCAPitch = ambCAPitch/400+0.87;
			ALLambCA[ambCARandom].setPitch(ambCAPitch);
				
			// PLAY //
			ALLambCA[ambCARandom].play();
		}

		// IF NOT PLAYING CB /////////////////////////////////////////////////////////

		if ( ambMadness > ambCBTriggerLevel && ALLambCB[ambCBRandom].getStatus() == 0)
		{
			// FILE SELECTOR //
			ambCBRandom = rand()% ARRAY_SIZE(ambCBFile);
			//ALLambCB[ambCBRandom].openFromFile(ambCBFile[ambCBRandom]);

			// VOLUME RESET //
			ALLambCB[ambCBRandom].setVolume(0);

			// PITCH //
			ambCBPitch = rand() % 100;
			ambCBPitch = ambCBPitch/400+0.87;
			ALLambCB[ambCBRandom].setPitch(ambCBPitch);
				
			// PLAY //
			ALLambCB[ambCBRandom].play();
		}

		// IF NOT PLAYING CC /////////////////////////////////////////////////////////

		if (ambMadness > ambCCTriggerLevel && ALLambCC[ambCCRandom].getStatus() == 0)
		{
			// FILE SELECTOR //
			ambCCRandom = rand()% ARRAY_SIZE(ambCCFile);
			//ALLambCC[ambCCRandom].openFromFile(ambCCFile[ambCCRandom]);

			// VOLUME RESET //
			ALLambCC[ambCCRandom].setVolume(0);

			// PITCH //
			ambCCPitch = rand() % 100;
			ambCCPitch = ambCCPitch/400+0.87;
			ALLambCC[ambCCRandom].setPitch(ambCCPitch);
				
			// PLAY //
			ALLambCC[ambCCRandom].play();
		}
		
		// VOLUME CA ////////////////////////////////////////////////////////////////

		if (ALLambCA[ambCARandom].getStatus() == 2)
		{
			/*if((ambMadness - ambCATriggerLevel)*(ambMadness/100+1)*0.50*(ambMaxVolume/100)*0.75 >= 50)
				ALLambCA[ambCARandom].setVolume(50);
			else*/
				ALLambCA[ambCARandom].setVolume((ambMadness - ambCATriggerLevel)*(ambMadness/100+1)*0.50*(ambMaxVolume/100)*0.20);

			// STOP //

			if (ambMadness <= ambCATriggerLevel)
			{
				ALLambCA[ambCARandom].stop();
				ALLambCA[ambCARandom].setVolume(0);
			}
		}

		// VOLUME CB ////////////////////////////////////////////////////////////////

		if (ALLambCB[ambCBRandom].getStatus() == 2)
		{
			/*if((ambMadness - ambCATriggerLevel)*(ambMadness/100+1)*0.50*(ambMaxVolume/100)*0.75 >= 50)
				ALLambCB[ambCBRandom].setVolume(50);
			else*/
				ALLambCB[ambCBRandom].setVolume((ambMadness - ambCATriggerLevel)*(ambMadness/100+1)*0.50*(ambMaxVolume/100)*0.20);

			// STOP //

			if (ambMadness <= ambCBTriggerLevel)
			{
				ALLambCB[ambCBRandom].stop();
				ALLambCB[ambCBRandom].setVolume(0);
			}
		}

		// VOLUME CC ////////////////////////////////////////////////////////////////

		if (ALLambCC[ambCCRandom].getStatus() == 2)
		{
			/*if((ambMadness - ambCATriggerLevel)*(ambMadness/100+1)*0.50*(ambMaxVolume/100)*0.75 >= 50)
				ALLambCC[ambCCRandom].setVolume(50);
			else*/
				ALLambCC[ambCCRandom].setVolume((ambMadness - ambCATriggerLevel)*(ambMadness/100+1)*0.50*(ambMaxVolume/100)*0.20);

			// STOP //

			if (ambMadness <= ambCCTriggerLevel)
			{
				ALLambCC[ambCCRandom].stop();
				ALLambCC[ambCCRandom].setVolume(0);
			}
		}
		
		// PLAY D //////////////////////////////////////////////////////////////////////////////
		
		if (ambMadness > ambDTriggerLevel || ambDBeforeAfter == 1)
		{
			ambDCounter++;
			
			// LONG BEEP TRIGGER //

			if (ambMadness >= 100 && ambDB.getStatus() == 0)
			{
				ambDA.stop();
				ambDB.setVolume(ambMaxVolume*0.60);
				ambDB.play();
				ambDBeforeAfter = 1;
				ambDTimer = 0;
			}
			
			// BEFORE BEEP PLAY //

			else if (ambDCounter > 160-((ambMadness*ambMadness)/75) && ambDBeforeAfter == 0 && ambDB.getStatus() == 0)
			{
				ambDCounter = 0;

				ambDA.setVolume((ambMadness-ambDTriggerLevel)*(ambMadness-ambDTriggerLevel)*(ambMaxVolume/100)*0.60);
				ambDA.play();
			}
			
			// AFTER BEEP PLAY //

			else if (ambDB.getStatus() == 0 && ambDCounter > 90 && ambDBeforeAfter == 1)
			{
				ambDCounter = 0;
				ambDTimer++;

				ambDC.setVolume(ambDCVolumeTable[ambDTimer]*(ambMaxVolume/100)*0.4);
				ambDD.setVolume(ambDDVolumeTable[ambDTimer]*(ambMaxVolume/100)*0.4);

				if (ambDBeforeAfter == 1)
				{
					ambDC.play();
					ambDD.play();
				}

				// STOP //

				if (ambDTimer == 11)
				{
					ambDBeforeAfter = 0;
					ambDTimer = 0;
				}
			}
		}
	}