goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.27k stars 2.21k forks source link

Feature Request: Simple Compression and Filter #54

Open erichlof opened 11 years ago

erichlof commented 11 years ago

Hi James and all, James I know you have a lot on your plate right now, but with possible reworking of some of the aspects of Howler's positional methods, I wanted to try to throw in a couple of feature requests that would be relatively easier to implement now, during possible re-structuring, rather than later as an afterthought.

Two effects come to mind when having a robust audio engine for games. The first is almost a necessity - compression. If the developer has too many sounds playing at the same time and a possible background track going on, the audio will become distorted due to clipping. May I suggest a howler.compressor object to limit the final output of the app's audio and to help keep in check the overall volume when the gameplay sounds get heavy (like a sudden firefight in a war game).

The second isn't so much a necessity as it is a cool effect that is difficult to hard-code ourselves, or re-record everything with the effect added. This is a Low-Pass Filter. For those of you non-audio buffs out there, it is essentially a muffling effect. It limits all the high parts of the audio spectrum (imagine speaking while cupping your hand over your mouth). The volume remains the same, but only the low parts pass through.

I can think of a couple of situations where a filter would come in handy - one is in a FPS when the player gets knocked by a nearby grenade or something, a muffled-world sound would ensue as well as red-tinted-screen 'damage' effects or whatever the developer wanted. The second case would be people talking or a club-music atmosphere going on in another room. As you approach the room from outside, the voices or music sound muffled, and when you open the door, the developer switches howler.filter to Off and then you can hear the high parts of the sounds again (just like in real-life).

So in summary, howler.compressor(amount) and howler.filter(frequency). The lower the frequency, the more muffled, the higher the frequency the less muffled the sound becomes. We could even use this feature to code a sweep of that frequency parameter and go smoothly from totally muffled to totally bright (as DeadMau5 makes money doing every night - haha).

Implementing these with Web Audio API is trivial. It's probably 4 or 5 lines of code for each effect. It involves creating the filter or compressor and then hooking them up with the .connect() function to the final audio destination (your speakers). As usual the Web Audio API overkills and gives you total control over every possible parameter if you want to design a synthesizer, but we just need a one-size-fits-all function with maybe 1 adjustable parameter to keep things simple and useful for gaming applications.

Please let me know what you all think.

goldfire commented 10 years ago

I'm going ahead and marking this as 2.0 since one of the goals of that release will be full coverage of Web Audio API. I was hoping to have at least gotten an early version of 2.0 out for testing by now, but it turns out startups take up a lot of your time (who would have thought)!

nathanielatom commented 7 years ago

Have lowpass and highpass filters been implemented in v2.0.2?

Edit: it looks like they may not be built into Howler but you can easily create a Web Audio filter and connect it to howler.

markhughes commented 7 years ago

@goldfire is Howler still maintained? Would a pull request be accepted?

goldfire commented 7 years ago

@MarkehMe Yes, I've just been very busy with my company lately. I'm hoping to get some more of the pending PR's pulled in soon. Any help on this would be greatly appreciated. Keep in mind that it should be structured as a plugin rather than added into core.

markhughes commented 7 years ago

@goldfire Understandable! Don't burn yourself out πŸ˜‰

I can only see a way of doing this with the Web Audio API, so I'll tackle this!

JapanYoshi commented 4 years ago

Bumping about the compressor.

Ronsku commented 3 months ago

@goldfire Understandable! Don't burn yourself out πŸ˜‰

I can only see a way of doing this with the Web Audio API, so I'll tackle this!

Did you ever tackle this? 😊

markhughes commented 3 months ago

Did you ever tackle this? 😊

I did actually just never pushed it up, I'll try recover the project.