public override Data getData()
        {
            object obj = null;

            if (this.streamEndReached)
            {
                if (!this.utteranceEndSent)
                {
                    obj = new DataEndSignal(this.getDuration());
                    this.utteranceEndSent = true;
                }
            }
            else if (!this.utteranceStarted)
            {
                this.utteranceStarted = true;
                obj = new DataStartSignal(this.sampleRate);
            }
            else if (this.dataStream != null)
            {
                do
                {
                    obj = this.readNextFrame();
                }while ((DoubleData)obj != null && this.getDuration() < this.timeFrame.getStart());
                if (((DoubleData)obj == null || this.getDuration() > this.timeFrame.getEnd()) && !this.utteranceEndSent)
                {
                    obj = new DataEndSignal(this.getDuration());
                    this.utteranceEndSent = true;
                    this.streamEndReached = true;
                }
            }
            else
            {
                this.logger.warning("Input stream is not set");
                if (!this.utteranceEndSent)
                {
                    obj = new DataEndSignal(this.getDuration());
                    this.utteranceEndSent = true;
                }
            }
            object obj2 = obj;
            Data   result;

            if (obj2 != null)
            {
                if ((result = (obj2 as Data)) == null)
                {
                    throw new IncompatibleClassChangeError();
                }
            }
            else
            {
                result = null;
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Reads and returns the next Data from the InputStream of
        /// StreamDataSource, return null if no data is read and end of file is
        /// reached.
        /// </summary>
        /// <returns>the next Data or <code>null</code> if none is available</returns>
        public override IData GetData()
        {
            IData output = null;

            if (_streamEndReached)
            {
                if (!_utteranceEndSent)
                {
                    // since 'firstSampleNumber' starts at 0, the last
                    // sample number should be 'totalValuesRead - 1'
                    output            = new DataEndSignal(Duration);
                    _utteranceEndSent = true;
                }
            }
            else
            {
                if (!_utteranceStarted)
                {
                    _utteranceStarted = true;
                    output            = new DataStartSignal(SampleRate);
                }
                else
                {
                    if (_dataStream != null)
                    {
                        do
                        {
                            output = ReadNextFrame();
                        }while (output != null && Duration < _timeFrame.Start);

                        if ((output == null || Duration > _timeFrame.End) &&
                            !_utteranceEndSent)
                        {
                            output            = new DataEndSignal(Duration);
                            _utteranceEndSent = true;
                            _streamEndReached = true;
                        }
                    }
                    else
                    {
                        this.LogInfo("Input stream is not set");
                        if (!_utteranceEndSent)
                        {
                            output            = new DataEndSignal(Duration);
                            _utteranceEndSent = true;
                        }
                    }
                }
            }
            return(output);
        }
Example #3
0
        public override Data getData()
        {
            object obj;

            if (this.curPoint == -1)
            {
                obj = new DataStartSignal(this.sampleRate);
                this.curPoint++;
            }
            else
            {
                if (this.curPoint == this.numPoints)
                {
                    if (this.numPoints > 0)
                    {
                        this.firstSampleNumber = this.firstSampleNumber - (long)this.frameShift + (long)this.frameSize - 1L;
                    }
                    int  num      = this.curPoint;
                    int  num2     = this.cepstrumLength;
                    int  num3     = (num2 != -1) ? (num / num2) : (-num);
                    int  i        = (num3 - 1) * this.frameShift + this.frameSize;
                    long duration = ByteCodeHelper.d2l((double)i / (double)this.sampleRate * 1000.0);
                    obj = new DataEndSignal(duration);
                    try
                    {
                        this.binaryStream.close();
                        this.curPoint++;
                    }
                    catch (IOException ex)
                    {
                        throw new DataProcessingException("IOException closing cepstrum stream", ex);
                    }
                    goto IL_1B5;
                }
                if (this.curPoint > this.numPoints)
                {
                    obj = null;
                }
                else
                {
                    double[] array = new double[this.cepstrumLength];
                    int      i     = 0;
                    while (i < this.cepstrumLength)
                    {
                        try
                        {
                            if (this.bigEndian)
                            {
                                array[i] = (double)this.binaryStream.readFloat();
                            }
                            else
                            {
                                array[i] = (double)Utilities.readLittleEndianFloat(this.binaryStream);
                            }
                            this.curPoint++;
                        }
                        catch (IOException ex4)
                        {
                            throw new DataProcessingException("IOException reading from cepstrum stream", ex4);
                        }
                        i++;
                        continue;
                    }
                    obj = new DoubleData(array, this.sampleRate, this.firstSampleNumber);
                    this.firstSampleNumber += (long)this.frameShift;
                }
            }
IL_1B5:
            object obj2 = obj;
            Data result;

            if (obj2 != null)
            {
                if ((result = (obj2 as Data)) == null)
                {
                    throw new IncompatibleClassChangeError();
                }
            }
            else
            {
                result = null;
            }
            return(result);
        }
 /** Handles the last element in a feature-stream.
  * /// @param dataEndSignal*/
 protected void handleDataEndSignal(DataEndSignal dataEndSignal)
 {
     // we don't treat the end-signal here, but extending classes might do
 }
Example #5
0
        /// <summary>
        /// Returns the next Data object, which is the mel cepstrum of the input frame. However, it can also be other Data objects like DataStartSignal.
        /// </summary>
        /// <returns>
        /// The next available Data object, returns null if no Data object is available.
        /// </returns>
        /// <exception cref="System.Exception">
        /// IOException closing cepstrum stream
        /// or
        /// IOException reading from cepstrum stream
        /// </exception>
        public override IData GetData()
        {
            IData data;

            if (_curPoint == -1)
            {
                data = new DataStartSignal(_sampleRate);
                _curPoint++;
            }
            else if (_curPoint == _numPoints)
            {
                if (_numPoints > 0)
                {
                    _firstSampleNumber =
                        (_firstSampleNumber - _frameShift + _frameSize - 1);
                }
                // send a DataEndSignal
                var numberFrames = _curPoint / _cepstrumLength;
                var totalSamples = (numberFrames - 1) * _frameShift + _frameSize;
                var duration     = (long)
                                   ((totalSamples / (double)_sampleRate) * 1000.0);

                data = new DataEndSignal(duration);

                try {
                    if (_binary)
                    {
                        _binaryStream.Close();
                    }
                    else
                    {
                        _est.Close();
                    }
                    _curPoint++;
                } catch (IOException ioe) {
                    throw new Exception("IOException closing cepstrum stream", ioe);
                }
            }
            else if (_curPoint > _numPoints)
            {
                data = null;
            }
            else
            {
                var vectorData = new double[_cepstrumLength];

                for (var i = 0; i < _cepstrumLength; i++)
                {
                    try {
                        if (_binary)
                        {
                            if (_bigEndian)
                            {
                                vectorData[i] = _binaryStream.ReadFloat();
                            }
                            else
                            {
                                vectorData[i] = Utilities.ReadLittleEndianFloat(_binaryStream);
                            }
                        }
                        else
                        {
                            vectorData[i] = _est.GetFloat("cepstrum data");
                        }
                        _curPoint++;
                    } catch (IOException ioe) {
                        throw new Exception("IOException reading from cepstrum stream", ioe);
                    }
                }

                // System.out.println("Read: " + curPoint);
                data = new DoubleData
                           (vectorData, _sampleRate, _firstSampleNumber);
                _firstSampleNumber += _frameShift;
                // System.out.println(data);
            }
            return(data);
        }