ambience sounds fade in/out

Posted By: CodeMaster

ambience sounds fade in/out - 12/16/12 10:49

i need idea how create a code that will play ambience sounds when the player approaches, such as rivers, burning fire, waterfalls, and of course, when a player is moving away then the volume decreases. All this i have connect later with the master volume variable
Posted By: MasterQ32

Re: ambience sounds fade in/out - 12/16/12 10:51

just take a look at ent_playsounnd and ent_playloop
Posted By: 3run

Re: ambience sounds fade in/out - 12/16/12 10:58

This looks so awful, when people ask something simple as this without even reading the fucking manual by themselves (or doing tutorials). And I hate to realize, that once upon a time, I was doing this myself.. There is nothing have to deal with master volume! (as it is master, it will decrease the volume of the whole game!), all you need to use is "ent_playsound" (and probably "ent_playloop"), read the manual for such simple stuff please, if you want to learn anything:
ent_playsound ( ENTITY*, SOUND*, var volume): handle
As if this isn't what you want (for example you need rain sound, which will fade in slowly, and then play with constant volume), you need to do something like this:
Code:
var rain_handle_snd = 0; // pointer to the rain sound
var rain_volume_snd = 0; // volume of the rain sound

SOUND* rain_wav = "rain.wav"; // rain sound file itself

function handle_rain(){
	// play rain sound in a loop:
	rain_handle_snd = snd_loop(rain_wav, 0, 0);
	// endless while loop:
	while(1){
		// if we need to increase it:
		if(rain_volume_snd < 50){
			// then increase it:
			rain_volume_snd += 2 * time_step;
		}
		// tune the volume of the rain:
		snd_tune(rain_handle_snd, rain_volume_snd, 0, 0);
		// wait one frame:
		wait(1);
	}
}

Posted By: CodeMaster

Re: ambience sounds fade in/out - 12/16/12 11:38

3run i think you not understand me, code you gave me is really simple but this is not what i need. Just imagine that we have a river in level and when the player gets closer to the river, volume begin increases, but only for the value of what a player is away from the river. The same thing happens when we turn away from the river. I was trying to find the right formula something like 100 - distance_player_of river = river_current_sound, and later this current sound i need to change in game/volume options.
I don't know how other peoples solve this problem, i know there are a wed sounds, but i think this can't help?
Posted By: MasterQ32

Re: ambience sounds fade in/out - 12/16/12 12:01

i don't understand your problem
the code 3run posted does exactly what you want to hear
Posted By: 3run

Re: ambience sounds fade in/out - 12/16/12 12:10

CodeMaster@ you don't need to recreate bicycle once again, as it already exist. Use "ent_playloop", with the pointer to your river.
Posted By: CodeMaster

Re: ambience sounds fade in/out - 12/16/12 12:11

did you see in 3run code that rain_volume_snd all time goes up if is above 50? when player stop moving, volume decrease/increase must stop
Posted By: 3run

Re: ambience sounds fade in/out - 12/16/12 12:15

CodeMaster@ would you please stop trolling and take a look at ent_playloop already?? All you need to do is simple this!
Code:
action fucking_river(){
     ent_playloop(my, river_fucking_sound, 500); // play with 500 
}

Attach this action to your RIVER (or whatever) and you are good to go.
Posted By: Harry Potter

Re: ambience sounds fade in/out - 12/16/12 12:35

Originally Posted By: MasterQ32
i don't understand your problem
the code 3run posted does exactly what you want to hear
I think the problem is that he wants to use ent_playloop or ent_playsound for a VERY LONG entity (e.g. a river).
He could place some dummy entities along the river - each of them playing an ambient sound. But then the sound will not be constant when walking along the riverside.

I think the problem is:
When using ent_playsound or ent_playloop the audio source is point-like, and can not be a whole surface.

Posted By: CodeMaster

Re: ambience sounds fade in/out - 12/16/12 12:42

yes right!
Posted By: 3run

Re: ambience sounds fade in/out - 12/16/12 12:47

Harry Potter@ you can place a path above that river, and make entity with "ent_playloop" move on the path, with player, there is no need to make a bunch of entities, which will play all those ambiance sounds.

CodeMaster@ I'm happy that it was useful, but please take a look at the manual some times.
Posted By: Harry Potter

Re: ambience sounds fade in/out - 12/16/12 12:50

Originally Posted By: 3run
you can place a path above that river, and make entity with "ent_playloop" move on the path, with player, there is no need to make a bunch of entities, which will play all those ambiance sounds.
Yes, that's a good idea.
© 2024 lite-C Forums