feature-common.h
Go to the documentation of this file.
1 // feat/feature-common.h
2 
3 // Copyright 2016 Johns Hopkins University (author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABILITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_FEAT_FEATURE_COMMON_H_
21 #define KALDI_FEAT_FEATURE_COMMON_H_
22 
23 #include <map>
24 #include <string>
25 #include "feat/feature-window.h"
26 
27 namespace kaldi {
30 
31 
32 
37  // .. more would go here.
38 };
39 
46  public:
48 
52  return opts_.frame_opts;
53  }
54 
56  int32 Dim() const;
57 
61  bool NeedRawLogEnergy() const { return true; }
62 
66  opts_(opts) { }
67 
70 
92  void Compute(BaseFloat signal_raw_log_energy,
93  BaseFloat vtln_warp,
94  VectorBase<BaseFloat> *signal_frame,
95  VectorBase<BaseFloat> *feature);
96 
97  private:
98  // disallow assignment.
99  ExampleFeatureComputer &operator = (const ExampleFeatureComputer &in);
100  Options opts_;
101 };
102 
103 
110 template <class F>
112  public:
113  typedef typename F::Options Options;
114 
115  // Note: feature_window_function_ is the windowing function, which initialized
116  // using the options class, that we cache at this level.
117  OfflineFeatureTpl(const Options &opts):
118  computer_(opts),
119  feature_window_function_(computer_.GetFrameOptions()) { }
120 
121  // Internal (and back-compatibility) interface for computing features, which
122  // requires that the user has already checked that the sampling frequency
123  // of the waveform is equal to the sampling frequency specified in
124  // the frame-extraction options.
125  void Compute(const VectorBase<BaseFloat> &wave,
126  BaseFloat vtln_warp,
127  Matrix<BaseFloat> *output);
128 
129  // This const version of Compute() is a wrapper that
130  // calls the non-const version on a temporary object.
131  // It's less efficient than the non-const version.
132  void Compute(const VectorBase<BaseFloat> &wave,
133  BaseFloat vtln_warp,
134  Matrix<BaseFloat> *output) const;
135 
151  void ComputeFeatures(const VectorBase<BaseFloat> &wave,
152  BaseFloat sample_freq,
153  BaseFloat vtln_warp,
154  Matrix<BaseFloat> *output);
155 
156  int32 Dim() const { return computer_.Dim(); }
157 
158  // Copy constructor.
160  computer_(other.computer_),
161  feature_window_function_(other.feature_window_function_) { }
162  private:
163  // Disallow assignment.
164  OfflineFeatureTpl<F> &operator =(const OfflineFeatureTpl<F> &other);
165 
168 };
169 
171 } // namespace kaldi
172 
173 
174 #include "feat/feature-common-inl.h"
175 
176 #endif // KALDI_FEAT_FEATURE_COMMON_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
OfflineFeatureTpl(const OfflineFeatureTpl< F > &other)
FeatureWindowFunction feature_window_function_
ExampleFeatureComputer(const ExampleFeatureComputerOptions &opts)
constructor from options class; it should not store a reference or pointer to the options class but s...
kaldi::int32 int32
ExampleFeatureComputerOptions Options
const FrameExtractionOptions & GetFrameOptions() const
Returns a reference to the frame-extraction options class, which will be part of our own options clas...
This class is only added for documentation, it is not intended to ever be used.
FrameExtractionOptions frame_opts
This class is only added for documentation, it is not intended to ever be used.
This templated class is intended for offline feature extraction, i.e.
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
OfflineFeatureTpl(const Options &opts)
bool NeedRawLogEnergy() const
Returns true if this function may inspect the raw log-energy of the signal (before windowing and pre-...