Set start time to play sound in A_PlaySound

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

Set start time to play sound in A_PlaySound

Postby Nash » Fri Jun 01, 2018 1:56 pm

As a follow up to my previous request, I'd like a new parameter in A_PlaySound to set the starting time to play the sound from.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Set start time to play sound in A_PlaySound

Postby ZzZombo » Mon Jun 04, 2018 10:22 am

Sorry? Isn't it there you just set the preceding state's duration equal to the desired delay?
ZzZombo
 
Joined: 16 Jul 2012

Re: Set start time to play sound in A_PlaySound

Postby wildweasel » Mon Jun 04, 2018 10:43 am

I suspect Nash is asking for the other way around: not delaying the A_PlaySound, but specifying that the A_PlaySound should start somewhat further in to the sound than from its beginning.
User avatar
wildweasel
change o' pace.
Moderator Team Lead
 
Joined: 15 Jul 2003

Re: Set start time to play sound in A_PlaySound

Postby Nash » Mon Jun 04, 2018 10:46 am

Yeah the whole point is not to delay when the sound starts. But to make it play from a random starting position.

Say you have a long, 1 minute ambient sound loop (played in UI context). Every time you enter the level, the sound keeps playing at the start. You'll eventually recognize the sound patterns and then you'll get sick of hearing it.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Set start time to play sound in A_PlaySound

Postby RockstarRaccoon » Mon Jun 04, 2018 1:58 pm

I'd really like to be able to do this sort of thing for music too, being able to see where it is in one track and starting at the same place in a different track, for things like having multiple versions of a song that switch between each other at certain points...


That said, Nash, I think you should consider having said Ambient sound play differently in different parts...
User avatar
RockstarRaccoon
Totally Babies
 
Joined: 31 Jul 2016

Re: Set start time to play sound in A_PlaySound

Postby Graf Zahl » Mon Jun 04, 2018 3:30 pm

RockstarRaccoon wrote:I'd really like to be able to do this sort of thing for music too, being able to see where it is in one track and starting at the same place in a different track, for things like having multiple versions of a song that switch between each other at certain points...


Most music renderers do not support any fast forwarding to a given position so this is very unlikely.
User avatar
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Set start time to play sound in A_PlaySound

Postby Nash » Sun Dec 23, 2018 12:56 am

This is directed to Chris:

I'm sorry for bumping this, but think you could take a look at this?

I have already tried to do it on my own and maybe help submit a PR but OpenAL is really strange to me.

I did try - I tried to see what the engine is doing with the "load game" code - because I know for sure that loading a game would set the sound position to whatever it was previously at - I thought I could somehow do some copy pasta here and apply the same concept - but no luck so far. :(

Forgive me if I'm wrong but the feature suggestion in the OP - to my inexperienced eyes as least - sounds like something that'll be trivial to do; in fact I was so confident that it is, hence why I tried to do it myself... it's just that I really have no idea how to do anything with OpenAL. :S

If you'd rather not do it, then perhaps you'd be willing to provide me some pointers on where to start looking? I'm comfortable enough with doing my own PRs, after all.

Thanks, and sorry for the bump again.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Set start time to play sound in A_PlaySound

Postby Chris » Sun Dec 23, 2018 10:08 am

This will probably need a bit of work in both the higher and lower level sound code. It's trivial for OpenAL itself, but the OpenAL backend only knows to set a time offset when the sound-to-play comes with a predetermined FISoundChannel, as a result of loading a save game or restarting a sound that got preempted. For it to work with a freshly started sound, you'd need to add another parameter to the SoundRenderer's StartSound and StartSound3D (and MarkStartTime) methods that specifies a start offset (either in samples or (milli/micro)seconds, given the available information and desired precision).

It's the higher level code (src/s_sound.cpp and related places with scripting glue) that I would be completely lost on.
User avatar
Chris
 
Joined: 17 Jul 2003

Re: Set start time to play sound in A_PlaySound

Postby Major Cooke » Wed Jul 24, 2019 1:45 pm

If you can provide the code for OpenAL, I could fulfill the ZScript side of things, now that Nash has brought this up to my attention again. ZScript has a function for getting the length of a sound and returns a double, I don't remember the specifics of it. S_GetLength() I think?
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: Set start time to play sound in A_PlaySound

Postby Chris » Wed Jul 24, 2019 2:16 pm

Major Cooke wrote:If you can provide the code for OpenAL, I could fulfill the ZScript side of things, now that Nash has brought this up to my attention again. ZScript has a function for getting the length of a sound and returns a double, I don't remember the specifics of it. S_GetLength() I think?

The code for setting the source's start offset is already there in OpenALSoundRenderer::StartSound and OpenALSoundRenderer::StartSound3D, when reuse_chan is not null. I'm not 100% convinced this is a good idea though, given that a scripted start offset may not work properly when a sound gets modded, requiring a change to the scripts along with the sound.
User avatar
Chris
 
Joined: 17 Jul 2003

Re: Set start time to play sound in A_PlaySound

Postby Marisa Kirisame » Wed Jul 24, 2019 3:09 pm

Making the start time relative to length (in a range of 0.0-1.0) seems more reasonable then.
User avatar
Marisa Kirisame
ZScript Magician
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: Marisa Kirisame#4689
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Set start time to play sound in A_PlaySound

Postby Nash » Wed Jul 24, 2019 3:10 pm

Marisa Kirisame wrote:Making the start time relative to length (in a range of 0.0-1.0) seems more reasonable then.


Yeah, this makes sense.
User avatar
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Set start time to play sound in A_PlaySound

Postby Major Cooke » Wed Jul 24, 2019 3:58 pm

That's what I was thinking too. What do you think, Chris?
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: Set start time to play sound in A_PlaySound

Postby Chris » Thu Jul 25, 2019 4:31 am

That would probably end up being worse, as the start point would then be affected by any tailing silence or fade out characteristics of the sound, in addition to any internal timing differences. Specifying the offset in time units (floating point seconds, or microseconds or something) I think would have fewer overall issues, and the ones it does have could be more easily corrected by sound authors. It's just that I imagine few sound replacers actually use newly authored sounds and instead are pulling from some other sources where timing issues can't be corrected so easily.
User avatar
Chris
 
Joined: 17 Jul 2003

Re: Set start time to play sound in A_PlaySound

Postby Major Cooke » Thu Aug 01, 2019 9:06 pm

...Okay, I somehow completely missed this part.

Chris wrote:It's just that I imagine few sound replacers actually use newly authored sounds


...Crap. There's no way around this either, at least from attempting to look through the source code. A shame. If there was a way to detect if a sound was played or was a random sound, then it could've been programmed to have the option of skipping the start time positioning, but alas...
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007


Return to Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests