forked from csukuangfj/kaldi-native-fbank
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
porting the dithering function from kaldi
- Loading branch information
1 parent
cd20baa
commit 926fa47
Showing
2 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// kaldi-native-fbank/csrc/feature-window.h | ||
// | ||
// Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang) | ||
|
||
// This file is copied/modified from kaldi/src/feat/feature-window.h | ||
|
||
#pragma once | ||
|
||
#include <cmath> // logf, sqrtf, cosf | ||
#include <cstdlib> // RAND_MAX | ||
|
||
#ifndef M_PI | ||
#define M_PI 3.1415926535897932384626433832795 | ||
#endif | ||
|
||
#ifndef M_2PI | ||
#define M_2PI 6.283185307179586476925286766559005 | ||
#endif | ||
|
||
namespace knf { | ||
|
||
inline float Log(float x) { return logf(x); } | ||
|
||
// Returns a random integer between 0 and RAND_MAX, inclusive | ||
int Rand(struct RandomState* state = NULL); | ||
|
||
// State for thread-safe random number generator | ||
struct RandomState { | ||
RandomState(); | ||
unsigned seed; | ||
}; | ||
|
||
/// Returns a random number strictly between 0 and 1. | ||
inline float RandUniform(struct RandomState* state = NULL) { | ||
return static_cast<float>((Rand(state) + 1.0) / (RAND_MAX+2.0)); | ||
} | ||
|
||
inline float RandGauss(struct RandomState* state = NULL) { | ||
return static_cast<float>(sqrtf (-2 * Log(RandUniform(state))) | ||
* cosf(2*M_PI*RandUniform(state))); | ||
} | ||
|
||
} // namespace knf |