Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change handling of webaudio radius & volume #14

Merged
merged 7 commits into from
May 1, 2021
Merged

Change handling of webaudio radius & volume #14

merged 7 commits into from
May 1, 2021

Conversation

Vurv78
Copy link
Owner

@Vurv78 Vurv78 commented May 1, 2021

Fixes #13, also made the maximum radius and volume settings much more relaxed at 3x volume and 10,000 source units distance radius. If you want it lower, just set your server or client's convars.

Fixes #13, also made the maximum radius and volume settings much more relaxed at 3x volume and 10,000 source units distance radius. If you want it lower, just set your server or client's convars.
@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

Can you test if this works fine for you? @RanchTheDeer
I buffed the default convars as well since the server and client can always change the settings themselves

@ghost
Copy link

ghost commented May 1, 2021

For me, these changes cause the stream to play with no volume whatsoever
With a little debugging and printing some values, I get the following:

Stream volume setting: 	0.41535366210937
Vars:
Stream volume: 	1
Distance to stream: 	2923.2316894531
Stream radius: 	5000

As I get further away from the stream, the Distance to stream actually increases. Whether that's because the stream's origin is being placed at an arbitrary position rather than where the stream should actually start, or whether the function is somehow inverted from what it should be, I'm not sure.
Edit: I believe I have worked out the problem.
When I get closer to the arbitrary position of the stream's origin (which seems to bear no correlation to what should be the origin), these are the settings I get:

Vars:
Stream volume: 	1
Distance to stream: 	169.76853942871
Stream radius: 	5000

And I am now able to hear the sound, and it fades away correctly with distance from the origin.
Something must be wrong in the position that the sound gets to play from, because it does not start at the center of the stream's parent.

Edit 2: If (what is set to be) the stream's parent moves, the sound does move relative to the parent, though is still at a weird position in the sky.

Edit 3: Here's the output of a few of the used positional parameters:

stream.parent_pos: 	-1018.408691 383.391968 12285.219727
Pos: 	-971.442261 146.368134 -6.260397

The stream.parent_pos does not change if the stream's parent is moved, however pos does.

Edit 4: I have resolved the problem. In wa_receiver.lua, line 27, changing:
local pos = parent:LocalToWorld(stream.parent_pos)
to
local pos = parent:GetPos()
resolves the issue.
I have tried setting it to local pos = stream.parent_pos but that does not work. There appears to be an issue with the way stream.parent_pos is set, as it does not change when the parent is actually moved and is set to a position nowhere near the stream's actual parent position.

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

You're most likely using setPos at the same tick of setParent, which results in the stream being parented to the object local to the stream's set position. This is expected behavior

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

Either don't set the position of the stream at all before parenting it or set it to the parent's position in the same tick if you want that normal behavior

@ghost
Copy link

ghost commented May 1, 2021

I'm not using setPos at all in my code, as it should not be required when setting the parent of the stream. Simply setting the parent and then starting the stream should be sufficient to set the correct origin.

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

Could you give a code snippet or something? And are you on singleplayer? Cause I still haven't debugged any behaviors for that..

@ghost
Copy link

ghost commented May 1, 2021

if(webAudioCanCreate(S))
        {
            TimeIncrement = 1000
            PlaybackRate = 1
            WebAudio = webAudio(S)
            WebAudio:setParent(TargetEntity)
            WebAudio:setRadius(2000)
            WebAudio:play()
            WebAudio:setVolume(Volume)
            WebAudio:setPlaybackRate(PlaybackRate)
            WebAudio:update()
            timer("playNext_1", 100)
        }

I'm running on singleplayer, yes.
I'd really expect SetParent to set the parent position to the center of the entity it's parented to, and for setPos to be optional rather than required. Perhaps some clarification is required in the documentation if this is not the case.

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

It's not required, I said don't set the position of the stream at all before parenting it in my last message

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

Ok it's meant to not be required but apparently the code wasn't working my bad, didn't notice I had a setPos in there that basically set it to the same position at the prop to parent to. brilliant

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

Ugh, it was because at some point I made self.pos initialize as Vector() instead of nil as it initially was meant to be. Documented it so I don't make the mistake again

@Vurv78
Copy link
Owner Author

Vurv78 commented May 1, 2021

Thanks for the report, think it's all good now 👍

Vurv78 added 3 commits May 1, 2021 13:54
Don't set parent_pos if we want to be at the parent prop's position. Avoids constant matrix math.
@ghost
Copy link

ghost commented May 1, 2021

Current revision of code now behaves as expected; parenting the stream now works correctly and without issue.

@Vurv78 Vurv78 merged commit d48cf3c into main May 1, 2021
@Vurv78 Vurv78 deleted the think-changes branch May 1, 2021 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Last update (#12) causes streams to be too quiet & range does not work
1 participant