[Added] Pitch tuning in A_PlaySound/A_PlaySoundEX

Moderator: GZDoom Developers

Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby GAA1992 » Sun Jul 21, 2019 6:29 pm

Well. This is my first feature suggestion, and, since i am not programmer for a living, i ask you patience and comprehension.

Looking at the playsound and sndinfo commands, it seems one can't exactly force or control the sound pitch of an specific sound to a certain extent; we can only limit the variables of the octaves in a shared way.

For example (a terrible one of the top of my head), let's say i want to make a weapon mod and, to save some space, i want to use the same casing sounds for all weapons, but change the pitch of the sound the heavier the casing is.

Defining $pitchshift 1, 2 or 3... (correct me if i am wrong) plays either lower or higher octaves of that sound, not a specific one.

My suggestion would be to add a parameter related to pitch either on the sndinfo or the playsound commands, something that could work like:

A_PlaysoundEx("Blah/Blah","Weapon", true, 0, (-1,4))

Those last two parameters in parenthesis define, respectively, the lower octaves to reach and the second the higher ones to reach. A value of 0 means the sound won't change its pitch.

Again, sorry if this isn't viable to program, but i wouldn't know if i didn't asked.
User avatar
GAA1992
Demons are a disease. Meet the cure.
 
Joined: 04 Jun 2015
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Cherno » Sun Jul 21, 2019 7:28 pm

I would really like to see this, it would make vehicle simulations far better by adjusting the engine pitch sound based on velocity :)
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Chris » Sun Jul 21, 2019 8:08 pm

I'm not really sure what you're asking. If you want to take a sound and play it in a higher or lower pitch, that's what the pitch parameter is for. If you have a sound with a 600hz fundamental frequency, for example, setting a pitch of 2 changes it to 1200hz while setting a pitch of 0.5 changes it to 300hz. It's a linear function, so it's as simple as:
Code: Select allExpand view
pitch = desired_frequency / original_frequency


Unless I'm misunderstanding what you want.
User avatar
Chris
 
Joined: 17 Jul 2003

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby GAA1992 » Sun Jul 21, 2019 10:02 pm

(somehow it logged out and i created the thread, but anyway)

I knew it would be hard to explain. But what i want to do is to set the exact pitch, or control the exact variation of the pitch to a certain sound instead of typing "$pitchshift misc/teleport 3", for example.

Think the sound "DSTELEPT" or whatever the Doom teleport sound is called. It's in the key of #F. limiting "misc/teleport" with "3" plays keys below and above #F as far as i know. What if i want it to shift pitch to only lower values than #F, or, get Cherno's example of a car engine sound always going up according to speed.

EDIT: Thanks Caligari!
Last edited by GAA1992 on Sun Jul 21, 2019 10:27 pm, edited 1 time in total.
User avatar
GAA1992
Demons are a disease. Meet the cure.
 
Joined: 04 Jun 2015
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Caligari87 » Sun Jul 21, 2019 10:20 pm

Fixed the guestpost ;)

8-)
User avatar
Caligari87
I'm just here for the community
User Accounts Assistant
 
Joined: 26 Feb 2004
Location: Salt Lake City, Utah, USA
Discord: Caligari87#3089

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Chris » Sun Jul 21, 2019 11:19 pm

GAA1992 wrote:(somehow it logged out and i created the thread, but anyway)

I knew it would be hard to explain. But what i want to do is to set the exact pitch, or control the exact variation of the pitch to a certain sound instead of typing "$pitchshift misc/teleport 3", for example.

Think the sound "DSTELEPT" or whatever the Doom teleport sound is called. It's in the key of #F. limiting "misc/teleport" with "3" plays keys below and above #F as far as i know. What if i want it to shift pitch to only lower values than #F, or, get Cherno's example of a car engine sound always going up according to speed.

Ah. Well, controlling the particular key/tone a sound plays at is unlikely, since it would depend on analyzing the sound to find the dominant frequency to know how much to shift for a given desired key (and then deal with inevitable ambiguities). Although, other than potential compatibility issues, I see no technical reason why you couldn't have more control over the upper and lower randomized limit. For example, setting a range of 0.5-1.0 so it won't randomly play less than half or more than normal. Graf or someone else would have to comment on whether that could be made available via A_PlaySound[Ex] or SNDINFO or something without breaking compatibility.

