ProducingDoubleDataSource extends BufferedDoubleDataSource implements Runnable { public void start() { dataProducingThread = new Thread(this); dataProducingThread.setDaemon(true); dataProducingThread.start(); } protected  ProducingDoubleDataSource(); protected  ProducingDoubleDataSource(long numDataThatWillBeProduced); protected  ProducingDoubleDataSource(InlineDataProcessor dataProcessor); protected  ProducingDoubleDataSource(long numDataThatWillBeProduced, InlineDataProcessor dataProcessor); void start(); abstract void run(); void putOneDataPoint(double value); @Override boolean hasMoreData(); @Override int available();  }
@Test public void canReadZeroFrames() throws IOException { TestProducer producer = new TestProducer(0); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(0, ais.getFrameLength()); }
@Test public void canReadTenDoubles() { int numDoubles = 10; TestProducer producer = new TestProducer(numDoubles); producer.start(); assertEquals(numDoubles, producer.getDataLength()); double[] data = producer.getAllData(); assertEquals(numDoubles, data.length); }
@Test public void canRead4000Doubles() { int numDoubles = 4000; TestProducer producer = new TestProducer(numDoubles); producer.start(); assertEquals(numDoubles, producer.getDataLength()); double[] data = producer.getAllData(); assertEquals(numDoubles, data.length); }
@Test public void canReadTenFrames() throws Exception { int numDoubles = 10; TestProducer producer = new TestProducer(numDoubles); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(numDoubles, ais.getFrameLength()); int bytesRead = ais.read(new byte[16000]); assertEquals(2 * numDoubles, bytesRead); }
@Test public void canRead4000Frames() throws Exception { int numDoubles = 4000; TestProducer producer = new TestProducer(numDoubles); producer.start(); AudioInputStream ais = new DDSAudioInputStream(producer, getTestAudioFormat()); assertEquals(numDoubles, ais.getFrameLength()); int bytesRead = ais.read(new byte[16000]); assertEquals(2 * numDoubles, bytesRead); }
@Test public void willApplyInlineProcessor() { InlineDataProcessor halver = new InlineDataProcessor() { public void applyInline(double[] data, int off, int len) { for (int i = off, max = off + len; i < max; i++) { data[i] *= .5; } } }; int numDoubles = 100; TestProducer producer = new TestProducer(numDoubles, halver); producer.start(); double[] result = producer.getAllData(); for (int i = 0; i < numDoubles; i++) { assertEquals(producer.DUMMY * .5, result[i], 1.e-10); } }