Sound properties (SOLVED)

#1

Following sprite properties, sound component should also have its properties like gain, pan, pitch that can be animated using go.animate("#sound", ...) without workarounds.

4 Likes

#2

Given the sound component is more like a factory, spawning voices (instances) of a sound, (each having separate initial properties):

#sound voice 1: gain1, pan1, speed1
#sound voice 2: gain2, pan2, speed2

Currently, the msg.post("#sound", "set_gain", ...) works on all playing voices of that sound component.
The same mechanic would then go into the go.animate("#sound", "gain"), addressing all voices.

I assume this is what you mean though, the same functionality as the “set_gain”, but without the need to manually set the values each frame ?

2 Likes

#3

Yeah, exactly, animating:

sound.play("#sound")
sound.set_gain("#sound", 0)
go.animate("#sound", "gain", go.PLAYBACK_ONCE_FORWARD, 1, go.EASING_INOUTSINE, 3)

should cause the sound that is playing to fade in. For now it’s causing an error:

ERROR:SCRIPT: /main/test.script:4: '193[main:/go#sound]' does not have any property called 'gain'
stack traceback:
	[C]: in function 'animate'
	/main/test.script:4: in function </main/test.script:1>

Currently we have only a workaround to this: sound.set_gain()/msg.post("#sound", "set_gain",...) either with a timer or in update().

I don’t understand one thing in this:

Currently one sound component can have only one Sound property, so why you’re highlighting “on all playing voices”?

0 Likes

#4

Because you can play the sound multiple times, simultaneously.
Documentation: play_sound

1 Like

#5

What about the error when animating its property? I still didn’t manage to animate sound’s gain, nor pan, nor even speed with go.animate(). Is there any feature request to allow it ongoing?

0 Likes

#6

This should have been released already. We are investigating.

1 Like

#7

You can use go.animate() but the sound must be playing, which means that you need to delay the go.animate() call.

Added https://github.com/defold/defold/issues/4725 to investigate and possibly fix this.

3 Likes

#8

Thanks for looking into this! :wink:
(and still no access to issues :frowning: )

0 Likes

#9

We know. We will be able to provide a single unified issue list just a couple of weeks. And these links will work then.

2 Likes

#10

Even after a sound started playing, it is not possible:

ERROR:SCRIPT: /main/sound.script:4: '192[main:/go#sound]' does not have any property called 'gain'
stack traceback:
	[C]: in function 'animate'
	/main/sound.script:4: in function </main/sound.script:3>

I’m attaching a simple repro:

Empty Project.zip (9.3 MB)

1 Like

#11

It’s working in this example: https://defold.com/examples/sound/fade_in_out/

You can’t make the call to play and then immediately animate. You must let the call to play process first. Either animate after a msg.post or timer.delay(0

1 Like

#12

First of all, either downloaded or pulled project with those examples is not working for me (tried several times), because several files appears to be damaged :frowning:

Secondly, I can’t play the sound from my examples even with the code provided in that example (I changed name of sound to music), because of the same reason:

ERROR:SCRIPT: /main/sound.script:11: '22[main:/go#music]' does not have any property called 'gain'
stack traceback:
	[C]: in function 'animate'
	/main/sound.script:11: in function </main/sound.script:9>

In my code, there is also a timer of 2 seconds after sound.play(), so I’m sure the music is playing, but I can’t animate its gain :confused:

0 Likes

#13

Ok - updating to 1.2.166 instantly solved this problem

1 Like