Pitch tuning in A_PlaySound/A_PlaySoundEX

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: Pitch tuning in A_PlaySound/A_PlaySoundEX

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Major Cooke » Wed Jul 24, 2019 10:27 am

Alright.

@Graf: Chris has completed his work. And I've squashed it down into one commit so it's clean.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Rachael » Wed Jul 24, 2019 8:59 am

Oh also obviously - if you do make a pull request, make sure to remind us in your post to please move it to the code submissions section. ;) Moderators can do it too, so reporting it is fine.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Major Cooke » Wed Jul 24, 2019 8:48 am

Understood. Anyway I'm working with Chris on this now.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Rachael » Wed Jul 24, 2019 8:32 am

@Cooke: I merged your pull request thread. There's really no need to make a separate thread.

If you think Graf isn't going to notice, give him some time and see if he does, and then you cna post a reminder in the dev forum.

Re: Sound Pitch Setting/Adjusting

by Graf Zahl » Wed Jul 24, 2019 1:07 am

This will be merged once Chris has made a review. I cannot judge if it is ok.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Major Cooke » Tue Jul 23, 2019 7:01 pm

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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Dr_Cosmobyte » Tue Jul 23, 2019 6:56 pm

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

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

Sound Pitch Setting/Adjusting

by Major Cooke » Tue Jul 23, 2019 6:49 pm

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.
Attachments
test.pk3
MAP01. Has a water sector in it.
summon z and z2

z makes use of A_SoundPitch.
z2 makes use of S_Sound.
(2.8 KiB) Downloaded 46 times

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Major Cooke » Tue Jul 23, 2019 3:55 pm

This has been wanted for a looooooong time.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Dr_Cosmobyte » Tue Jul 23, 2019 3:07 pm

Well, at least my idea attracted some interests :p

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Major Cooke » Tue Jul 23, 2019 2:30 pm

I've got it covered. I'll make a code submission here in a bit.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

by Chris » Tue Jul 23, 2019 12:54 pm

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

by Major Cooke » Tue Jul 23, 2019 12:39 pm

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

by Chris » Tue Jul 23, 2019 12:15 pm

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.

Top