Audio networking, API consistency and 3d sound improvements

I’m excited to announce some upcoming changes to the Sound object.

Capture.PNG

Sound.Playing
A new read/write value that will definitively tell whether the sound is playing or not.
This value is serialized, so it can be set in studio to create a background music or ambience scriptlessly.
This value is replicated, so for any Sound that has been in the workspace any changes will propagate to server and client.
This value will properly work on the server.
IsPaused/IsPlaying will be read-only getters of this value.
This value will bypass FilteringEnabled (this is current behaviour with play/pause/etc). This is used to create a local sound playback immediately that replicates.

Sound.TimePosition
This value now works properly on servers.
This value is now properly replicated among clients and server.
This value is now serialized, so it can be set in studio.

Sound.IsLoaded, Sound.Loaded
Two new properties to determine if the sound is loaded.
Sound.IsLoaded is a read-only boolean (true if loaded, else false)
Sound.Loaded is an event that will fire when the sound is loaded.

Sound.TimeLength
This value now works properly on servers.
This value will be 0 until the sound is loaded. It will not change if an invalid SoundId was set.
This value will be 0 immediately after setting SoundId.

Sound:Play(), Sound:Pause(), Sound:Resume(), Sound:Stop()
These methods will now behave consistently between server and client.
These methods will modify Sound.Playing and Sound.TimePosition.
Sound:Play() will first set the Sound.TimePosition to the last set Sound.TimePosition value (default 0), then set Sound.Playing to true.
Sound:Resume() will set Sound.Playing to true.
Sound:Pause() will set Sound.Playing to false.
Sound:Stop() will first set Sound.Playing to false, then set Sound.TimePosition to 0.

Sound.DidLoop, Sound.Ended, Sound.Paused, Sound.Played, Sound.Stopped
These events should now replicate and fire consistently across server and client.
Only the Play/Pause/Resume/Stop methods will trigger their respective events.

Sound.MinDistance, Sound.MaxDistance
Sound.MinDistance and Sound.MaxDistance will now work properly for “3D sounds” (sounds which are a direct child of a part).
Sound.MinDistance is the minimum distance at which a 3D sound will begin to attenuate. Think of it as the size of the object which is emitting the sound. An airplane would have a large Sound.MinDistance of 100, while a bee would have a small Sound.MinDistance of 0.1.
Sound.MaxDistance is the maximum distance at which a 3D sound can be heard. For 3D sounds outside of the Sound.MaxDistance range, no SoundChannel will be created for them. This value will also affect the 3D attenuation rate per distance.
These values are both still serialized (settable in studio) and replicated across server and client.

These changes should be completely backwards compatible with all existing Sound code.
If you think you do anything interesting/complex/hacky for sounds, I’d highly recommend testing that everything still works.
>>Test build link for dev forum members<<

The wiki will be updated with the new documentation, and expect these changes to be live within a few weeks.

Please let me know if you’ve got any questions or comments!

70 Likes

Was the issue fixed where you couldn’t put a sound in workspace and play it from the client? like create a sound on the client only?

From what you’re describing, sounds like you should be able to do that now. You can test the new API changes here (dev forum member only link).

Sounds awesome!

17 Likes

ScriptOn quality puns.

2 Likes

Hey so right now there is a limit to how many sounds can be played at once. If the sound is playing but is also out of range, will it count towards this limit?

This would imply that sounds out of range do not count towards that limit, since no channel is occupied by them.

Playing 3D sounds outside of MaxDistance range from listener will not create a channel.

You can see this in the test build by opening up the diagnostics window and looking at Sound->ChannelsPlaying.

I’d like to do a bit of channel management work in the near future.

1 Like

Can you make IsLoaded and Loaded for all assets in general? It’d be great to know when an image(or any other asset) loads. I just looked this up on the wiki and didn’t see it anywhere so I assume that it doesn’t exist.

1 Like

That should be in the works.
I know you could check Sound.TimePosition before as a “is loaded?” kind of value, are there other hacks for other asset types?

For decals you can just Preload them using the ContentProvider and when you assign images to a decal/imagelabel/etc, it should appear directly. I don’t think that’s bad practice or hacky, so I personally don’t think image-based objects need an IsLoaded property.

Wouldn’t it be better to add an IsAssetPreloaded method to ContentProvider, instead of adding “Loaded” properties/events to the Sound object, and then have it work for all asset types that can be preloaded? Or is there extra work involved for preparing a sound to be played after it has been downloaded, which warrant a property on the object itself?

3 Likes

Preloading will not always work out well especially if you’re trying to preload many assets. And even so, preloading does not guarantee that it will load quickly.

Yes I would much rather this be the case, instead of having .IsLoaded and .Loaded for every object

I think you are agreeing with me that a “Loaded” event or “IsAssetPreloaded” method on ContentProvider would be useful in that case, since that means you can just preload a bunch of stuff and then use the events/methods to find out if something specific has preloaded (and not just Sounds!). If you think there are problems with ContentProvider it should be reported as a bug (that’s a bit off-topic for this post).

sweet!

not sure if this is related, but my sound says it’s playing, yet its TimePosition and TimeLength both say 0. The length isn’t 0 so I don’t know why it says that.

edit: played a sound in studio and it finished and IsPlaying is still true.

1 Like

Just checking, are you using the test studio link in the other thread?

no, this is online.

none of this stuff is live yet, try the build link here
http://devforum.roblox.com/t/test-new-sound-features-and-make-sure-your-old-code-still-works/26096
and timeposition playback on server should be fixed.

So, even in Filtering, all sounds replicate everywhere?

The only way to make local 3D sounds continues to be bricks in the PlayerGui, correct?

1 Like