예제 #1
0
        public override Data getData()
        {
            while (this.curInBufferSize < this.blockSizeSamples || this.curInBufferSize == 0)
            {
                Data data = this.getPredecessor().getData();
                if (data is DataStartSignal)
                {
                    this.sampleRate        = ((DataStartSignal)data).getSampleRate();
                    this.blockSizeSamples  = (int)Math.round((double)this.sampleRate * this.blockSizeMs / 1000.0);
                    this.curInBufferSize   = 0;
                    this.curFirstSamplePos = 0;
                    this.inBuffer.clear();
                }
                if (!(data is DoubleData))
                {
                    return(data);
                }
                DoubleData doubleData = (DoubleData)data;
                this.inBuffer.add(doubleData);
                this.curInBufferSize += doubleData.getValues().Length;
            }
            double[] array             = new double[this.blockSizeSamples];
            int      num               = 0;
            long     firstSampleNumber = ((DoubleData)this.inBuffer.get(0)).getFirstSampleNumber() + (long)this.curFirstSamplePos;

            while (!this.inBuffer.isEmpty())
            {
                DoubleData doubleData2 = (DoubleData)this.inBuffer.remove(0);
                double[]   values      = doubleData2.getValues();
                int        num2        = Math.min(this.blockSizeSamples - num, values.Length - this.curFirstSamplePos);
                ByteCodeHelper.arraycopy_primitive_8(values, this.curFirstSamplePos, array, num, num2);
                if (num2 < values.Length - this.curFirstSamplePos)
                {
                    if (!DataBlocker.assertionsDisabled && !this.inBuffer.isEmpty())
                    {
                        throw new AssertionError();
                    }
                    this.curFirstSamplePos += num2;
                    this.inBuffer.add(0, doubleData2);
                    break;
                }
                else
                {
                    num += num2;
                    this.curFirstSamplePos = 0;
                }
            }
            this.curInBufferSize = ((!this.inBuffer.isEmpty()) ? (((DoubleData)this.inBuffer.get(0)).getValues().Length - this.curFirstSamplePos) : 0);
            return(new DoubleData(array, this.sampleRate, firstSampleNumber));
        }
예제 #2
0
        public static FloatData toFloatData(Data data)
        {
            FloatData result;

            if (data is FloatData)
            {
                result = (FloatData)data;
            }
            else
            {
                if (!(data is DoubleData))
                {
                    string text = new StringBuilder().append("data type '").append(Object.instancehelper_getClass(data)).append("' is not supported").toString();

                    throw new IllegalArgumentException(text);
                }
                DoubleData doubleData = (DoubleData)data;
                result = new FloatData(MatrixUtils.double2float(doubleData.getValues()), doubleData.getSampleRate(), doubleData.getFirstSampleNumber());
            }
            return(result);
        }