Low-Pass Filter?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
gamebabu
Prole
Posts: 3
Joined: Mon Aug 05, 2013 9:38 pm

Low-Pass Filter?

Post by gamebabu »

Hey guys! I'm fairly new to these forums, but you guys have actually helped me out a lot!
There's some great community documentation of problems in here. It's gotten me out a snag a great many times.

But I've encountered a problem that I can not find a clean solution for.

My partner who is doing the audio for my game has requested a low-pass filter for better sound design.
I've looked and looked, but I can not seem to find anything on how this may be done.

I'm not the greatest programmer when it comes to portability, and am afraid to modify the love source to add this functionality.

Is there no other way?

Thank you for taking the time to read this!

P.S. If I've broken any rules with this topic, I apologize. I read through it, and it seems like this kind of problem is okay.. :o:
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Low-Pass Filter?

Post by raidho36 »

I think you should rather do that with .dll and .so than with Lua, since it's not exactly up to the task.

LP filter is done pretty simple: for input sample, you multiply it by smoothing factor and add to it multiple of previous output sample by inverted factor.

Code: Select all

local a = samplerate / ( factor + samplerate )
local a1 = 1 - a
output[ 1 ] = input[ 1 ]
for i = 2, #input do 
    output[ i ] = a * input[ i ] + a1 * output[ i - 1 ] 
end
gamebabu
Prole
Posts: 3
Joined: Mon Aug 05, 2013 9:38 pm

Re: Low-Pass Filter?

Post by gamebabu »

Thank you for taking the time to respond!

..This might be slightly over my head.

I haven't done much work with .dll and .so, nor really much work with audio in general.

If I were to go down this path as you have suggested, do you think you could guide me a bit more along the way?
This is something head scratchingly difficult for me, and your help would be really appreciated!

I have two main questions :oops:
Would I need to write this LP filter in C?
With this additional library, how would I ensure portability and go about making the executables for Linux, Mac, and Windows?

I apologize if this is asking for too much. I just really don't know where to start with this. :death:
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Low-Pass Filter?

Post by Lafolie »

The easiest method is to use LPF and friends in your DAW, which will (should) produce higher quality results. If you need to dynamically phase between a sound at different envelope frequencies then try experimenting with just that - phase 2 or more audio tracks in your game (one clean, one enveloped).
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Low-Pass Filter?

Post by raidho36 »

As long as your library only contains math code, there won't be any compatibility issues. But I second what Lafolie said, you should prefer pre-render to dynamic rendering when possible. As for audio quality, you will most likely not notice any difference; pre-render or dymanic, same algorithm, the only difference is interpolation, multisampling, more expensive computations, etc. that result in slightly higher quality for prerendered stuff, in cost of great (relative) rendering time. It's like comparing quality of the same 3d scene (same models, same textures, etc) rendered real-time with some performance tradeoffs like FXAA instead of MSAA, against full-blown high quality software 3d pre-render.
gamebabu
Prole
Posts: 3
Joined: Mon Aug 05, 2013 9:38 pm

Re: Low-Pass Filter?

Post by gamebabu »

Hmm, I've given it a lot of thought, and this alternative solution might be what we end up using.
It's certainly a lot easier to implement.

Thank you guys!

I'll keep looking to see if an LPF would be feasible for me, just to see what we could do with it. My partner was telling me about using the low pass gradually as the player gets nearer and farther from certain things. It may not be the same sound quality as a DAW's LPF, but I can definitely see how it would be more immersive..

I did some more searching and found this libary: https://github.com/graue/luasynth
But, I have no idea on how I would go about integrating it with LÖVE.
Still, thanks you for the help guys. I'll keep fiddling from time to time to see if I can make it work.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Low-Pass Filter?

Post by raidho36 »

I don't think you should use a lowpass filter for that unless you expect distances of order of several miles.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests