mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Updates pull request from Roman Tsypuk to convert the build system from
ant to gradle. Removes linux and windows application launch scripts and produces an executable jar with all resources included.
This commit is contained in:
72
src/main/java/io/github/dsheirer/sample/ConversionUtils.java
Normal file
72
src/main/java/io/github/dsheirer/sample/ConversionUtils.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package io.github.dsheirer.sample;
|
||||
|
||||
import io.github.dsheirer.sample.real.RealBuffer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
/**
|
||||
* Utilities for converting to/from signed 16-bit sample byte arrays and float buffers
|
||||
*/
|
||||
public class ConversionUtils
|
||||
{
|
||||
public static float[] convertFromSigned16BitSamples( byte[] bytes )
|
||||
{
|
||||
return convertFromSigned16BitSamples( ByteBuffer.wrap( bytes ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the byte buffer containing 16-bit samples into a float array
|
||||
*/
|
||||
public static float[] convertFromSigned16BitSamples( ByteBuffer buffer )
|
||||
{
|
||||
ShortBuffer byteBuffer =
|
||||
buffer.order( ByteOrder.LITTLE_ENDIAN ).asShortBuffer();
|
||||
|
||||
float[] samples = new float[ buffer.limit() / 2 ];
|
||||
|
||||
for( int x = 0; x < samples.length; x++ )
|
||||
{
|
||||
samples[ x ] = (float)byteBuffer.get() / 32767.0f;
|
||||
}
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the float samples into a little-endian 16-bit sample byte buffer.
|
||||
* @param samples - float array of sample data
|
||||
* @return - little-endian 16-bit sample byte buffer
|
||||
*/
|
||||
public static ByteBuffer convertToSigned16BitSamples( float[] samples )
|
||||
{
|
||||
ByteBuffer converted = ByteBuffer.allocate( samples.length * 2 );
|
||||
converted.order( ByteOrder.LITTLE_ENDIAN );
|
||||
|
||||
for( float sample: samples )
|
||||
{
|
||||
converted.putShort( (short)( sample * Short.MAX_VALUE ) );
|
||||
}
|
||||
|
||||
return converted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the float samples in a complex buffer to a little endian 16-bit
|
||||
* buffer
|
||||
*/
|
||||
public static ByteBuffer convertToSigned16BitSamples( Buffer buffer )
|
||||
{
|
||||
return convertToSigned16BitSamples( buffer.getSamples() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the float samples in a complex buffer to a little endian 16-bit
|
||||
* buffer
|
||||
*/
|
||||
public static ByteBuffer convertToSigned16BitSamples( RealBuffer buffer )
|
||||
{
|
||||
return convertToSigned16BitSamples( buffer.getSamples() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user