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

NPC mouth issue #35

Open
BlackShadow opened this issue Jul 22, 2021 · 3 comments
Open

NPC mouth issue #35

BlackShadow opened this issue Jul 22, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@BlackShadow
Copy link

NPC's doesn't move their mouth when high quality sound file used.

@LAGonauta
Copy link
Owner

Would it be possible to upload a sample for testing?

@BlackShadow
Copy link
Author

There you go:

https://streamable.com/mn2gv2

If you don't use Half-Life's standard Mono WAV files, this happens

@hzqst
Copy link
Contributor

hzqst commented Jul 23, 2021

First of all,

This is because vannila GoldSrc handles mouth movement in S_MixChannelsToPaintbuffer (basically where GoldSrc paint raw wave data into paintbuffer and finally transfer them into DirectSound output driver) and call SND_MoveMouth while voicing.

However MetaAudio never paints or mix sound channel by itself (it is all done by Alure software driver) so nothing goes into S_MixChannelsToPaintbuffer.

void S_MixChannelsToPaintbuffer(...){
//...
if (ch->entchannel == CHAN_STREAM || ch->entchannel == CHAN_VOICE)
							SND_MoveMouth(ch, sc, count);
//...
}

And modify mouth controller for current entity according to the voice volume.

void SND_MoveMouth(channel_t *ch, sfxcache_t *sc, int count)
{
	int data;
	signed char *pdata;
	int i;
	int savg;
	int scount;
	cl_entity_t *pent;

	pdata = (signed char *)sc->data + ch->pos;
	i = 0;
	scount = cl_entities[ch->entnum].mouth.sndcount;
	savg = 0;
	pent = &cl_entities[ch->entnum];

	while (i < count && scount < CAVGSAMPLES)
	{
		data = pdata[i];
		savg += abs(data);

		i += 80 + ((byte)data & 0x1F);
		scount++;
	}

	pent->mouth.sndavg += savg;
	pent->mouth.sndcount = (byte)scount;

	if (pent->mouth.sndcount >= CAVGSAMPLES)
	{
		pent->mouth.mouthopen = pent->mouth.sndavg / CAVGSAMPLES;
		pent->mouth.sndavg = 0;
		pent->mouth.sndcount = 0;
	}
}

How to fix :

We can iterate every stream/voice channel in channel_manager and simulate the SND_MoveMouth with volume from Alure driver instead of stupid raw bytes calculation i += 80 + ((byte)data & 0x1F);

@LAGonauta LAGonauta added the bug Something isn't working label Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants