Tempo (seperate from pitch) for A_Playsound?

Moderator: GZDoom Developers

User avatar
Alfred Don
Posts: 45
Joined: Mon Aug 01, 2022 11:52 am

Tempo (seperate from pitch) for A_Playsound?

Post by Alfred Don »

Would be useful in a number of applications where you don't want something to have a higher pitch but you do want to speed it up.
Professor Hastig
Posts: 256
Joined: Mon Jan 09, 2023 2:02 am
Graphics Processor: nVidia (Modern GZDoom)

Re: Tempo (seperate from pitch) for A_Playsound?

Post by Professor Hastig »

That would require complete resampling of the sound. The current pitch feature only alters the playback frequency which is simple.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49188
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Tempo (seperate from pitch) for A_Playsound?

Post by Graf Zahl »

Yeah, it's an entirely different level of complexity. This essentially needs to create new sounds for each specific tempo value unless your playback engine can automatically do it, which I doubt OpenAL can.
User avatar
Chris
Posts: 2956
Joined: Thu Jul 17, 2003 12:07 am
Graphics Processor: ATI/AMD with Vulkan/Metal Support

Re: Tempo (seperate from pitch) for A_Playsound?

Post by Chris »

Graf Zahl wrote: Fri Aug 18, 2023 3:13 pm Yeah, it's an entirely different level of complexity. This essentially needs to create new sounds for each specific tempo value unless your playback engine can automatically do it, which I doubt OpenAL can.
Technically it can, though not with the greatest quality. The AL_EFFECT_PITCH_SHIFTER effect can change the pitch of a sound without changing its length/speed, which when combined with the AL_PITCH source property, can make a sound play faster or slower without changing the final pitch. But the quality of the pitch shifter effect isn't the greatest; the current implementation is mono only (which since it's applied after 3D panning, means it loses 3D positioning, along with stereo sounds becoming mono), messes around with the original phase of the sound, and isn't cheap on the processor, so it could easily overload the system if you want different sounds playing simultaneously at different tempos (each sound would need its own effect instance). I have been intending to look at using an alternate implementation of the effect which may be a bit cheaper and easier to make non-mono, but such an alternate implementation can have an audible buzzing-like quality with larger changes.

Aside from the quality issue, there would also be the problem of getting the pitch shifter effect to interact with the reverb effect. OpenAL Soft can chain effects, but an effect can only output to another effect or the main output. It wouldn't be a problem for sounds that don't use environmental effects, like UI sounds or music, but for this to work more efficiently with environmental effects where both dry and wet/room outputs are needed, OpenAL Soft would need a way to apply an effect prior to the direct/send split. That's certainly something I should investigate.

Since it would need to be done in real-time, there's always going to be quality trade-offs. If you want it to sound as good as it can, one option would be to apply the effect "offline" with a dedicated program that has higher quality algorithms (like audacity, ffmpeg, sox, etc) to create different files with different tempos, and select the appropriate one in-game using sndinfo, decorate, and/or zscript.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49188
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Tempo (seperate from pitch) for A_Playsound?

Post by Graf Zahl »

This is exactly what I would have expected as a best case scenario, it's clearly not worth doing.

Return to “Closed Feature Suggestions [GZDoom]”