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...
 
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

◆ Options

typedef F::Options Options

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

Constructor & Destructor Documentation

◆ OfflineFeatureTpl() [1/2]

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() [2/2]

OfflineFeatureTpl ( const OfflineFeatureTpl< F > &  other)
inline

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

159  :
160  computer_(other.computer_),
161  feature_window_function_(other.feature_window_function_) { }
FeatureWindowFunction feature_window_function_

Member Function Documentation

◆ Compute() [1/2]

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

Definition at line 60 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().

63  {
64  KALDI_ASSERT(output != NULL);
65  int32 rows_out = NumFrames(wave.Dim(), computer_.GetFrameOptions()),
66  cols_out = computer_.Dim();
67  if (rows_out == 0) {
68  output->Resize(0, 0);
69  return;
70  }
71  output->Resize(rows_out, cols_out);
72  Vector<BaseFloat> window; // windowed waveform.
73  bool use_raw_log_energy = computer_.NeedRawLogEnergy();
74  for (int32 r = 0; r < rows_out; r++) { // r is frame index.
75  BaseFloat raw_log_energy = 0.0;
76  ExtractWindow(0, wave, r, computer_.GetFrameOptions(),
77  feature_window_function_, &window,
78  (use_raw_log_energy ? &raw_log_energy : NULL));
79 
80  SubVector<BaseFloat> output_row(*output, r);
81  computer_.Compute(raw_log_energy, vtln_warp, &window, &output_row);
82  }
83 }
FeatureWindowFunction feature_window_function_
kaldi::int32 int32
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:185
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).

◆ Compute() [2/2]

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

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

References OfflineFeatureTpl< F >::Compute().

89  {
90  OfflineFeatureTpl<F> temp(*this);
91  // call the non-const version of Compute() on a temporary copy of this object.
92  // This is a workaround for const-ness that may sometimes be useful in
93  // multi-threaded code, although it's not optimally efficient.
94  temp.Compute(wave, vtln_warp, output);
95 }

◆ ComputeFeatures()

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_ASSERT, KALDI_ERR, and kaldi::ResampleWaveform().

Referenced by 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  ! 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 to allow "
44  << " downsampling the waveform).";
45  else if (new_sample_freq > sample_freq &&
46  ! computer_.GetFrameOptions().allow_upsample)
47  KALDI_ERR << "Waveform and config sample Frequency mismatch: "
48  << sample_freq << " .vs " << new_sample_freq
49  << " (use --allow-upsample=true option to allow "
50  << " upsampling the waveform).";
51  // Resample the waveform.
52  Vector<BaseFloat> resampled_wave(wave);
53  ResampleWaveform(sample_freq, wave,
54  new_sample_freq, &resampled_wave);
55  Compute(resampled_wave, vtln_warp, output);
56  }
57 }
void Compute(const VectorBase< BaseFloat > &wave, BaseFloat vtln_warp, Matrix< BaseFloat > *output)
void ResampleWaveform(BaseFloat orig_freq, const VectorBase< BaseFloat > &wave, BaseFloat new_freq, Vector< BaseFloat > *new_wave)
Downsample or upsample a waveform.
Definition: resample.cc:368
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Dim()

int32 Dim ( ) const
inline

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

156 { return computer_.Dim(); }

◆ operator=()

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

Member Data Documentation

◆ computer_

F computer_
private

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

◆ feature_window_function_

FeatureWindowFunction feature_window_function_
private

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


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