OnlineFeInput< E > Class Template Reference

#include <online-feat-input.h>

Inheritance diagram for OnlineFeInput< E >:
Collaboration diagram for OnlineFeInput< E >:

Public Member Functions

 OnlineFeInput (OnlineAudioSourceItf *au_src, E *fe, const int32 frame_size, const int32 frame_shift, const bool snip_edges=true)
 
virtual int32 Dim () const
 
virtual bool Compute (Matrix< BaseFloat > *output)
 
- Public Member Functions inherited from OnlineFeatInputItf
virtual ~OnlineFeatInputItf ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (OnlineFeInput)
 

Private Attributes

OnlineAudioSourceItfsource_
 
E * extractor_
 
const int32 frame_size_
 
const int32 frame_shift_
 
Vector< BaseFloatwave_
 
Vector< BaseFloatwave_remainder_
 
FrameExtractionOptions frame_opts_
 

Detailed Description

template<class E>
class kaldi::OnlineFeInput< E >

Definition at line 272 of file online-feat-input.h.

Constructor & Destructor Documentation

◆ OnlineFeInput()

OnlineFeInput ( OnlineAudioSourceItf au_src,
E *  fe,
const int32  frame_size,
const int32  frame_shift,
const bool  snip_edges = true 
)

Definition at line 300 of file online-feat-input.h.

References FrameExtractionOptions::frame_length_ms, OnlineFeInput< E >::frame_opts_, FrameExtractionOptions::frame_shift_ms, FrameExtractionOptions::samp_freq, and FrameExtractionOptions::snip_edges.

303  : source_(au_src), extractor_(fe),
304  frame_size_(frame_size), frame_shift_(frame_shift) {
305  // we need a FrameExtractionOptions to call NumFrames()
306  // 1000 is just a fake sample rate which equates ms and samples
307  frame_opts_.samp_freq = 1000;
308  frame_opts_.frame_shift_ms = frame_shift;
309  frame_opts_.frame_length_ms = frame_size;
310  frame_opts_.snip_edges = snip_edges;
311 }
FrameExtractionOptions frame_opts_
OnlineAudioSourceItf * source_

Member Function Documentation

◆ Compute()

bool Compute ( Matrix< BaseFloat > *  output)
virtual

Implements OnlineFeatInputItf.

Definition at line 314 of file online-feat-input.h.

References OnlineFeInput< E >::extractor_, OnlineFeInput< E >::frame_opts_, OnlineFeInput< E >::frame_shift_, OnlineFeInput< E >::frame_size_, KALDI_ASSERT, KALDI_WARN, kaldi::NumFrames(), MatrixBase< Real >::NumRows(), VectorBase< Real >::Range(), OnlineAudioSourceItf::Read(), Matrix< Real >::Resize(), OnlineFeInput< E >::source_, and OnlineFeInput< E >::wave_remainder_.

314  {
315  MatrixIndexT nvec = output->NumRows(); // the number of output vectors
316  if (nvec <= 0) {
317  KALDI_WARN << "No feature vectors requested?!";
318  return true;
319  }
320 
321  // Prepare the input audio samples
322  int32 samples_req = frame_size_ + (nvec - 1) * frame_shift_;
323  Vector<BaseFloat> read_samples(samples_req);
324 
325  bool ans = source_->Read(&read_samples);
326 
327  Vector<BaseFloat> all_samples(wave_remainder_.Dim() + read_samples.Dim());
328  all_samples.Range(0, wave_remainder_.Dim()).CopyFromVec(wave_remainder_);
329  all_samples.Range(wave_remainder_.Dim(), read_samples.Dim()).
330  CopyFromVec(read_samples);
331 
332  // Extract the features
333  if (all_samples.Dim() >= frame_size_) {
334  // extract waveform remainder before calling Compute()
335  int32 num_frames = NumFrames(all_samples.Dim(), frame_opts_);
336  // offset is the amount at the start that has been extracted.
337  int32 offset = num_frames * frame_shift_;
338  int32 remaining_len = all_samples.Dim() - offset;
339  wave_remainder_.Resize(remaining_len);
340  KALDI_ASSERT(remaining_len >= 0);
341  if (remaining_len > 0)
342  wave_remainder_.CopyFromVec(SubVector<BaseFloat>(all_samples, offset, remaining_len));
343  extractor_->Compute(all_samples, 1.0, output);
344  } else {
345  output->Resize(0, 0);
346  wave_remainder_ = all_samples;
347  }
348 
349  return ans;
350 }
virtual bool Read(Vector< BaseFloat > *data)=0
FrameExtractionOptions frame_opts_
kaldi::int32 int32
Vector< BaseFloat > wave_remainder_
int32 MatrixIndexT
Definition: matrix-common.h:98
int32 NumFrames(int64 num_samples, const FrameExtractionOptions &opts, bool flush)
This function returns the number of frames that we can extract from a wave file with the given number...
OnlineAudioSourceItf * source_
#define KALDI_WARN
Definition: kaldi-error.h:150
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Definition: kaldi-matrix.h:64
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).

◆ Dim()

virtual int32 Dim ( ) const
inlinevirtual

Implements OnlineFeatInputItf.

Definition at line 282 of file online-feat-input.h.

References OnlineFeatInputItf::Compute().

282 { return extractor_->Dim(); }

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( OnlineFeInput< E >  )
private

Member Data Documentation

◆ extractor_

E* extractor_
private

Definition at line 288 of file online-feat-input.h.

Referenced by OnlineFeInput< E >::Compute().

◆ frame_opts_

FrameExtractionOptions frame_opts_
private

◆ frame_shift_

const int32 frame_shift_
private

Definition at line 290 of file online-feat-input.h.

Referenced by OnlineFeInput< E >::Compute().

◆ frame_size_

const int32 frame_size_
private

Definition at line 289 of file online-feat-input.h.

Referenced by OnlineFeInput< E >::Compute().

◆ source_

OnlineAudioSourceItf* source_
private

Definition at line 287 of file online-feat-input.h.

Referenced by OnlineFeInput< E >::Compute().

◆ wave_

Vector<BaseFloat> wave_
private

Definition at line 291 of file online-feat-input.h.

◆ wave_remainder_

Vector<BaseFloat> wave_remainder_
private

Definition at line 292 of file online-feat-input.h.

Referenced by OnlineFeInput< E >::Compute().


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