Note, however, that the snd_pitched CVAR currently controls whether any pitch shifting is done. If snd_pitched is false, no pitch shift is applied to sounds (except when underwater, where there's a fixed base of 0.7937 instead of 1.0). If you rely on different pitches for the same sound, that CVAR will need reconsideration.
User avatar
Chris
 
Joined: 17 Jul 2003

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby phantombeta » Sun Jul 21, 2019 11:33 pm

Chris wrote:
GAA1992 wrote:(somehow it logged out and i created the thread, but anyway)

I knew it would be hard to explain. But what i want to do is to set the exact pitch, or control the exact variation of the pitch to a certain sound instead of typing "$pitchshift misc/teleport 3", for example.

Think the sound "DSTELEPT" or whatever the Doom teleport sound is called. It's in the key of #F. limiting "misc/teleport" with "3" plays keys below and above #F as far as i know. What if i want it to shift pitch to only lower values than #F, or, get Cherno's example of a car engine sound always going up according to speed.

Ah. Well, controlling the particular key/tone a sound plays at is unlikely, since it would depend on analyzing the sound to find the dominant frequency to know how much to shift for a given desired key (and then deal with inevitable ambiguities). Although, other than potential compatibility issues, I see no technical reason why you couldn't have more control over the upper and lower randomized limit. For example, setting a range of 0.5-1.0 so it won't randomly play less than half or more than normal. Graf or someone else would have to comment on whether that could be made available via A_PlaySound[Ex] or SNDINFO or something without breaking compatibility.

Note, however, that the snd_pitched CVAR currently controls whether any pitch shifting is done. If snd_pitched is false, no pitch shift is applied to sounds (except when underwater, where there's a fixed base of 0.7937 instead of 1.0). If you rely on different pitches for the same sound, that CVAR will need reconsideration.

I think the point of the feature request is that they want a way to specify the exact pitch, and without needing the player to set snd_pitched to true.
User avatar
phantombeta
In the meadow of sinful thoughts, every flower's a perfect one
 
Joined: 02 May 2013
Location: The United Soviet Socialist Dictatorship of Hueland
Discord: phantombeta#2461
Twitch ID: phantombeta_
Github ID: Doom2fan
Operating System: Windows 10/8.1/8 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Marisa Kirisame » Mon Jul 22, 2019 4:56 am

I very much would like that. Being able to still control pitch without having to enable randomization. And if it's a specific multiplier of pitch I'd say it would be more useful, rather than using the same math pitch randomization already uses.
User avatar
Marisa Kirisame
ZScript Magician
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: Marisa Kirisame#4689
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby GAA1992 » Mon Jul 22, 2019 5:58 am

Both Chris and Phantom are right. The main objective here is to give more control over pitch. Forcing itself to randomize even when randomization is off can also throw a lot of possibilities in game (like when the vanilla chainsaw gets all annoying when sound pitching is on). Whether this can only be achieved with "Sound Randomization" true or false, i think its more of the devs call.
User avatar
GAA1992
Demons are a disease. Meet the cure.
 
Joined: 04 Jun 2015
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Major Cooke » Mon Jul 22, 2019 12:57 pm

Yes please. Very much, please! I would LOVE this. I can finally make cartoony sound effects a little more in line with animations without needing to make them over again.

But would it be possible to introduce a function that also changes the pitch? I've always wanted to replicate the ability to shift a pitch mid-playing like Battlezone's MAG Cannon does (raises the pitch + speed of the audio the bigger the charge).
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Cherno » Mon Jul 22, 2019 2:53 pm

As far as I'm concerned, I would be more than happy with a simple (?) function akin to A_SoundVolume, only for changing pitch of an already playing sound. Thiscould be called immediately after A_PlaySound as well, if adding a pitch parameter to A_PlaySound is out of the question.
User avatar
Cherno
 
Joined: 06 Dec 2016

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby GAA1992 » Mon Jul 22, 2019 3:03 pm

Major Cooke wrote:But would it be possible to introduce a function that also changes the pitch? I've always wanted to replicate the ability to shift a pitch mid-playing like Battlezone's MAG Cannon does (raises the pitch + speed of the audio the bigger the charge).


You mean, like, shifting pitch on the fly? Then that would be dope.

The charging buster solution I'd apply would be to set a looping sound over another in the same channel, but that's more of a dirty hack.
User avatar
GAA1992
Demons are a disease. Meet the cure.
 
Joined: 04 Jun 2015
Location: Killing spiders.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Major Cooke » Mon Jul 22, 2019 3:32 pm

I've no idea how it could be done but honestly, if it can be, I hope it becomes a thing.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Marisa Kirisame » Mon Jul 22, 2019 5:23 pm

Hey, if Unreal Engine 1 can do it, why shouldn't GZDoom? :P
User avatar
Marisa Kirisame
ZScript Magician
 
 
 
Joined: 08 Feb 2008
Location: Vigo, Galicia
Discord: Marisa Kirisame#4689
Twitch ID: magusmarisa
Github ID: OrdinaryMagician
Operating System: Other Linux 64-bit
Graphics Processor: nVidia with Vulkan support

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Postby Major Cooke » Mon Jul 22, 2019 8:57 pm

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.
User avatar
Major Cooke
Do unto others as you would have unto you. Judge yourself first.
 
Joined: 28 Jan 2007

Next

Return to Closed Feature Suggestions

Who is online

Users browsing this forum: Yandex [Bot] and 2 guests