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

Sound: get/set playback timeline position #7835

Open
8bitskull opened this issue Jul 26, 2023 · 8 comments
Open

Sound: get/set playback timeline position #7835

8bitskull opened this issue Jul 26, 2023 · 8 comments
Labels
engine Issues related to the Defold engine feature request A suggestion for a new feature sound Issues related to sound handling

Comments

@8bitskull
Copy link
Sponsor

I would like to be able to get and set the timeline positions of sounds in Defold.

Use case:
We have three intensity variations of a music track. At certain points in the track, we check if we want to switch to another intensity level. The variations are not mapped 1:1 in terms of duration and position, so for example if we're at 00:12 of one track we might want to switch to 00:23 for the other.

For get, I would expect something like:

go.get("#sound", "timeline_position")

You could do a workaround for the get side by tracking time elapsed since you started the track. I've tried this before, but do not find it to be a reliable solution. I can not think of a workaround for the set side.

For set, I would expect something like:

go.set("#sound", "timeline_position", 23.7)

However, for my use case it would also be acceptable if the timeline position is set on play (similar to the offset parameter in sprite.play_flipbook).

I've looked around for similar functions elsewhere: FMOD (get / set), Unity (both), Godot (seemingly only get)

@8bitskull 8bitskull added the feature request A suggestion for a new feature label Jul 26, 2023
@JCash
Copy link
Contributor

JCash commented Jul 26, 2023

Are you talking about the next "start" position, or the position for an active voice? (Remember you can play a sound multiple time, and each will spawn a voice)

@8bitskull
Copy link
Sponsor Author

8bitskull commented Jul 26, 2023

I'm not intimately familiar with the sound API, but it doesn't seem like we ever really interact with specific voices? E.g. you can only stop all voices at the same time, not a specific one.

I think setting the timeline position of the next voice (e.g. doing it on play, like the sprite offset parameter) would be fine for my use case I think. I wouldn't be playing multiple voices of the same sound anyway when we're talking about music tracks.

@britzl
Copy link
Contributor

britzl commented Jul 26, 2023

I think it makes sense to have start_time or similarly named argument added to the play properties:

sound.play("#mysound", { start_time = 0.5 })

Changing timeline_position or similar on the sound component using go.set() would set it for future calls to sound.play(), not for already playing voices. Not sure how useful that would be?

@8bitskull
Copy link
Sponsor Author

start_time as an argument to the play properties sounds perfect to me. I can't imagine when it would be useful to set it for future calls (not to say there isn't a use case for it, just I don't see one).

@britzl britzl added engine Issues related to the Defold engine sound Issues related to sound handling labels Aug 8, 2023
@Insality
Copy link
Sponsor

Agree, have the same issue

I have a different parts of music which should be player in different game moments and for easier management and music creation I want to keep one music file

It would be cool if it will able to set start time on sound.play or while playing sound

@stevencodeuk
Copy link

stevencodeuk commented May 17, 2024

Would also love the ability to get the playback position of an active sound to allow me to implement fades.

Being able to query the length of a sound would be great too.

@britzl
Copy link
Contributor

britzl commented May 21, 2024

Would also love the ability to get the playback position of an active sound to allow me to implement fades.

This is more complicated since you can have multiple voices playing the same sound. The sound.play() is fire and forget and you do not get a handle or anything back that you can use at a later time to get the current position. So in order to solve this we need to return a voice handle to the user and then a new function to query the voice position. This is further complicated by the fact that sounds are mixed and played on a thread so you need to interrupt the thread to get the position.

Being able to query the length of a sound would be great too.

I suppose this is mainly useful if you can also query for the current playback position?

@stevencodeuk
Copy link

I suppose this is mainly useful if you can also query for the current playback position?

It would be, yes.

For my usage, I have a soundtrack manager, with a playlist of three loopable tracks, and knowing when a track is coming near to the end to fade it out and fade in the next would be useful. I can't edit the tracks together as the last track would end abruptly.

Currently I'm using the track length, and tracking the play time in Update, so hopefully this hacky way is accurate :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine Issues related to the Defold engine feature request A suggestion for a new feature sound Issues related to sound handling
Projects
None yet
Development

No branches or pull requests

5 participants