Reputation: 1712
For an upcoming project using the Web Audio API I would like to be able to amplify the volume of some audio.
As I read in the documentation, a gain node multiplies the incoming signal by it gain value. The documentation states that this value is in the range of 0
to 1
, hence amplification seems not to be doable with a gain node. But how else could I do it?
Upvotes: 5
Views: 1122
Reputation: 13908
To be more specific: as Kevin said, the "nominal" value of one represents unity gain - i.e., no change. That is NOT the same as a range. Implementations MUST support values > 1 - in fact, the entire range of the value. There are many scenarios that use large gain scaling values to do interesting things, and would be very broken if implementations didn't support this.
In short: use a gain > 1 to amplify things. If you're at all worried about clipping, put a dynamics processor node after it.
Upvotes: 4
Reputation: 14466
I'm not aware of an implementation that doesn't increase the gain above 1. That's what I've been using in all of my projects, and haven't run into any issues.
If you're super concerned about it, I guess you could use a ScriptProcessorNode
and basically just multiply all your samples by whatever scaling value you want, but the performance will be quite a bit worse than you'd get with a gain node. And, also, that would just be flat out kind of ridiculous.
The way I read the spec doesn't really give me any reason to believe values greater than 1 will be ignored for the GainNode
's gain
parameter. It's basically just saying 1 is the nominal value. In other words, if you want your audio to pass through unaffected, set the value to 1. Otherwise, you'll get attenuation or amplification.
Upvotes: 2