ent_playsound on moving entities

Posted By: painkiller

ent_playsound on moving entities - 12/21/16 16:06

well, I want to play sounds for the characters using ent_playsound instead of snd_play, for example for footsteps, weapons and so on. Right after starting the game, where the player it's on its original position the sound plays fine. However, if I move the character, for example to x=800, sounds can barely be heard. as you get farther from the original position the volume will get lower unitl you can't heard it.

According to the manual ent_playsound "Plays a 3D sound at the current position of the given entity". However, it looks like when you call ent_playsound it uses the entity original position instead of the current one.

Has anyone else noticed this behaviour?
Posted By: 3run

Re: ent_playsound on moving entities - 12/21/16 16:23

I never noticed anything like that.. works pretty good for me. How many view do you have? Cause (as far as I know) there should be only one with flag AUDIBLE set on. Maybe there is a view, which doesn't move with the entity?

Greets!
Posted By: painkiller

Re: ent_playsound on moving entities - 12/21/16 17:55

Originally Posted By: 3run
I never noticed anything like that.. works pretty good for me. How many view do you have? Cause (as far as I know) there should be only one with flag AUDIBLE set on. Maybe there is a view, which doesn't move with the entity?

Greets!


I'm using only the default camera view, so that shouldn't be a problem. Maybe Shade-c EVO or PhysX causes it? I think I used ent_playsound in the past and didn't have those issues
Posted By: 3run

Re: ent_playsound on moving entities - 12/21/16 18:14

Probably the only way is going to be split project and add it piece by piece till problem occurs. Have you tried making simple example with one model playing sound?
Posted By: painkiller

Re: ent_playsound on moving entities - 12/21/16 18:32

I think it's related somehow to shade-c evo. If I disable it then ent_playsound works fine
Posted By: 3run

Re: ent_playsound on moving entities - 12/21/16 18:39

If it's related to shade-c evo, then probably rayp or Reconnoiter could help here, since they have good experience with it.
Posted By: rayp

Re: ent_playsound on moving entities - 12/21/16 22:25

This is up to a windows setting iam pretty sure.
Go to audio settings and disable/uncheck things like sound boost/optimization ( sry dont know the proper names of the settings right now ).
i once had a similar prob (sounds played in a loop startet quiet and became louder and louder)and unchecking those things solved it. U could try that but i dont know if it helps in this case to be honest.
Posted By: painkiller

Re: ent_playsound on moving entities - 12/22/16 10:49

I don't have any special settings set on windows audio settings. The problem only seems to appear when using shade-c evo.

I've searched through all shade-c files and every created view has its AUDIBLE flag reset except for screen.views.gBuffer on sc_gBuffer.c line 46. However, changing it to reset doesn't seem to fix it neither.
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/22/16 12:03

Perhaps its related to the variable doppler_factor? It sounds like that anyway. If that isn't it, it could perhaps be that Shade-c has a similar kind of variable that is experimental or such (would have to dig in the scripts though).

-edit, or it might be related to physx or such in the sense that the xyz coordinates that ent_playsound uses it perhaps not updated automatically. Try updating the xyz values manually too.
Posted By: painkiller

Re: ent_playsound on moving entities - 12/22/16 12:18

Originally Posted By: Reconnoiter
Perhaps its related to the variable doppler_factor? It sounds like that anyway. If that isn't it, it could perhaps be that Shade-c has a similar kind of variable that is experimental or such (would have to dig in the scripts though).

-edit, or it might be related to physx or such in the sense that the xyz coordinates that ent_playsound uses it perhaps not updated automatically. Try updating the xyz values manually too.


I've tried to change doppler_factor and look for it on shade-c files but no luck.

xyz coordinates shouldn't be a problem I think, as I'm attaching the camera to the entity using them and that works fine.
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/22/16 12:33

I just tried it and for me ent_playsound works as it should ent_playloop(my, beep_snd, 100); or ent_playsound(my, beep_snd, 100); in a loop.

Are you sure you haven't accidently attach the sound to an other object that you forget / or dont move?

ps: I use both Shade-C evo and physx
Posted By: painkiller

Re: ent_playsound on moving entities - 12/22/16 13:04

Originally Posted By: Reconnoiter
I just tried it and for me ent_playsound works as it should ent_playloop(my, beep_snd, 100); or ent_playsound(my, beep_snd, 100); in a loop.

