mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
#1170 resolves issue with MP3 encoded audio raspy. Adds auto-clipping of PCM audio prior to encoding and adds 4x new 32-bit input sample rate selections to choose from, in addition to original 4x 16-bit input formats. (#1171)
Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
@@ -66,7 +66,48 @@ public class ConversionUtils
|
||||
|
||||
for(float sample : samples)
|
||||
{
|
||||
converted.putShort((short)(sample * Short.MAX_VALUE));
|
||||
if(sample > 1.0f)
|
||||
{
|
||||
converted.putShort(Short.MAX_VALUE);
|
||||
}
|
||||
else if(sample < -1.0f)
|
||||
{
|
||||
converted.putShort((short)-Short.MAX_VALUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
converted.putShort((short)(sample * Short.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the float samples into a little-endian 32-bit sample byte buffer.
|
||||
*
|
||||
* @param samples - float array of sample data
|
||||
* @return - little-endian 32-bit sample byte buffer
|
||||
*/
|
||||
public static ByteBuffer convertToSigned32BitSamples(float[] samples)
|
||||
{
|
||||
ByteBuffer converted = ByteBuffer.allocate(samples.length * 4);
|
||||
converted.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
for(float sample : samples)
|
||||
{
|
||||
if(sample > 1.0f)
|
||||
{
|
||||
converted.putInt(Integer.MAX_VALUE);
|
||||
}
|
||||
else if(sample < -1.0f)
|
||||
{
|
||||
converted.putInt(-Integer.MAX_VALUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
converted.putInt((int)(sample * Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
||||
return converted;
|
||||
|
||||
Reference in New Issue
Block a user