mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -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:
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
public class ByteSampleAdapter implements ISampleAdapter
|
||||
{
|
||||
private final static float[] LOOKUP_VALUES;
|
||||
|
||||
/**
|
||||
* Creates a static lookup table that converts the 8-bit valued range
|
||||
* from 0 - 255 into scaled float values of -1.0 to 0 to 1.0
|
||||
*/
|
||||
static
|
||||
{
|
||||
LOOKUP_VALUES = new float[ 256 ];
|
||||
|
||||
for( int x = 0; x < 256; x++ )
|
||||
{
|
||||
LOOKUP_VALUES[ x ] = (float)( x - 127 ) / 128.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] convert( byte[] samples )
|
||||
{
|
||||
float[] convertedSamples = new float[ samples.length ];
|
||||
int pointer = 0;
|
||||
|
||||
for( byte sample: samples )
|
||||
{
|
||||
/* Convert byte value into float from the lookup table */
|
||||
convertedSamples[ pointer++ ] = LOOKUP_VALUES[ ( sample & 0xFF ) ];
|
||||
}
|
||||
|
||||
return convertedSamples;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
import io.github.dsheirer.source.mixer.MixerChannel;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Converts 16-bit little endian byte data into an array of floats
|
||||
*/
|
||||
public class ChannelShortAdapter implements ISampleAdapter
|
||||
{
|
||||
private ShortToFloatMap mMap = new ShortToFloatMap();
|
||||
private ByteOrder mByteOrder = ByteOrder.LITTLE_ENDIAN;
|
||||
private MixerChannel mMixerChannel;
|
||||
|
||||
public ChannelShortAdapter( MixerChannel channel )
|
||||
{
|
||||
/* Only use with LEFT/RIGHT channels */
|
||||
Validate.isTrue(channel != MixerChannel.MONO);
|
||||
|
||||
mMixerChannel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float[] convert( byte[] samples )
|
||||
{
|
||||
float[] processed = new float[ samples.length / 4 ];
|
||||
|
||||
int pointer = 0;
|
||||
|
||||
/* Wrap byte array in a byte buffer so we can process them as shorts */
|
||||
ByteBuffer buffer = ByteBuffer.wrap( samples );
|
||||
|
||||
/* Set endian to correct byte ordering */
|
||||
buffer.order( mByteOrder );
|
||||
|
||||
while( buffer.hasRemaining() )
|
||||
{
|
||||
if( mMixerChannel == MixerChannel.LEFT )
|
||||
{
|
||||
processed[ pointer ] = mMap.get( buffer.getShort() );
|
||||
|
||||
/* Throw away the right channel */
|
||||
buffer.getShort();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Throw away the left channel */
|
||||
buffer.getShort();
|
||||
|
||||
processed[ pointer ] = mMap.get( buffer.getShort() );
|
||||
}
|
||||
|
||||
pointer++;
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set byte interpretation to little or big endian. Defaults to LITTLE
|
||||
* endian
|
||||
*/
|
||||
public void setByteOrder( ByteOrder order )
|
||||
{
|
||||
mByteOrder = order;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
import io.github.dsheirer.source.mixer.MixerChannel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Receives complex samples and send either the left channel or the right
|
||||
* channel to the short sample listener
|
||||
*/
|
||||
public class ComplexToFloatSampleConverter implements Listener<List<Complex>>
|
||||
{
|
||||
private MixerChannel mChannel;
|
||||
private Listener<Float> mListener;
|
||||
|
||||
public ComplexToFloatSampleConverter( Listener<Float> listener,
|
||||
MixerChannel channel )
|
||||
{
|
||||
mListener = listener;
|
||||
mChannel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receive( List<Complex> samples )
|
||||
{
|
||||
for( Complex sample: samples )
|
||||
{
|
||||
mListener.receive( mChannel == MixerChannel.LEFT ?
|
||||
sample.left() :
|
||||
sample.right() );
|
||||
}
|
||||
}
|
||||
|
||||
public Listener<Float> getListener()
|
||||
{
|
||||
return mListener;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
import io.github.dsheirer.sample.complex.Complex;
|
||||
|
||||
public class FloatArrayToComplexAdapter implements Listener<Float[]>
|
||||
{
|
||||
private Listener<Complex> mListener;
|
||||
|
||||
@Override
|
||||
public void receive( Float[] samples )
|
||||
{
|
||||
if( samples != null )
|
||||
{
|
||||
for( int x = 0; x < samples.length; x += 2 )
|
||||
{
|
||||
if( mListener != null &&
|
||||
samples[ x ] != null &&
|
||||
samples[ x + 1 ] != null )
|
||||
{
|
||||
mListener.receive( new Complex( samples[ x ],
|
||||
samples[ x + 1 ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
samples = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener( Listener<Complex> listener )
|
||||
{
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public void removeListener( Listener<Complex> listener )
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
public void dispose()
|
||||
{
|
||||
mListener = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014,2015 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
/*
|
||||
* Adapter to convert byte data received from a data stream into float[]
|
||||
* samples
|
||||
*/
|
||||
public interface ISampleAdapter
|
||||
{
|
||||
public abstract float[] convert( byte[] samples );
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2014 Dennis Sheirer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
******************************************************************************/
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* Converts 16-bit little endian byte data into an array of floats
|
||||
*/
|
||||
public class ShortAdapter implements ISampleAdapter
|
||||
{
|
||||
private ShortToFloatMap mMap = new ShortToFloatMap();
|
||||
private ByteOrder mByteOrder = ByteOrder.LITTLE_ENDIAN;
|
||||
|
||||
@Override
|
||||
public float[] convert( byte[] samples )
|
||||
{
|
||||
float[] processed = new float[ samples.length / 2 ];
|
||||
|
||||
int pointer = 0;
|
||||
|
||||
/* Wrap byte array in a byte buffer so we can process them as shorts */
|
||||
ByteBuffer buffer = ByteBuffer.wrap( samples );
|
||||
|
||||
/* Set endian to correct byte ordering */
|
||||
buffer.order( mByteOrder );
|
||||
|
||||
while( buffer.hasRemaining() )
|
||||
{
|
||||
processed[ pointer ] = mMap.get( buffer.getShort() );
|
||||
|
||||
pointer++;
|
||||
}
|
||||
|
||||
return processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set byte interpretation to little or big endian. Defaults to LITTLE
|
||||
* endian
|
||||
*/
|
||||
public void setByteOrder( ByteOrder order )
|
||||
{
|
||||
mByteOrder = order;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
public class ShortToFloatMap
|
||||
{
|
||||
private static float[] MAP = new float[ 65536 ];
|
||||
|
||||
static
|
||||
{
|
||||
for( int x = 0; x < 65536; x++ )
|
||||
{
|
||||
MAP[ x] = (float)( x - 32768 ) / 32768.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public float get( short value )
|
||||
{
|
||||
return MAP[ 32768 + value ];
|
||||
}
|
||||
}
|
||||
25
src/main/java/io/github/dsheirer/sample/adapter/Test.java
Normal file
25
src/main/java/io/github/dsheirer/sample/adapter/Test.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package io.github.dsheirer.sample.adapter;
|
||||
|
||||
import io.github.dsheirer.source.tuner.hackrf.HackRFTunerController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Test
|
||||
{
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( HackRFTunerController.class );
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
mLog.debug( "Starting" );
|
||||
|
||||
ShortToFloatMap map1 = new ShortToFloatMap();
|
||||
|
||||
for( short x = -32768; x < -32758; x++ )
|
||||
{
|
||||
mLog.debug( "X:" + x + " value:" + map1.get( x ) );
|
||||
}
|
||||
mLog.debug( "Finished" );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user