mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Adding missing gain class
This commit is contained in:
65
src/dsp/gain/NonClippingGain.java
Normal file
65
src/dsp/gain/NonClippingGain.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package dsp.gain;
|
||||
|
||||
import sample.real.RealBuffer;
|
||||
|
||||
public class NonClippingGain
|
||||
{
|
||||
private float mGain;
|
||||
private float mMaxValue;
|
||||
|
||||
/**
|
||||
* Applies a fixed gain value to the float samples.
|
||||
*
|
||||
* @param gain value
|
||||
* @param maxValue max absolute value to prevent clipping ( 0.0 to 1.0 )
|
||||
*/
|
||||
public NonClippingGain( float gain, float maxValue )
|
||||
{
|
||||
mGain = gain;
|
||||
mMaxValue = maxValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies gain to the sample
|
||||
*/
|
||||
public float apply( float sample )
|
||||
{
|
||||
float adjusted = sample * mGain;
|
||||
|
||||
if( adjusted > mMaxValue )
|
||||
{
|
||||
adjusted = mMaxValue;
|
||||
}
|
||||
if( adjusted < -mMaxValue )
|
||||
{
|
||||
adjusted = -mMaxValue;
|
||||
}
|
||||
|
||||
return adjusted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies gain to the sample array
|
||||
*/
|
||||
public float[] apply( float[] samples )
|
||||
{
|
||||
for( int x = 0; x < samples.length; x++ )
|
||||
{
|
||||
samples[ x ] = apply( samples[ x ]);
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies gain to the real buffer
|
||||
*/
|
||||
public RealBuffer apply( RealBuffer buffer )
|
||||
{
|
||||
float[] samples = buffer.getSamples();
|
||||
|
||||
apply( samples );
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user