Page 1 of 3

Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 5:29 pm
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 6:28 pm
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 :)

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 7:08 pm
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 allExpand view
pitch = desired_frequency / original_frequency


Unless I'm misunderstanding what you want.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 9:02 pm
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!

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 9:20 pm
by Caligari87
Fixed the guestpost ;)

8-)

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 10:19 pm
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Sun Jul 21, 2019 10:33 pm
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 3:56 am
by Marisa Kirisame
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 4:58 am
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 11:57 am
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).

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 1:53 pm
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 2:03 pm
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.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 2:32 pm
by Major Cooke
I've no idea how it could be done but honestly, if it can be, I hope it becomes a thing.

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 4:23 pm
by Marisa Kirisame
Hey, if Unreal Engine 1 can do it, why shouldn't GZDoom? :P

Re: Pitch tuning in A_PlaySound/A_PlaySoundEX

PostPosted: Mon Jul 22, 2019 7:57 pm
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.