[Added] Pitch tuning in A_PlaySound/A_PlaySoundEX

Moderator: GZDoom Developers

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Marisa Kirisame » Tue Jul 23, 2019 4:29 am

No but I'd love to have that too.
User avatar
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Nash » Tue Jul 23, 2019 4:55 am

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
Nash
 
 
 
Joined: 27 Oct 2003
Location: Kuala Lumpur, Malaysia
Github ID: nashmuhandes

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Chris » Tue Jul 23, 2019 9:45 am

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
Chris
 
Joined: 17 Jul 2003

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Major Cooke » Tue Jul 23, 2019 10:12 am

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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Marisa Kirisame » Tue Jul 23, 2019 10:25 am

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
Marisa Kirisame
ZScript Crimester
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: 霧雨魔理沙#1666
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: nVidia with Vulkan support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby 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.
User avatar
Chris
 
Joined: 17 Jul 2003

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby 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 allExpand view
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
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby 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 allExpand view
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 allExpand view
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
Chris
 
Joined: 17 Jul 2003

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

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

I've got it covered. I'll make a code submission here in a bit.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

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

Well, at least my idea attracted some interests :p
User avatar
Dr_Cosmobyte
Also known as: GAA1992
 
Joined: 05 Jun 2015
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

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

This has been wanted for a looooooong time.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Sound Pitch Setting/Adjusting

Postby 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.
You do not have the required permissions to view the files attached to this post.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

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

User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby 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?
User avatar
Dr_Cosmobyte
Also known as: GAA1992
 
Joined: 05 Jun 2015
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby 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.
User avatar
Major Cooke
QZDoom Maintenance Team
 
Joined: 28 Jan 2007

PreviousNext

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests