2020#ifndef KALDI_FEAT_FEATURE_COMMON_INL_H_
2121#define KALDI_FEAT_FEATURE_COMMON_INL_H_
2222
23+ #include " feat/resample.h"
2324// Do not include this file directly. It is included by feat/feature-common.h
2425
2526namespace kaldi {
2627
28+ template <class F >
29+ void OfflineFeatureTpl<F>::ComputeFeatures(
30+ const VectorBase<BaseFloat> &wave,
31+ BaseFloat sample_freq,
32+ BaseFloat vtln_warp,
33+ Matrix<BaseFloat> *output) {
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+ }
59+
60+ template <class F >
61+ void OfflineFeatureTpl<F>::ComputeFeatures(
62+ const VectorBase<BaseFloat> &wave,
63+ BaseFloat sample_freq,
64+ BaseFloat vtln_warp,
65+ Matrix<BaseFloat> *output) const {
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+ }
73+
2774template <class F >
2875void OfflineFeatureTpl<F>::Compute(
2976 const VectorBase<BaseFloat> &wave,
3077 BaseFloat vtln_warp,
31- Matrix<BaseFloat> *output,
32- Vector<BaseFloat> *deprecated_wave_remainder) {
78+ Matrix<BaseFloat> *output) {
3379 KALDI_ASSERT (output != NULL );
3480 int32 rows_out = NumFrames (wave.Dim (), computer_.GetFrameOptions ()),
3581 cols_out = computer_.Dim ();
3682 if (rows_out == 0 ) {
3783 output->Resize (0 , 0 );
38- if (deprecated_wave_remainder != NULL )
39- *deprecated_wave_remainder = wave;
4084 return ;
4185 }
4286 output->Resize (rows_out, cols_out);
43- if (deprecated_wave_remainder != NULL )
44- ExtractWaveformRemainder (wave, computer_.GetFrameOptions (),
45- deprecated_wave_remainder);
4687 Vector<BaseFloat> window; // windowed waveform.
4788 bool use_raw_log_energy = computer_.NeedRawLogEnergy ();
4889 for (int32 r = 0 ; r < rows_out; r++) { // r is frame index.
@@ -60,13 +101,12 @@ template <class F>
60101void OfflineFeatureTpl<F>::Compute(
61102 const VectorBase<BaseFloat> &wave,
62103 BaseFloat vtln_warp,
63- Matrix<BaseFloat> *output,
64- Vector<BaseFloat> *deprecated_wave_remainder) const {
104+ Matrix<BaseFloat> *output) const {
65105 OfflineFeatureTpl<F> temp (*this );
66106 // call the non-const version of Compute() on a temporary copy of this object.
67107 // This is a workaround for const-ness that may sometimes be useful in
68108 // multi-threaded code, although it's not optimally efficient.
69- temp.Compute (wave, vtln_warp, output, deprecated_wave_remainder );
109+ temp.Compute (wave, vtln_warp, output);
70110}
71111
72112} // end namespace kaldi
0 commit comments