Logo Search packages:      
Sourcecode: libgdf version File versions  Download package

void gdf::Reader::getSignals ( std::vector< std::vector< double > > &  buffer,
double  start_time = 0,
double  end_time = -1,
std::vector< uint16 >  signal_indices = std::vector<uint16>() 
)

Read Signals from file into buffer (physical units)

Sample values are converted to physical units.

Parameters:
[out]buffervector; each element is a channel.
[in]start_timesamples with n >= start_time*fs are loaded.
[in]end_timesamples with n < end_time*fs are loaded. end_time = -1 loads the complete signal.
[in]signal_indicesvector with signal indices that should be loaded. If empty, all signals are loaded.

Definition at line 136 of file Reader.cpp.

References gdf::Channel::deblitSamplesPhys(), gdf::Record::getChannel(), and getRecordPtr().

    {
        using boost::numeric_cast;

        if( signal_indices.size() == 0 )
        {
            signal_indices.resize( m_header.getMainHeader_readonly().get_num_signals() );
            for( size_t i=0; i<m_header.getMainHeader_readonly().get_num_signals(); i++ )
                signal_indices[i] = i;
        }

        buffer.resize( signal_indices.size() );

        double record_rate = m_header.getMainHeader_readonly().get_datarecord_duration(1) / m_header.getMainHeader_readonly().get_datarecord_duration(0);
        size_t record = boost::numeric_cast<size_t>( floor( start_time * record_rate ) );


        std::vector<size_t> start, samples_to_go, readpos, writepos;

        start.resize( signal_indices.size() );
        samples_to_go.resize( signal_indices.size() );
        readpos.resize( signal_indices.size() );
        writepos.resize( signal_indices.size() );
        for( size_t i=0; i<signal_indices.size(); i++ )
        {
            SignalHeader *sh = &m_header.getSignalHeader( signal_indices[i] );
            double fs = sh->get_samplerate( );
            start[i] = boost::numeric_cast<size_t>( floor( start_time * fs ) );
            samples_to_go[i] = boost::numeric_cast<size_t>( floor( end_time * fs ) );
            if( end_time < 0 )
                samples_to_go[i] = boost::numeric_cast<size_t>( m_header.getMainHeader_readonly().get_num_datarecords() * sh->get_samples_per_record() );
            samples_to_go[i] = std::min( samples_to_go[i], boost::numeric_cast<size_t>( m_header.getMainHeader_readonly().get_num_datarecords() * sh->get_samples_per_record() ) );
            samples_to_go[i] -= start[i];
            buffer[i].resize( boost::numeric_cast<size_t>( samples_to_go[i] ) );
            readpos[i] = start[i] % sh->get_samples_per_record();
        }

        while( sum(samples_to_go) > 0 )
        {
            Record *r = getRecordPtr( record );
            for( size_t i=0; i<signal_indices.size(); i++ )
            {
                SignalHeader *sh = &m_header.getSignalHeader( signal_indices[i] );
                size_t n = std::min( boost::numeric_cast<size_t>(sh->get_samples_per_record( )) - readpos[i], samples_to_go[i] );
                r->getChannel( signal_indices[i] )->deblitSamplesPhys( &buffer[i][writepos[i]], readpos[i], n );
                samples_to_go[i] -= n;
                writepos[i] += n;
                readpos[i] = 0;
            }
            record++;
        }
    }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index