Vurv78 / WebAudio

A safe, efficient and powerful replacement for Streamcore that adds playing & manipulating URL streams through IGmodAudioChannel/BASS
https://steamcommunity.com/sharedfiles/filedetails/?id=2466875474
MIT License
18 stars 3 forks source link

Change handling of webaudio radius & volume #14

Closed Vurv78 closed 3 years ago

Vurv78 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

ghost commented 3 years ago
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 commented 3 years ago

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

Vurv78 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

ghost commented 3 years ago

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