34 return frame * frame_shift;
36 int64 midpoint_of_frame = frame_shift * frame + frame_shift / 2,
37 beginning_of_frame = midpoint_of_frame - opts.
WindowSize() / 2;
38 return beginning_of_frame;
51 if (num_samples < frame_length)
54 return (1 + ((num_samples - frame_length) / frame_shift));
69 int32 num_frames = (num_samples + (frame_shift / 2)) / frame_shift;
81 while (num_frames > 0 && end_sample_of_last_frame > num_samples) {
83 end_sample_of_last_frame -= frame_shift;
91 if (dither_value == 0.0)
102 if (preemph_coeff == 0.0)
return;
103 KALDI_ASSERT(preemph_coeff >= 0.0 && preemph_coeff <= 1.0);
105 (*waveform)(
i) -= preemph_coeff * (*waveform)(
i-1);
106 (*waveform)(0) -= preemph_coeff * (*waveform)(0);
112 window.Resize(frame_length);
113 double a =
M_2PI / (frame_length-1);
114 for (
int32 i = 0;
i < frame_length;
i++) {
115 double i_fl =
static_cast<double>(
i);
117 window(
i) = 0.5 - 0.5*cos(a * i_fl);
121 window(
i) = sin(0.5 * a * i_fl);
123 window(
i) = 0.54 - 0.46*cos(a * i_fl);
125 window(
i) = pow(0.5 - 0.5*cos(a * i_fl), 0.85);
148 window->
Add(-window->
Sum() / frame_length);
150 if (log_energy_pre_window != NULL) {
152 std::numeric_limits<float>::epsilon());
153 *log_energy_pre_window =
Log(energy);
176 int64 num_samples = sample_offset + wave.
Dim(),
178 end_sample = start_sample + frame_length;
182 end_sample <= num_samples);
184 KALDI_ASSERT(sample_offset == 0 || start_sample >= sample_offset);
187 if (window->
Dim() != frame_length_padded)
192 int32 wave_start =
int32(start_sample - sample_offset),
193 wave_end = wave_start + frame_length;
194 if (wave_start >= 0 && wave_end <= wave.
Dim()) {
196 window->
Range(0, frame_length).CopyFromVec(
197 wave.
Range(wave_start, frame_length));
203 for (
int32 s = 0; s < frame_length; s++) {
204 int32 s_in_wave = s + wave_start;
205 while (s_in_wave < 0 || s_in_wave >= wave_dim) {
211 if (s_in_wave < 0) s_in_wave = - s_in_wave - 1;
212 else s_in_wave = 2 * wave_dim - 1 - s_in_wave;
214 (*window)(s) = wave(s_in_wave);
218 if (frame_length_padded > frame_length)
219 window->
Range(frame_length, frame_length_padded - frame_length).SetZero();
223 ProcessWindow(opts, window_function, &frame, log_energy_pre_window);
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Vector< BaseFloat > window
float RandGauss(struct RandomState *state=NULL)
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
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 MulElements(const VectorBase< Real > &v)
Multiply element-by-element by another vector.
int64 FirstSampleOfFrame(int32 frame, const FrameExtractionOptions &opts)
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...
Real * Data()
Returns a pointer to the start of the vector's data.
void ProcessWindow(const FrameExtractionOptions &opts, const FeatureWindowFunction &window_function, VectorBase< BaseFloat > *window, BaseFloat *log_energy_pre_window)
This function does all the windowing steps after actually extracting the windowed signal: depending o...
MatrixIndexT Dim() const
Returns the dimension of the vector.
Real Sum() const
Returns sum of the elements.
void Preemphasize(VectorBase< BaseFloat > *waveform, BaseFloat preemph_coeff)
A class representing a vector.
#define KALDI_ASSERT(cond)
Provides a vector abstraction class.
void Add(Real c)
Add a constant to each element of a vector.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void Dither(VectorBase< BaseFloat > *waveform, BaseFloat dither_value)
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).