Are you sure you haven't accidently attach the sound to an other object that you forget / or dont move?

ps: I use both Shade-C evo and physx


if you move the entity the sound plays at its new position?

I just play them from the entity's action
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/22/16 13:42

Yes I move the entity with pXent_move. Also tried several sounds simultaneously. (from entity's action)
Perhaps your camera/view settings are different or such.
Posted By: painkiller

Re: ent_playsound on moving entities - 12/22/16 20:26

Originally Posted By: Reconnoiter
Yes I move the entity with pXent_move. Also tried several sounds simultaneously. (from entity's action)
Perhaps your camera/view settings are different or such.


In my case I move it using forces, not sure if that would make a difference
Posted By: painkiller

Re: ent_playsound on moving entities - 12/23/16 10:47

I've uploaded a small demo based on the shade-c examples showing the problem: http://www.mediafire.com/file/v3bktj65kwn8pld/sound_test.zip
You can move the player with wasd and mouse and play sound with e key.

On my computer on the origin position the sound plays fine, however if I move the player the volume gets lower like if the sound is still played at the origin position.
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/23/16 11:49

Hey painkiller, I did some tests. I also didn't get any sounds with your script at far distance. The only thing I can think of now is indeed that the force function is the problem, but only the function(s) it seems. Cause e.g. if I move rigid objects (with an attached sound loop) with my character controller they continue to make sounds. So my quess is that its a bug with the physx force function.

-edit: a possible solution might be either just a dummy entity that you move normally with the player and play the sounds on it, or use snd_play and based on distance to camera calculate the right volume.

Merry Christmas
Posted By: painkiller

Re: ent_playsound on moving entities - 12/23/16 12:23

hmm this is strange. If I attach a dummy entity to the player or camera it moves with it as it should but the sound problem is still there.

Also tried to change the type to PH_CHAR and use pXent_move but the bug happens also.

ent_playloop seems to move with the entities, but ent_playsound stays at the entity's original position.

using snd_play and changing the volume depending on the position would work, but would loose 3d sounds advantages, for example knowing if an enemy comes from the left or right side.

Merry christmas to you too!
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/23/16 12:57

I tried your sound + setting the player in my script as rigid + adding this to its action pXent_addforcecentral(me, vector(0,-200,200)); , and the sounds kept working until I commented the original move function out. So perhaps try adding a dummy pXent_move call so something gets updated correctly(?).
Posted By: Superku

Re: ent_playsound on moving entities - 12/23/16 13:14

Originally Posted By: painkiller
using snd_play and changing the volume depending on the position would work, but would loose 3d sounds advantages, for example knowing if an enemy comes from the left or right side.

You can do that yourself too though, for example as follows (untested, just the idea):

vec_diff(temp,ent.x,camera.x);
temp.z = 0;
vec_normalize(temp,1);
vec_set(temp2,vector(0,-1,0));
vec_rotate(temp2,vector(camera.pan,0,0)); // pan alone should be enough, right?
var balance = vec_dot(temp,temp2)*100;
snd_tune(...,balance);

If the result is super wrong, I'd start with DEBUG_VARing the vec_dot result.
Posted By: painkiller

Re: ent_playsound on moving entities - 12/23/16 13:42

Originally Posted By: Reconnoiter
I tried your sound + setting the player in my script as rigid + adding this to its action pXent_addforcecentral(me, vector(0,-200,200)); , and the sounds kept working until I commented the original move function out. So perhaps try adding a dummy pXent_move call so something gets updated correctly(?).


I think that doesn't seem to work, at least on my computer. I tried to add a pXent_move call but still got the problem. Did you try it on the demo I uploaded?

Code:
pXent_move(me,vector(0,0,0.1),nullvector);
		
		vec_set(player_move_vec,nullvector);
		vec_set(player_move_vec,vector(key_w-key_s,key_a-key_d,0));
		vec_normalize(player_move_vec,0.975*time_step);
		vec_rotate(player_move_vec,vector(my.pan,0,0));
		
		pXent_addforcecentral(me, player_move_vec);
		
		pXent_move(me,vector(0,0,-0.1),nullvector);



Originally Posted By: Superku
Originally Posted By: painkiller
using snd_play and changing the volume depending on the position would work, but would loose 3d sounds advantages, for example knowing if an enemy comes from the left or right side.

You can do that yourself too though, for example as follows (untested, just the idea):

vec_diff(temp,ent.x,camera.x);
temp.z = 0;
vec_normalize(temp,1);
vec_set(temp2,vector(0,-1,0));
vec_rotate(temp2,vector(camera.pan,0,0)); // pan alone should be enough, right?
var balance = vec_dot(temp,temp2)*100;
snd_tune(...,balance);

If the result is super wrong, I'd start with DEBUG_VARing the vec_dot result.


That's a good idea, I will take a look at it. Thanks superku
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/23/16 14:21

Originally Posted By: painkiller
I think that doesn't seem to work, at least on my computer. I tried to add a pXent_move call but still got the problem. Did you try it on the demo I uploaded?
, I tried it many times but I cannot get it working in your script. I do know there is a lot of differences between our scripts, but mine is getting quite big so it could be alot of things. If Superku's solution doesn't work out you could take a look at 3run's physx code on this forum, I used that as a base for the physx parts of my script. Probably some variable is different
Posted By: painkiller

Re: ent_playsound on moving entities - 12/23/16 16:08

Originally Posted By: Reconnoiter
Originally Posted By: painkiller
I think that doesn't seem to work, at least on my computer. I tried to add a pXent_move call but still got the problem. Did you try it on the demo I uploaded?
, I tried it many times but I cannot get it working in your script. I do know there is a lot of differences between our scripts, but mine is getting quite big so it could be alot of things. If Superku's solution doesn't work out you could take a look at 3run's physx code on this forum, I used that as a base for the physx parts of my script. Probably some variable is different


hmm in your code based on the 3run's demo you are using shade-c evo, aren't you? because I think that is related.

Anyway this is very strange indeed. I think I will use Superku solution for now as this is getting me a bit crazy, I've tested it also changing the volume depending of the distance and works fine. Thanks for the help wink
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/23/16 20:24

Yes I use shade-c evo, glad to be of help (even though it didn't solve the weird problem).
Posted By: 3run

Re: ent_playsound on moving entities - 12/23/16 21:17

After playing for a while with your demo (painkilled), I found out that evil comes from sc_setup (just comment it in main and you'll see that sound works correctly), at the end I could only strip down your demo to this functions:
Quote:
sc_materials_init();
sc_gBuffer_init(screen, SC_GBUFFER_DEFERRED, screen.settings.bitdepthGBuffer);
sc_deferredLighting_init(screen, 1, screen.settings.bitdepthLBuffer);
sc_forward_init(screen, SC_FORWARD_PASSTHROUGH); // option 2
They are called in sc_setup(SC_SCREEN* screen) (wrapper.c), seems that problem is in one of them.. I played a little bit with views in those files, but with no luck.

Greets
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/23/16 21:36

Bingo, with 3run's post I found the problem, do this:

sc_screen_default.settings.forward.enabled = 1;

Seems that the deferred pipeline was the culprit. So that is why the sounds worked in my script cause I turned it off already so particles would work in my script.

Posted By: 3run

Re: ent_playsound on moving entities - 12/23/16 21:53

Team-play! grin
Posted By: Reconnoiter

Re: ent_playsound on moving entities - 12/23/16 21:58

JCL would have been proud grin
Posted By: painkiller

Re: ent_playsound on moving entities - 12/27/16 17:10

wow thanks Reconnoiter and 3run!! setting forward renderer to 1 solved the problem indeed
Posted By: txesmi

Re: ent_playsound on moving entities - 12/29/16 06:08

Hi,
looking to the solution it could have something to do with the AUDIBLE view flag set or missing on the main camera or one of the renderer view chains...

Salud!
Posted By: painkiller

Re: ent_playsound on moving entities - 12/29/16 11:04

Originally Posted By: txesmi
Hi,
looking to the solution it could have something to do with the AUDIBLE view flag set or missing on the main camera or one of the renderer view chains...

Salud!


I tried to find issues with the AUDIBLE flag but I didn't find anything wrong in the shade-c code.
Posted By: 3run

Re: ent_playsound on moving entities - 12/29/16 19:43

Originally Posted By: painkiller
Originally Posted By: txesmi
Hi,
looking to the solution it could have something to do with the AUDIBLE view flag set or missing on the main camera or one of the renderer view chains...

Salud!


I tried to find issues with the AUDIBLE flag but I didn't find anything wrong in the shade-c code.
Yep, same here.
© 2024 lite-C Forums