View Issue Details

IDProjectCategoryView StatusLast Update
0004716The Dark ModCodingpublic04.01.2018 05:03
ReporterSpringheel Assigned Tostgatilov  
PrioritynormalSeveritynormalReproducibilityhave not tried
Status resolvedResolutionfixed 
Product VersionTDM 2.06 
Target VersionTDM 2.06Fixed in VersionTDM 2.06 
Summary0004716: "sound" keyword in materials is out of sync
DescriptionI discovered it while trying to create a new entity that is basically a blast of lightning, that works using the sound system for lights. The brightness of the light is controlled by the volume of the sound. I've created a custom sound that is 20 seconds of silence followed by the sound of a blast of electricity.

 

In 2.05, this plays perfectly. The light appears during the blast of sound and nothing is visible during the silence.

 

in 2.06, the light appears several seconds before or after the sound. The two do not sync. If you use Restart Mission from the main menu, the sound is much closer to the light appearing (though still not exactly at the same time).

 

One difference I notice is that the sound does not play during the "Press Attack to Start" window in 2.05. It DOES play during that window in 2.06. I don't know if that's related to the issue, but it seems like a good bet.

Video and testmap at:
http://forums.thedarkmod.com/topic/19162-beta-testing-206/?p=416870
TagsNo tags attached.

Activities

stgatilov

stgatilov

29.12.2017 16:19

administrator   ~0009920

It seems that "sound" keyword no longer uses the actual sound data.
The real sound is played by OpenAL. The material depends on the amplitude data which is fetched in CPU mixing loop. They are somewhat separate now...

When you load the mission from scratch, global sound time starts counting immediately. When the mission is loaded and you see "Press attack", sound decoding starts, but not from the beginning of the sound sample, but from the middle. Perhaps it starts from the moment (global_sound_time modulo sample_length)... You can see where sound sample decoding is by enabling com_showSoundDecoders.

However, the sound itself is played by OpenAL, and it starts playing from the beginning of the sample when "Press attack" screen appears. So it is not synchronized.

I wonder if the problem is present in two slightly different cases:
1. Sound sample is non-looping.
2. Sound is enabled only when player hits a button.
stgatilov

stgatilov

30.12.2017 17:44

administrator   ~0009937

One more thing.
It would be great if someone can test 2.05 version with OpenAL enabled.
stgatilov

stgatilov

30.12.2017 17:57

administrator   ~0009938

Last edited: 30.12.2017 17:58

Ok, I just checked, and here are two interesting facts.

1. The sound DOES play before you "click attack to start" in both 2.05, 2.06 beta, and SVN. Be sure to wait at least 30 seconds if you check it.
2. The issue is perfectly reproduced on 2.05 if you enable OpenAL ("s_useOpenAL 1"), but is not reproducible without OpenAL. In 2.06 beta or SVN we have OpenAL always enabled.

So this is not a code regression, it is not that we broke something in 2.06. It is an inherent problem of the original Doom3 code for the OpenAL case.

The difference is:
No OpenAL: the sound starts playing from its middle, just as it should according to current sound time and channel trigger time
With OpenAL: the sounds starts playing from the beginning, which is not correct, since the offset from channel trigger time and current sound time is not zero when sound starts.

Springheel

Springheel

30.12.2017 20:00

administrator   ~0009941

"In 2.06 beta or SVN we have OpenAL always enabled."

Do you know why that change was made?
stgatilov

stgatilov

31.12.2017 04:03

administrator   ~0009942

The change came from x64 branch with a set of changes from dhewm3. It was done in dhewm3 to remove all OS-specific backends for better platform independence. Also, it may be related to EFX support, although I cannot be sure here.
stgatilov

stgatilov

31.12.2017 06:20

administrator   ~0009943

Looking at idSoundWorldLocal::AddChannelContribution...

There is an "if":
  if ( sound->removeStatus < REMOVE_STATUS_SAMPLEFINISHED )
Strangely, inside this if properly calculated offset is never used.

And there is also an "else" for it, which happens when removeStatus = REMOVE_STATUS_SAMPLEFINISHED. However, it never happens now.
It uses properly calculated offset and it calls some things which are clearly necessary only when OpenAL is NOT used. So I guess that this case is actually for non-OpenAL playback and it is dead now.
stgatilov

stgatilov

31.12.2017 07:03

administrator   ~0009944

Supposedly fixed in revision 7361 (binaries available in 15129).
Please check that it works now.

This change may potentially break some other stuff: in particular, how sounds are synchronized with anything else. This is especially true for ambients, I suppose.
BTW, Is this sound keyword used in any real map?
Springheel

Springheel

31.12.2017 15:01

administrator   ~0009953

The keyword is used in all the flickering electric light entities.

I'll test the fix.
Springheel

Springheel

02.01.2018 17:25

administrator   ~0009961

The fix appears to be working from my preliminary test of the testmap. My build is crashing for other reasons so I wasn't able to do a full test.
stgatilov

stgatilov

03.01.2018 14:58

administrator   ~0009967

Last edited: 03.01.2018 15:16

Is there ANY real FM where synchronization between a sound and a material connected to it is crucial?
I know that test map works, but I think it's better to check on at least one real FM.

On the other hand, I think the issue happens only when the sound in question starts immediately at the beginning of the FM. So it is very unlikely to find any real-world case where issue happens on current 2.06 beta.

Springheel

Springheel

03.01.2018 16:28

administrator   ~0009972

Last edited: 03.01.2018 16:28

As I said, any map using the humming electric light entities will be using this, though it's unlikely players would notice if the flickering of the light wasn't synced with the humming sound, so not really crucial.

I don't know if any maps have used it in other ways--there's no way to know that without looking at the pk4 or asking mappers directly.

Issue History

Date Modified Username Field Change
27.12.2017 21:21 Springheel New Issue
29.12.2017 14:38 Springheel Description Updated
29.12.2017 16:19 stgatilov Note Added: 0009920
30.12.2017 17:44 stgatilov Note Added: 0009937
30.12.2017 17:57 stgatilov Note Added: 0009938
30.12.2017 17:58 stgatilov Note Edited: 0009938
30.12.2017 20:00 Springheel Note Added: 0009941
31.12.2017 04:03 stgatilov Note Added: 0009942
31.12.2017 06:20 stgatilov Note Added: 0009943
31.12.2017 07:03 stgatilov Note Added: 0009944
31.12.2017 07:04 stgatilov Assigned To => stgatilov
31.12.2017 07:04 stgatilov Status new => assigned
31.12.2017 15:01 Springheel Note Added: 0009953
02.01.2018 17:14 stgatilov Assigned To stgatilov => Springheel
02.01.2018 17:14 stgatilov Status assigned => feedback
02.01.2018 17:25 Springheel Note Added: 0009961
02.01.2018 17:25 Springheel Status feedback => assigned
02.01.2018 19:32 nbohr1more Assigned To Springheel => stgatilov
02.01.2018 19:32 nbohr1more Status assigned => feedback
03.01.2018 14:58 stgatilov Note Added: 0009967
03.01.2018 15:16 stgatilov Note Edited: 0009967
03.01.2018 16:28 Springheel Note Added: 0009972
03.01.2018 16:28 Springheel Status feedback => assigned
03.01.2018 16:28 Springheel Note Edited: 0009972
04.01.2018 05:03 stgatilov Status assigned => resolved
04.01.2018 05:03 stgatilov Fixed in Version => TDM 2.06
04.01.2018 05:03 stgatilov Resolution open => fixed