public void prepareForNewStream() { if (randStreamStart) nextInsertionPoint = 0; else nextInsertionPoint = computeNextInsertionPoint(); // reset the number of inserted samples numInsertedSamples = 0; }
/** * Returns the next DoubleData object, which is a dithered version of the input * * @return the next available DoubleData object, or null if no Data is available * @throws edu.cmu.sphinx.frontend.DataProcessingException * if a data processing error occurred */ @Override public Data getData() throws DataProcessingException { Data input = getPredecessor().getData(); // get the spectrum if (input instanceof DataStartSignal) prepareForNewStream(); if (input != null && maxRepeatedMs != 0) { if (input instanceof DoubleData || input instanceof FloatData) { input = process(input); } } return input; }
@Test public void testInsertAt4() { RandomSampleRepeater rsr = ConfigurationManager.getInstance(RandomSampleRepeater.class); rsr.randStreamStart = true; rsr.useRandSeed = false; rsr.initialize(); rsr.maxRepeatedSamples = 3; rsr.numInsertedSamples = 20; rsr.nextInsertionPoint = 5; // create a dummy DoubleData double[] data = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; DoubleData dd = new DoubleData(data, 16000, 0); DoubleData extData = rsr.process(dd); double[] expectedData = new double[]{1, 2, 3, 4, 5, 1, 2, 6, 7, 8, 9, 10}; Assert.assertEquals(extData.getFirstSampleNumber(), 20, 0); Assert.assertEquals(extData.getValues().length, expectedData.length); for (int i = 0; i < expectedData.length; i++) { Assert.assertEquals(extData.getValues()[i], expectedData[i], 0); } }
@Override public void newProperties(PropertySheet ps) throws PropertyException { super.newProperties(ps); logger = ps.getLogger(); maxRepeatedMs = ps.getDouble(RandomSampleRepeater.PROP_MAX_REAPTED_MS); uDistWidthSec = ps.getDouble(RandomSampleRepeater.PROP_UNIFORM_DIST_WIDTH); useRandSeed = ps.getBoolean(RandomSampleRepeater.PROP_USE_RANDSEED); randStreamStart = ps.getBoolean(RandomSampleRepeater.PROP_RAND_STREAM_START); sampleRate = ps.getInt(RandomSampleRepeater.PROP_SAMPLE_RATE); initialize(); }
@Test public void testInsertAtBlockEnd() { RandomSampleRepeater rsr = ConfigurationManager.getInstance(RandomSampleRepeater.class); rsr.randStreamStart = true; rsr.useRandSeed = false; rsr.initialize(); rsr.maxRepeatedSamples = 3; rsr.numInsertedSamples = 20; rsr.nextInsertionPoint = 9; // create a dummy DoubleData double[] data = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; DoubleData dd = new DoubleData(data, 16000, 0); DoubleData extData = rsr.process(dd); double[] expectedData = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 10}; Assert.assertEquals(extData.getFirstSampleNumber(), 20, 0); Assert.assertEquals(extData.getValues().length, expectedData.length); for (int i = 0; i < expectedData.length; i++) { Assert.assertEquals(extData.getValues()[i], expectedData[i], 0); } }
@Test public void testInsertAtZero() { RandomSampleRepeater rsr = ConfigurationManager.getInstance(RandomSampleRepeater.class); rsr.randStreamStart = true; rsr.useRandSeed = false; rsr.initialize(); rsr.maxRepeatedSamples = 5; rsr.numInsertedSamples = 20; rsr.nextInsertionPoint = 5; // create a dummy DoubleData double[] data = new double[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; DoubleData dd = new DoubleData(data, 16000, 0); DoubleData extData = rsr.process(dd); double[] expectedData = new double[]{1, 2, 3, 4, 5, 1, 2, 6, 7, 8, 9, 10}; Assert.assertEquals(extData.getFirstSampleNumber(), 20, 0); Assert.assertEquals(extData.getValues().length, expectedData.length); for (int i = 0; i < expectedData.length; i++) { Assert.assertEquals(extData.getValues()[i], expectedData[i], 0); } }
System.arraycopy(inFeatures, startIndex, extFeatures, startIndex + insertLength, inFeatures.length - startIndex); numInsertedSamples += insertLength; nextInsertionPoint = computeNextInsertionPoint(); } else { extFeatures = inFeatures;