Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding features used externally #3724

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
adding features used externaly
  • Loading branch information
jtrmal committed Nov 20, 2019
commit 6d8681b780abb9b776c2c64401bf3bb22f118e46
5 changes: 5 additions & 0 deletions src/feat/feature-spectrogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ void SpectrogramComputer::Compute(BaseFloat signal_raw_log_energy,
else // An alternative algorithm that works for non-powers-of-two
RealFft(signal_frame, true);

if (opts_.return_raw_fft) {
feature->CopyFromVec(*signal_frame);
return;
}

// Convert the FFT into a power spectrum.
ComputePowerSpectrum(signal_frame);
SubVector<BaseFloat> power_spectrum(*signal_frame,
Expand Down
16 changes: 14 additions & 2 deletions src/feat/feature-spectrogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ struct SpectrogramOptions {
FrameExtractionOptions frame_opts;
BaseFloat energy_floor;
bool raw_energy; // If true, compute energy before preemphasis and windowing
bool return_raw_fft; // If true, return the raw FFT spectrum
// Note that in that case the Dim() will return double
// the expected dimension (because of the complex domain of it)

SpectrogramOptions() :
energy_floor(0.0),
raw_energy(true) {}
raw_energy(true),
return_raw_fft(false) {}

void Register(OptionsItf *opts) {
frame_opts.Register(opts);
Expand All @@ -54,6 +58,8 @@ struct SpectrogramOptions {
"std::numeric_limits<float>::epsilon().");
opts->Register("raw-energy", &raw_energy,
"If true, compute energy before preemphasis and windowing");
opts->Register("return-raw-fft", &return_raw_fft,
"If true, return raw FFT complex numbers instead of log magnitudes");
}
};

Expand All @@ -68,7 +74,13 @@ class SpectrogramComputer {
return opts_.frame_opts;
}

int32 Dim() const { return opts_.frame_opts.PaddedWindowSize() / 2 + 1; }
int32 Dim() const {
if (opts_.return_raw_fft) {
return opts_.frame_opts.PaddedWindowSize();
} else {
return opts_.frame_opts.PaddedWindowSize() / 2 + 1;
}
}

bool NeedRawLogEnergy() const { return opts_.raw_energy; }

Expand Down
4 changes: 4 additions & 0 deletions src/feat/feature-window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ FeatureWindowFunction::FeatureWindowFunction(const FrameExtractionOptions &opts)
double i_fl = static_cast<double>(i);
if (opts.window_type == "hanning") {
window(i) = 0.5 - 0.5*cos(a * i_fl);
} else if (opts.window_type == "sine") {
// when you are checking ws wikipedia, please
// note that 0.5 * a = M_PI/(frame_length-1)
window(i) = sin(0.5 * a * i_fl);
} else if (opts.window_type == "hamming") {
window(i) = 0.54 - 0.46*cos(a * i_fl);
} else if (opts.window_type == "povey") { // like hamming but goes to zero at edges.
Expand Down
4 changes: 2 additions & 2 deletions src/feat/feature-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct FrameExtractionOptions {
BaseFloat preemph_coeff; // Preemphasis coefficient.
bool remove_dc_offset; // Subtract mean of wave before FFT.
std::string window_type; // e.g. Hamming window
// May be "hamming", "rectangular", "povey", "hanning", "blackman"
// May be "hamming", "rectangular", "povey", "hanning", "sine", "blackman"
// "povey" is a window I made to be similar to Hamming but to go to zero at the
// edges, it's pow((0.5 - 0.5*cos(n/N*2*pi)), 0.85)
// I just don't think the Hamming window makes sense as a windowing function.
Expand Down Expand Up @@ -81,7 +81,7 @@ struct FrameExtractionOptions {
"option, e.g. to 1.0 or 0.1");
opts->Register("window-type", &window_type, "Type of window "
"(\"hamming\"|\"hanning\"|\"povey\"|\"rectangular\""
"|\"blackmann\")");
"|\"sine\"|\"blackmann\")");
opts->Register("blackman-coeff", &blackman_coeff,
"Constant coefficient for generalized Blackman window.");
opts->Register("round-to-power-of-two", &round_to_power_of_two,
Expand Down