Page 2 of 3

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 4:29 am
by Marisa the Magician
No but I'd love to have that too.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 4:55 am
by Nash
Major Cooke wrote:But can you take a sound and start it off from a position? Should be doable considering you can have LOOP_START data and what not.
I have an open suggestion here and I considered tackling it back there but man, that sound code is just way beyond my simple brain...

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 9:45 am
by Chris
Nash wrote:
Major Cooke wrote:But can you take a sound and start it off from a position? Should be doable considering you can have LOOP_START data and what not.
I have an open suggestion here and I considered tackling it back there but man, that sound code is just way beyond my simple brain...
A more logical problem with that, which I neglected to mention in that thread, is how the definition of the start time is necessarily separate from the sound itself. With LOOP_START, for example, it's embedded in the ogg/flac file comments, so if you mod/replace the file, the loop information changes with it. But a start time/offset will be part of a script the plays the sound, separate from the sound file. If you mod the sound file, and that new sound has different timings, it won't start correctly when given the offset.

I suppose a way around that could be to have custom tag points. So, similar to LOOP_START, the sound file could have something like a user-defined CUSTOM_START tag and a script would say to start the sound at CUSTOM_START instead of specifying the time/offset directly. That way, a modified sound could set its own appropriate start position that matches the effect of the original. This is getting a bit more complicated, though.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 10:12 am
by Major Cooke
Unfortunately that solution wouldn't work for modifying a sound that's already playing. Half life, unreal engine 1, and so one can take the sound while it's still playing and change the pitch right where it's at. I think all it does is start the sound off where it's currently playing again but applies a pitch to it, then override the current one.

Not to mention it'd mean bloating out sound files with needless extra custom tags.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 10:25 am
by Marisa the Magician
The thing about UE1 being able to change pitch of an ambient sound on the fly is actually an interesting case, as it seems the community-made openal sound driver for it couldn't replicate this feature.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 12:15 pm
by Chris
Changing the pitch on the fly wouldn't be difficult at all. Essentially making something like SoundRenderer::ChannelVolume that changes the source's AL_PITCH instead of AL_GAIN, and add a script function that can call it with a playing sound. That latter part is where I get stumped, though.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 12:39 pm
by Major Cooke
If the script part is giving you trouble, I could take a crack at it. Just to make sure, is this code correct?

Code: Select all

void OpenALSoundRenderer::ChannelPitch(FISoundChannel *chan, float pitch)
{
	if (chan == NULL || chan->SysChannel == NULL)
		return;

	alDeferUpdatesSOFT();

	ALuint source = GET_PTRID(chan->SysChannel);
	alSourcef(source, AL_PITCH, clamp<float>(pitch, -7.f, 7.f)); //SNDINFO's limit is this.
}
I know it'll take more than this, such as making it transcend the "Randomize Pitch" option but we'll deal with that after getting it working first.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 12:54 pm
by Chris
Major Cooke wrote:If the script part is giving you trouble, I could take a crack at it. Just to make sure, is this code correct?

Code: Select all

void OpenALSoundRenderer::ChannelPitch(FISoundChannel *chan, float pitch)
{
	if (chan == NULL || chan->SysChannel == NULL)
		return;

	alDeferUpdatesSOFT();

	ALuint source = GET_PTRID(chan->SysChannel);
	alSourcef(source, AL_PITCH, clamp<float>(pitch, -7.f, 7.f)); //SNDINFO's limit is this.
}
Not quite. I'm not sure how SNDINFO defines it, but pitch has to be greater than 0 (it's a linear playback speed multiple). Also, it should account for being underwater, so more like:

Code: Select all

if(WasInWater && !(chan->chanflags&CHAN_UI))
    alSourcef(source, AL_PITCH, max<float>(pitch, 0.0001f)*PITCH_MULT);
else
    alSourcef(source, AL_PITCH, max<float>(pitch, 0.0001f));

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 2:30 pm
by Major Cooke
I've got it covered. I'll make a code submission here in a bit.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 3:07 pm
by Dr_Cosmobyte
Well, at least my idea attracted some interests :p

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 3:55 pm
by Major Cooke
This has been wanted for a looooooong time.

Sound Pitch Setting/Adjusting

Posted: Tue Jul 23, 2019 6:49 pm
by Major Cooke
Pull Request

New function: A_SoundPitch, sets the pitch of a sound. Requires an actor.
S_Sound + A_PlaySound: New pitch parameter. Overrides randomized pitches! As long as the pitch value > 0.0.

This submission was crafted with Chris' help.

While S_Sound can set the starting pitch, there's no way possible to modify the sound since it's not spawned by an actor, and ZScript doesn't have sound channels as variables.

@Graf: If you're wondering, making another wrapper was not an option, unless you wanted me to modify every other call of S_Sound, and there are MANY. The least I could do is give them a different name instead of making them even more overloaded functions that clogs shit up.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 6:50 pm
by Major Cooke

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 6:56 pm
by Dr_Cosmobyte
Cooke, let me understand; is this A_SoundPitch compatible with DECORATE? And, (I'll give a second look to avoid asking obvious questions) what's the current syntax of this command? Similar to the one i submitted?

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Posted: Tue Jul 23, 2019 7:01 pm
by Major Cooke
Feel free to ask in that thread directly from here on out.

Yes, it's compatible. It's just A_SoundPitch(channel, pitch). 1.0 is standard pitch.