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)
 
void Compute (const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output) const
 
void ComputeFeatures (const VectorBase< BaseFloat > &wave, BaseFloat sample_freq, BaseFloat vtln_warp, Matrix< BaseFloat > *output)
 Computes the features for one file (one sequence of features). More...
 
void ComputeFeatures (const VectorBase< BaseFloat > &wave, BaseFloat sample_freq, BaseFloat vtln_warp, Matrix< BaseFloat > *output) const
 This const version of ComputeFeatures() is a wrapper that calls the non-const ComputeFeatures() on a temporary object that is a copy of *this. More...
 
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 169 of file feature-common.h.

169  :
170  computer_(other.computer_),
171  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 
)

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

References VectorBase< Real >::Dim(), 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().

78  {
79  KALDI_ASSERT(output != NULL);
80  int32 rows_out = NumFrames(wave.Dim(), computer_.GetFrameOptions()),
81  cols_out = computer_.Dim();
82  if (rows_out == 0) {
83  output->Resize(0, 0);
84  return;
85  }
86  output->Resize(rows_out, cols_out);
87  Vector<BaseFloat> window; // windowed waveform.
88  bool use_raw_log_energy = computer_.NeedRawLogEnergy();
89  for (int32 r = 0; r < rows_out; r++) { // r is frame index.
90  BaseFloat raw_log_energy = 0.0;
91  ExtractWindow(0, wave, r, computer_.GetFrameOptions(),
92  feature_window_function_, &window,
93  (use_raw_log_energy ? &raw_log_energy : NULL));
94 
95  SubVector<BaseFloat> output_row(*output, r);
96  computer_.Compute(raw_log_energy, vtln_warp, &window, &output_row);
97  }
98 }
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)
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:63
void Compute ( const VectorBase< BaseFloat > &  wave,
BaseFloat  vtln_warp,
Matrix< BaseFloat > *  output 
) const

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

References OfflineFeatureTpl< F >::Compute().

104  {
105  OfflineFeatureTpl<F> temp(*this);
106  // call the non-const version of Compute() on a temporary copy of this object.
107  // This is a workaround for const-ness that may sometimes be useful in
108  // multi-threaded code, although it's not optimally efficient.
109  temp.Compute(wave, vtln_warp, output);
110 }
void ComputeFeatures ( const VectorBase< BaseFloat > &  wave,
BaseFloat  sample_freq,
BaseFloat  vtln_warp,
Matrix< BaseFloat > *  output 
)

Computes the features for one file (one sequence of features).

This is the newer interface where you specify the sample frequency of the input waveform.

Parameters
[in]waveThe input waveform
[in]sample_freqThe sampling frequency with which 'wave' was sampled. if sample_freq is higher than the frequency specified in the config, we will downsample the waveform, but if lower, it's an error.
[in]vtln_warpThe VTLN warping factor (will normally be 1.0)
[out]outputThe matrix of features, where the row-index is the frame index.

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

References kaldi::DownsampleWaveForm(), KALDI_ASSERT, and KALDI_ERR.

Referenced by OfflineFeatureTpl< F >::ComputeFeatures(), and main().

33  {
34  KALDI_ASSERT(output != NULL);
35  BaseFloat new_sample_freq = computer_.GetFrameOptions().samp_freq;
36  if (sample_freq == new_sample_freq)
37  Compute(wave, vtln_warp, output);
38  else {
39  if (new_sample_freq < sample_freq) {
40  if (! computer_.GetFrameOptions().allow_downsample)
41  KALDI_ERR << "Waveform and config sample Frequency mismatch: "
42  << sample_freq << " .vs " << new_sample_freq
43  << " ( use --allow_downsample=true option to allow "
44  << " downsampling the waveform).";
45 
46  // Downsample the waveform.
47  Vector<BaseFloat> downsampled_wave(wave);
48  DownsampleWaveForm(sample_freq, wave,
49  new_sample_freq, &downsampled_wave);
50  Compute(downsampled_wave, vtln_warp, output);
51  } else
52  KALDI_ERR << "The waveform is allowed to get downsampled."
53  << "New sample Frequency " << new_sample_freq
54  << " is larger than waveform original sampling frequency "
55  << sample_freq;
56 
57  }
58 }
void Compute(const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output)
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:127
void DownsampleWaveForm(BaseFloat orig_freq, const VectorBase< BaseFloat > &wave, BaseFloat new_freq, Vector< BaseFloat > *new_wave)
Downsample a waveform.
Definition: resample.cc:368
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void ComputeFeatures ( const VectorBase< BaseFloat > &  wave,
BaseFloat  sample_freq,
BaseFloat  vtln_warp,
Matrix< BaseFloat > *  output 
) const

This const version of ComputeFeatures() is a wrapper that calls the non-const ComputeFeatures() on a temporary object that is a copy of *this.

It is not as efficient because of the overhead of copying *this.

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

References OfflineFeatureTpl< F >::ComputeFeatures().

65  {
66  OfflineFeatureTpl<F> temp(*this);
67  // This const version of ComputeFeatures() is a wrapper that
68  // calls the non-const ComputeFeatures() on a temporary object
69  // that is a copy of *this. It is not as efficient because of the
70  // overhead of copying *this.
71  temp.ComputeFeatures(wave, vtln_warp, output);
72 }
int32 Dim ( ) const
inline

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

References OfflineFeatureTpl< F >::computer_.

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

Member Data Documentation

F computer_
private

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

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

FeatureWindowFunction feature_window_function_
private

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


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