OnlineSpliceFrames Class Reference

#include <online-feature.h>

Inheritance diagram for OnlineSpliceFrames:
Collaboration diagram for OnlineSpliceFrames:

Public Member Functions

virtual int32 Dim () const
 
virtual bool IsLastFrame (int32 frame) const
 Returns true if this is the last frame. More...
 
virtual BaseFloat FrameShiftInSeconds () const
 
virtual int32 NumFramesReady () const
 returns the feature dimension. More...
 
virtual void GetFrame (int32 frame, VectorBase< BaseFloat > *feat)
 Gets the feature vector for this frame. More...
 
 OnlineSpliceFrames (const OnlineSpliceOptions &opts, OnlineFeatureInterface *src)
 
- Public Member Functions inherited from OnlineFeatureInterface
virtual void GetFrames (const std::vector< int32 > &frames, MatrixBase< BaseFloat > *feats)
 This is like GetFrame() but for a collection of frames. More...
 
virtual ~OnlineFeatureInterface ()
 Virtual destructor. More...
 

Private Attributes

int32 left_context_
 
int32 right_context_
 
OnlineFeatureInterfacesrc_
 

Detailed Description

Definition at line 458 of file online-feature.h.

Constructor & Destructor Documentation

◆ OnlineSpliceFrames()

OnlineSpliceFrames ( const OnlineSpliceOptions opts,
OnlineFeatureInterface src 
)
inline

Definition at line 481 of file online-feature.h.

482  :
483  left_context_(opts.left_context), right_context_(opts.right_context),
484  src_(src) { }
OnlineFeatureInterface * src_

Member Function Documentation

◆ Dim()

virtual int32 Dim ( ) const
inlinevirtual

Implements OnlineFeatureInterface.

Definition at line 463 of file online-feature.h.

463  {
464  return src_->Dim() * (1 + left_context_ + right_context_);
465  }
OnlineFeatureInterface * src_
virtual int32 Dim() const =0

◆ FrameShiftInSeconds()

virtual BaseFloat FrameShiftInSeconds ( ) const
inlinevirtual

Implements OnlineFeatureInterface.

Definition at line 470 of file online-feature.h.

470  {
471  return src_->FrameShiftInSeconds();
472  }
virtual BaseFloat FrameShiftInSeconds() const =0
OnlineFeatureInterface * src_

◆ GetFrame()

void GetFrame ( int32  frame,
VectorBase< BaseFloat > *  feat 
)
virtual

Gets the feature vector for this frame.

Before calling this for a given frame, it is assumed that you called NumFramesReady() and it returned a number greater than "frame". Otherwise this call will likely crash with an assert failure. This function is not declared const, in case there is some kind of caching going on, but most of the time it shouldn't modify the class.

Implements OnlineFeatureInterface.

Definition at line 504 of file online-feature.cc.

References OnlineFeatureInterface::Dim(), VectorBase< Real >::Dim(), OnlineFeatureInterface::GetFrame(), KALDI_ASSERT, rnnlm::n, OnlineFeatureInterface::NumFramesReady(), OnlineCmvn::NumFramesReady(), and OnlineCmvn::src_.

504  {
506  KALDI_ASSERT(frame >= 0 && frame < NumFramesReady());
507  int32 dim_in = src_->Dim();
508  KALDI_ASSERT(feat->Dim() == dim_in * (1 + left_context_ + right_context_));
509  int32 T = src_->NumFramesReady();
510  for (int32 t2 = frame - left_context_; t2 <= frame + right_context_; t2++) {
511  int32 t2_limited = t2;
512  if (t2_limited < 0) t2_limited = 0;
513  if (t2_limited >= T) t2_limited = T - 1;
514  int32 n = t2 - (frame - left_context_); // 0 for left-most frame,
515  // increases to the right.
516  SubVector<BaseFloat> part(*feat, n * dim_in, dim_in);
517  src_->GetFrame(t2_limited, &part);
518  }
519 }
virtual void GetFrame(int32 frame, VectorBase< BaseFloat > *feat)=0
Gets the feature vector for this frame.
kaldi::int32 int32
struct rnnlm::@11::@12 n
OnlineFeatureInterface * src_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
virtual int32 NumFramesReady() const
returns the feature dimension.
virtual int32 NumFramesReady() const =0
returns the feature dimension.
virtual int32 Dim() const =0

◆ IsLastFrame()

virtual bool IsLastFrame ( int32  frame) const
inlinevirtual

Returns true if this is the last frame.

Frame indices are zero-based, so the first frame is zero. IsLastFrame(-1) will return false, unless the file is empty (which is a case that I'm not sure all the code will handle, so be careful). This function may return false for some frame if we haven't yet decided to terminate decoding, but later true if we decide to terminate decoding. This function exists mainly to correctly handle end effects in feature extraction, and is not a mechanism to determine how many frames are in the decodable object (as it used to be, and for backward compatibility, still is, in the Decodable interface).

Implements OnlineFeatureInterface.

Definition at line 467 of file online-feature.h.

467  {
468  return src_->IsLastFrame(frame);
469  }
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
OnlineFeatureInterface * src_

◆ NumFramesReady()

int32 NumFramesReady ( ) const
virtual

returns the feature dimension.

Returns the total number of frames, since the start of the utterance, that are now available. In an online-decoding context, this will likely increase with time as more data becomes available.

Implements OnlineFeatureInterface.

Definition at line 496 of file online-feature.cc.

References OnlineFeatureInterface::IsLastFrame(), OnlineFeatureInterface::NumFramesReady(), and OnlineCmvn::src_.

496  {
497  int32 num_frames = src_->NumFramesReady();
498  if (num_frames > 0 && src_->IsLastFrame(num_frames - 1))
499  return num_frames;
500  else
501  return std::max<int32>(0, num_frames - right_context_);
502 }
kaldi::int32 int32
virtual bool IsLastFrame(int32 frame) const =0
Returns true if this is the last frame.
OnlineFeatureInterface * src_
virtual int32 NumFramesReady() const =0
returns the feature dimension.

Member Data Documentation

◆ left_context_

int32 left_context_
private

Definition at line 487 of file online-feature.h.

◆ right_context_

int32 right_context_
private

Definition at line 488 of file online-feature.h.

◆ src_

OnlineFeatureInterface* src_
private

Definition at line 489 of file online-feature.h.


The documentation for this class was generated from the following files: