Pitch tuning in A_PlaySound/A_PlaySoundEX

Moderator: GZDoom Developers

User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia
Contact:

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Marisa the Magician »

No but I'd love to have that too.
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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...
User avatar
Chris
Posts: 2940
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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.
User avatar
Marisa the Magician
Posts: 3886
Joined: Fri Feb 08, 2008 9:15 am
Preferred Pronouns: She/Her
Operating System Version (Optional): (btw I use) Arch
Graphics Processor: nVidia with Vulkan support
Location: Vigo, Galicia
Contact:

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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.
User avatar
Chris
Posts: 2940
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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.
User avatar
Chris
Posts: 2940
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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));
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Major Cooke »

I've got it covered. I'll make a code submission here in a bit.
User avatar
Dr_Cosmobyte
Posts: 2755
Joined: Thu Jun 04, 2015 9:07 pm
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Dr_Cosmobyte »

Well, at least my idea attracted some interests :p
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Major Cooke »

This has been wanted for a looooooong time.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Sound Pitch Setting/Adjusting

Post 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.
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 42 times
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Major Cooke »

User avatar
Dr_Cosmobyte
Posts: 2755
Joined: Thu Jun 04, 2015 9:07 pm
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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?
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post 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.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”