[WIP] Implements reusable sample buffers across all components. This

produces a significant reduction in memory usage, especially for tuners
like the airspy and hackrf that produce 10/20 MSPS sample rates.  This
is observed to be around 66% reduction in peak memory usage and provides
a more stable memory utilization across time reducing stress on the
garbage collector.

Use of these reusable memory buffers will be pushed further down into
the processing chain modules to ensure we keep new object creation
to the lowest levels possible.
This commit is contained in:
Denny
2018-02-03 10:05:16 -05:00
parent fcd3c2fd46
commit f2f2c92afe
56 changed files with 1630 additions and 1255 deletions

View File

@@ -0,0 +1,58 @@
/*******************************************************************************
* sdr-trunk
* Copyright (C) 2014-2018 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.complex.reusable.ReusableComplexBuffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
/**
* Converts 16-bit little endian byte data into an array of complex floats
*/
public class ComplexShortAdapter implements IComplexSampleAdapter
{
private ShortToFloatMap mMap = new ShortToFloatMap();
private FloatBuffer mFloatBuffer;
private ByteOrder mByteOrder = ByteOrder.LITTLE_ENDIAN;
@Override
public void convertAndLoad(byte[] samples, ReusableComplexBuffer reusableComplexBuffer)
{
int sampleCount = samples.length / 2;
if(mFloatBuffer == null || mFloatBuffer.capacity() != sampleCount)
{
mFloatBuffer = FloatBuffer.allocate(sampleCount);
}
mFloatBuffer.rewind();
/* 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())
{
mFloatBuffer.put(mMap.get(buffer.getShort()));
}
reusableComplexBuffer.reloadFrom(mFloatBuffer, System.currentTimeMillis());
}
}

View File

@@ -0,0 +1,28 @@
/*******************************************************************************
* sdr-trunk
* Copyright (C) 2014-2018 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.complex.reusable.ReusableComplexBuffer;
public interface IComplexSampleAdapter
{
/**
* Converts the sample byte array into complex float samples, loading the converted float samples into the buffer.
* @param samples
* @param reusableComplexBuffer
*/
void convertAndLoad(byte[] samples, ReusableComplexBuffer reusableComplexBuffer);
}