Pitch tuning in A_PlaySound/A_PlaySoundEX
Moderator: GZDoom Developers
- 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
No but I'd love to have that too.
Re: Pitch tuning in A_PlaySound/A_PlaySoundEX
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...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.
- 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
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.Nash wrote: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...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 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.
- 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
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.
Not to mention it'd mean bloating out sound files with needless extra custom tags.
- 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
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.
- 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
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.
- 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
If the script part is giving you trouble, I could take a crack at it. Just to make sure, is this code correct?
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.
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.
}
- 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
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: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. }
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));
- 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
I've got it covered. I'll make a code submission here in a bit.
- Dr_Cosmobyte
- Posts: 2755
- Joined: Thu Jun 04, 2015 9:07 pm
- Location: Killing spiders.
Re: Pitch tuning in A_PlaySound/A_PlaySoundEX
Well, at least my idea attracted some interests
- 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
This has been wanted for a looooooong time.
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
Sound Pitch Setting/Adjusting
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.
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
- Major Cooke
- Posts: 8170
- Joined: Sun Jan 28, 2007 3:55 pm
- Preferred Pronouns: He/Him
- Location: QZDoom Maintenance Team
- Dr_Cosmobyte
- Posts: 2755
- Joined: Thu Jun 04, 2015 9:07 pm
- Location: Killing spiders.
Re: Pitch tuning in A_PlaySound/A_PlaySoundEX
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?
- 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
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.
Yes, it's compatible. It's just A_SoundPitch(channel, pitch). 1.0 is standard pitch.