#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:
Denny Sheirer
2022-03-16 05:00:07 -04:00
committed by GitHub
parent 90bc321aca
commit 7749fd10f1
23 changed files with 245 additions and 183 deletions

View File

@@ -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;