All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OfflineFeatureTpl< F > Class Template Reference

This templated class is intended for offline feature extraction, i.e. More...

#include <feature-common.h>

Collaboration diagram for OfflineFeatureTpl< F >:

Public Types

typedef F::Options Options
 

Public Member Functions

 OfflineFeatureTpl (const Options &opts)
 
void Compute (const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output, Vector< BaseFloat > *deprecated_wave_remainder=NULL)
 
void Compute (const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output, Vector< BaseFloat > *deprecated_wave_remainder=NULL) const
 
int32 Dim () const
 
 OfflineFeatureTpl (const OfflineFeatureTpl< F > &other)
 

Private Member Functions

OfflineFeatureTpl< F > & operator= (const OfflineFeatureTpl< F > &other)
 

Private Attributes

computer_
 
FeatureWindowFunction feature_window_function_
 

Detailed Description

template<class F>
class kaldi::OfflineFeatureTpl< F >

This templated class is intended for offline feature extraction, i.e.

where you have access to the entire signal at the start. It exists mainly to be drop-in replacement for the old (pre-2016) classes Mfcc, Plp and so on, for use in the offline case. In April 2016 we reorganized the online feature-computation code for greater modularity and to have correct support for the snip-edges=false option.

Definition at line 111 of file feature-common.h.

Member Typedef Documentation

typedef F::Options Options

Definition at line 113 of file feature-common.h.

Constructor & Destructor Documentation

OfflineFeatureTpl ( const Options opts)
inline

Definition at line 117 of file feature-common.h.

117  :
118  computer_(opts),
119  feature_window_function_(computer_.GetFrameOptions()) { }
FeatureWindowFunction feature_window_function_
OfflineFeatureTpl ( const OfflineFeatureTpl< F > &  other)
inline

Definition at line 144 of file feature-common.h.

144  :
145  computer_(other.computer_),
146  feature_window_function_(other.feature_window_function_) { }
FeatureWindowFunction feature_window_function_

Member Function Documentation

void Compute ( const VectorBase< BaseFloat > &  wave,
BaseFloat  vtln_warp,
Matrix< BaseFloat > *  output,
Vector< BaseFloat > *  deprecated_wave_remainder = NULL 
)

Definition at line 28 of file feature-common-inl.h.

References VectorBase< Real >::Dim(), kaldi::ExtractWaveformRemainder(), kaldi::ExtractWindow(), KALDI_ASSERT, kaldi::NumFrames(), and Matrix< Real >::Resize().

Referenced by OfflineFeatureTpl< F >::Compute(), main(), kaldi::TestOnlineAppendFeature(), kaldi::TestOnlineMfcc(), kaldi::TestOnlinePlp(), UnitTestHTKCompare1(), UnitTestHTKCompare2(), UnitTestHTKCompare3(), UnitTestHTKCompare4(), UnitTestHTKCompare5(), UnitTestHTKCompare6(), and UnitTestSimple().

32  {
33  KALDI_ASSERT(output != NULL);
34  int32 rows_out = NumFrames(wave.Dim(), computer_.GetFrameOptions()),
35  cols_out = computer_.Dim();
36  if (rows_out == 0) {
37  output->Resize(0, 0);
38  if (deprecated_wave_remainder != NULL)
39  *deprecated_wave_remainder = wave;
40  return;
41  }
42  output->Resize(rows_out, cols_out);
43  if (deprecated_wave_remainder != NULL)
44  ExtractWaveformRemainder(wave, computer_.GetFrameOptions(),
45  deprecated_wave_remainder);
46  Vector<BaseFloat> window; // windowed waveform.
47  bool use_raw_log_energy = computer_.NeedRawLogEnergy();
48  for (int32 r = 0; r < rows_out; r++) { // r is frame index.
49  BaseFloat raw_log_energy = 0.0;
50  ExtractWindow(0, wave, r, computer_.GetFrameOptions(),
51  feature_window_function_, &window,
52  (use_raw_log_energy ? &raw_log_energy : NULL));
53 
54  SubVector<BaseFloat> output_row(*output, r);
55  computer_.Compute(raw_log_energy, vtln_warp, &window, &output_row);
56  }
57 }
FeatureWindowFunction feature_window_function_
void ExtractWindow(int64 sample_offset, const VectorBase< BaseFloat > &wave, int32 f, const FrameExtractionOptions &opts, const FeatureWindowFunction &window_function, Vector< BaseFloat > *window, BaseFloat *log_energy_pre_window)
void ExtractWaveformRemainder(const VectorBase< BaseFloat > &wave, const FrameExtractionOptions &opts, Vector< BaseFloat > *wave_remainder)
float BaseFloat
Definition: kaldi-types.h:29
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...
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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).
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void Compute ( const VectorBase< BaseFloat > &  wave,
BaseFloat  vtln_warp,
Matrix< BaseFloat > *  output,
Vector< BaseFloat > *  deprecated_wave_remainder = NULL 
) const

Definition at line 60 of file feature-common-inl.h.

References OfflineFeatureTpl< F >::Compute().

64  {
65  OfflineFeatureTpl<F> temp(*this);
66  // call the non-const version of Compute() on a temporary copy of this object.
67  // This is a workaround for const-ness that may sometimes be useful in
68  // multi-threaded code, although it's not optimally efficient.
69  temp.Compute(wave, vtln_warp, output, deprecated_wave_remainder);
70 }
int32 Dim ( ) const
inline

Definition at line 141 of file feature-common.h.

References OfflineFeatureTpl< F >::computer_.

141 { return computer_.Dim(); }
OfflineFeatureTpl<F>& operator= ( const OfflineFeatureTpl< F > &  other)
private

Member Data Documentation

F computer_
private

Definition at line 151 of file feature-common.h.

Referenced by OfflineFeatureTpl< F >::Dim().

FeatureWindowFunction feature_window_function_
private

Definition at line 152 of file feature-common.h.


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