Pitch tuning in A_PlaySound/A_PlaySoundEX

Moderator: GZDoom Developers

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

Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Dr_Cosmobyte »

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Cherno »

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
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 »

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 all

pitch = desired_frequency / original_frequency
Unless I'm misunderstanding what you want.
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 »

(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 Dr_Cosmobyte on Sun Jul 21, 2019 9:27 pm, edited 1 time in total.
User avatar
Caligari87
Admin
Posts: 6174
Joined: Thu Feb 26, 2004 3:02 pm
Preferred Pronouns: He/Him
Contact:

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Caligari87 »

Fixed the guestpost ;)

8-)
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 »

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
phantombeta
Posts: 2084
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by phantombeta »

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
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 »

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
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 »

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
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 »

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
Cherno
Posts: 1309
Joined: Tue Dec 06, 2016 11:25 am

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

Post by Cherno »

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
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 »

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
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 no idea how it could be done but honestly, if it can be, I hope it becomes a thing.
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 »

Hey, if Unreal Engine 1 can do it, why shouldn't GZDoom? :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 »

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

Return to “Closed Feature Suggestions [GZDoom]”