#2672 Polyphase channelizer enhancements to address buffer sizing and management

#2672 Bounds the polyphase buffer queue by sample duration instead of buffer count

The polyphase buffer processor queue was capped at 500 native buffers, which is only about 85 ms of samples for an RSP at 6 MSPS (about 1,000 samples per buffer) versus about 6.8 s for an RTL-SDR (32,768 samples per buffer).  Short processing stalls overflowed the queue and dropped buffers on RSP tuners.

- Dispatcher: adds a weight-bounded queue option (element weigher plus an  adjustable maximum queued weight).  Elements count toward the weight until  the listener has processed them.
- PolyphaseChannelManager: bounds the buffer queue at 1 second of samples and  updates the bound when the tuner sample rate changes.
- RspNativeBuffer: sampleCount() returned twice the complex sample count.  This  also corrects the tuner sample drop monitor and the spectral display buffer manager for RSP tuners.

Co-authored-by: denny <dennis.sheirer@gmail.com>
This commit is contained in:
Denny Sheirer
2026-11-18 03:05:39 -05:00
committed by GitHub
parent f47479b8d4
commit f302d46be1
10 changed files with 337 additions and 70 deletions

View File

@@ -19,11 +19,16 @@
package io.github.dsheirer.dsp.filter.channelizer;
import io.github.dsheirer.dsp.filter.channelizer.output.OneChannelOutputProcessor;
import io.github.dsheirer.dsp.filter.channelizer.output.TwoChannelOutputProcessor;
import io.github.dsheirer.sample.complex.ComplexSamples;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.CopyOnWriteArrayList;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -77,4 +82,51 @@ public class ChannelResultsBatchTest
assertEquals(1, pool.size());
}
/**
* Test: a running output processor copies its channels instead of retaining the batch, so the batch returns to the
* pool as soon as the channelizer releases it, even when the channel hasn't processed it yet. The copy holds the
* two channels' samples for each block in order.
*/
@Test
void runningOutputProcessorCopiesChannelsWithoutRetainingBatch() throws Exception
{
int blockLength = 8; //4 polyphase channels, I/Q interleaved
int blockCount = 2;
float[] samples = new float[blockLength * blockCount];
for(int x = 0; x < samples.length; x++)
{
samples[x] = x;
}
Queue<float[]> pool = new ArrayDeque<>();
ChannelResultsBatch batch = new ChannelResultsBatch(samples, blockLength, 0, pool);
List<float[]> copied = new CopyOnWriteArrayList<>();
TwoChannelOutputProcessor processor = new TwoChannelOutputProcessor(50000.0, List.of(1, 3), new float[]{1.0f},
1.0f, null, "test")
{
@Override
public void process(float[] channelSamples, int count)
{
copied.add(Arrays.copyOf(channelSamples, count * 4));
}
};
processor.setListener((ComplexSamples complexSamples) -> {});
processor.start();
processor.receiveChannelResults(batch);
batch.release();
assertSame(samples, pool.poll(), "Batch was retained by the output processor");
for(int wait = 0; wait < 100 && copied.isEmpty(); wait++)
{
Thread.sleep(20);
}
processor.stop();
//Channel 1 is at offset 2 and channel 3 at offset 6 within each 8 element block
assertArrayEquals(new float[]{2, 3, 6, 7, 10, 11, 14, 15}, copied.get(0));
}
}

View File

@@ -125,4 +125,60 @@ public class DispatcherTest
assertEquals(101, received.size());
}
/**
* Test: a weight-bounded queue drops elements that would exceed the maximum weight and keeps lighter ones.
*/
@Test
void weightBoundedQueueDropsElementsOverMaximumWeight() throws Exception
{
//Each element weighs its own value: 1 + 2 + 3 = 6 is queued, then 4 would exceed 6 and is dropped, then 0 fits
Dispatcher<Integer> dispatcher = new Dispatcher<>("test", 1, Integer::longValue, 6);
List<Integer> received = dispatchWhileBlocked(dispatcher, 4);
dispatcher.receive(0);
awaitSize(received, 5);
Thread.sleep(50);
dispatcher.stop();
assertEquals(List.of(0, 1, 2, 3, 0), received);
}
/**
* Test: an element heavier than the maximum weight is delivered when nothing else is queued.
*/
@Test
void weightBoundedQueueAcceptsHeavyElementWhenEmpty() throws Exception
{
Dispatcher<Integer> dispatcher = new Dispatcher<>("test", 1, Integer::longValue, 6);
List<Integer> received = dispatchWhileBlocked(dispatcher, 0);
dispatcher.receive(100);
dispatcher.receive(1);
awaitSize(received, 2);
Thread.sleep(50);
dispatcher.stop();
assertEquals(List.of(0, 100), received);
}
/**
* Test: processed elements release their weight so that the queue accepts new elements after an overflow.
*/
@Test
void weightBoundedQueueRecoversAfterOverflow() throws Exception
{
Dispatcher<Integer> dispatcher = new Dispatcher<>("test", 1, Integer::longValue, 6);
List<Integer> received = dispatchWhileBlocked(dispatcher, 10);
awaitSize(received, 4);
Thread.sleep(50);
for(int x = 0; x < 3; x++)
{
dispatcher.receive(5);
awaitSize(received, 5 + x);
}
dispatcher.stop();
assertEquals(List.of(0, 1, 2, 3, 5, 5, 5), received);
}
}