SpectrogramComputer Class Reference

Class for computing spectrogram features. More...

#include <feature-spectrogram.h>

Collaboration diagram for SpectrogramComputer:

Public Types

typedef SpectrogramOptions Options
 

Public Member Functions

 SpectrogramComputer (const SpectrogramOptions &opts)
 
 SpectrogramComputer (const SpectrogramComputer &other)
 
const FrameExtractionOptionsGetFrameOptions () const
 
int32 Dim () const
 
bool NeedRawLogEnergy () const
 
void Compute (BaseFloat signal_raw_log_energy, BaseFloat vtln_warp, VectorBase< BaseFloat > *signal_frame, VectorBase< BaseFloat > *feature)
 Function that computes one frame of spectrogram features from one frame of signal. More...
 
 ~SpectrogramComputer ()
 

Private Member Functions

SpectrogramComputeroperator= (const SpectrogramComputer &other)
 

Private Attributes

SpectrogramOptions opts_
 
BaseFloat log_energy_floor_
 
SplitRadixRealFft< BaseFloat > * srfft_
 

Detailed Description

Class for computing spectrogram features.

Definition at line 67 of file feature-spectrogram.h.

Member Typedef Documentation

◆ Options

Definition at line 69 of file feature-spectrogram.h.

Constructor & Destructor Documentation

◆ SpectrogramComputer() [1/2]

SpectrogramComputer ( const SpectrogramOptions opts)
explicit

Definition at line 27 of file feature-spectrogram.cc.

References SpectrogramOptions::energy_floor, SpectrogramOptions::frame_opts, kaldi::Log(), SpectrogramComputer::log_energy_floor_, FrameExtractionOptions::PaddedWindowSize(), and SpectrogramComputer::srfft_.

28  : opts_(opts), srfft_(NULL) {
29  if (opts.energy_floor > 0.0)
30  log_energy_floor_ = Log(opts.energy_floor);
31 
32  int32 padded_window_size = opts.frame_opts.PaddedWindowSize();
33  if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two
34  srfft_ = new SplitRadixRealFft<BaseFloat>(padded_window_size);
35 }
kaldi::int32 int32
double Log(double x)
Definition: kaldi-math.h:100
SplitRadixRealFft< BaseFloat > * srfft_

◆ SpectrogramComputer() [2/2]

Definition at line 37 of file feature-spectrogram.cc.

References SpectrogramComputer::srfft_.

37  :
38  opts_(other.opts_), log_energy_floor_(other.log_energy_floor_), srfft_(NULL) {
39  if (other.srfft_ != NULL)
40  srfft_ = new SplitRadixRealFft<BaseFloat>(*other.srfft_);
41 }
SplitRadixRealFft< BaseFloat > * srfft_

◆ ~SpectrogramComputer()

Definition at line 43 of file feature-spectrogram.cc.

References SpectrogramComputer::srfft_.

43  {
44  delete srfft_;
45 }
SplitRadixRealFft< BaseFloat > * srfft_

Member Function Documentation

◆ Compute()

void Compute ( BaseFloat  signal_raw_log_energy,
BaseFloat  vtln_warp,
VectorBase< BaseFloat > *  signal_frame,
VectorBase< BaseFloat > *  feature 
)

Function that computes one frame of spectrogram features from one frame of signal.

Parameters
[in]signal_raw_log_energyThe log-energy of the frame of the signal prior to windowing and pre-emphasis, or log(numeric_limits<float>::min()), whichever is greater. Must be ignored by this function if this class returns false from this->NeedsRawLogEnergy().
[in]vtln_warpThis is ignored by this function, it's only needed for interface compatibility.
[in]signal_frameOne frame of the signal, as extracted using the function ExtractWindow() using the options returned by this->GetFrameOptions(). The function will use the vector as a workspace, which is why it's a non-const pointer.
[out]featurePointer to a vector of size this->Dim(), to which the computed feature will be written.

Definition at line 47 of file feature-spectrogram.cc.

References VectorBase< Real >::ApplyFloor(), kaldi::ComputePowerSpectrum(), VectorBase< Real >::CopyFromVec(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), SpectrogramComputer::Dim(), SpectrogramOptions::energy_floor, SpectrogramOptions::frame_opts, KALDI_ASSERT, kaldi::Log(), SpectrogramComputer::log_energy_floor_, SpectrogramComputer::opts_, FrameExtractionOptions::PaddedWindowSize(), SpectrogramOptions::raw_energy, kaldi::RealFft(), SpectrogramOptions::return_raw_fft, SpectrogramComputer::srfft_, and kaldi::VecVec().

50  {
51  KALDI_ASSERT(signal_frame->Dim() == opts_.frame_opts.PaddedWindowSize() &&
52  feature->Dim() == this->Dim());
53 
54 
55  // Compute energy after window function (not the raw one)
56  if (!opts_.raw_energy)
57  signal_raw_log_energy = Log(std::max<BaseFloat>(VecVec(*signal_frame, *signal_frame),
58  std::numeric_limits<float>::epsilon()));
59 
60  if (srfft_ != NULL) // Compute FFT using split-radix algorithm.
61  srfft_->Compute(signal_frame->Data(), true);
62  else // An alternative algorithm that works for non-powers-of-two
63  RealFft(signal_frame, true);
64 
65  if (opts_.return_raw_fft) {
66  feature->CopyFromVec(*signal_frame);
67  return;
68  }
69 
70  // Convert the FFT into a power spectrum.
71  ComputePowerSpectrum(signal_frame);
72  SubVector<BaseFloat> power_spectrum(*signal_frame,
73  0, signal_frame->Dim() / 2 + 1);
74 
75  power_spectrum.ApplyFloor(std::numeric_limits<float>::epsilon());
76  power_spectrum.ApplyLog();
77 
78  feature->CopyFromVec(power_spectrum);
79 
80  if (opts_.energy_floor > 0.0 && signal_raw_log_energy < log_energy_floor_)
81  signal_raw_log_energy = log_energy_floor_;
82  // The zeroth spectrogram component is always set to the signal energy,
83  // instead of the square of the constant component of the signal.
84  (*feature)(0) = signal_raw_log_energy;
85 }
double Log(double x)
Definition: kaldi-math.h:100
void ComputePowerSpectrum(VectorBase< BaseFloat > *waveform)
SplitRadixRealFft< BaseFloat > * srfft_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
FrameExtractionOptions frame_opts
void RealFft(VectorBase< Real > *v, bool forward)
RealFft is a fourier transform of real inputs.

◆ Dim()

int32 Dim ( ) const
inline

Definition at line 77 of file feature-spectrogram.h.

Referenced by SpectrogramComputer::Compute().

77  {
78  if (opts_.return_raw_fft) {
80  } else {
81  return opts_.frame_opts.PaddedWindowSize() / 2 + 1;
82  }
83  }
FrameExtractionOptions frame_opts

◆ GetFrameOptions()

const FrameExtractionOptions& GetFrameOptions ( ) const
inline

Definition at line 73 of file feature-spectrogram.h.

73  {
74  return opts_.frame_opts;
75  }
FrameExtractionOptions frame_opts

◆ NeedRawLogEnergy()

bool NeedRawLogEnergy ( ) const
inline

Definition at line 85 of file feature-spectrogram.h.

◆ operator=()

SpectrogramComputer& operator= ( const SpectrogramComputer other)
private

Member Data Documentation

◆ log_energy_floor_

BaseFloat log_energy_floor_
private

◆ opts_

SpectrogramOptions opts_
private

Definition at line 114 of file feature-spectrogram.h.

Referenced by SpectrogramComputer::Compute().

◆ srfft_


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