Skip to content

Commit

Permalink
sinf cosf
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui committed Nov 21, 2024
1 parent 74ac28a commit e32ab4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/layer/inversespectrogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ int InverseSpectrogram::load_param(const ParamDict& pd)
// hann window
for (int i = 0; i < winlen; i++)
{
*p++ = 0.5f * (1 - cos(2 * 3.1415927f * i / winlen));
*p++ = 0.5f * (1 - cosf(2 * 3.1415927f * i / winlen));
}
}
if (window_type == 2)
{
// hamming window
for (int i = 0; i < winlen; i++)
{
*p++ = 0.54f - 0.46f * cos(2 * 3.1415927f * i / winlen);
*p++ = 0.54f - 0.46f * cosf(2 * 3.1415927f * i / winlen);
}
}
for (int i = 0; i < n_fft - winlen - (n_fft - winlen) / 2; i++)
Expand Down Expand Up @@ -173,8 +173,8 @@ int InverseSpectrogram::forward(const Mat& bottom_blob, Mat& top_blob, const Opt
{
double angle = 2 * 3.1415927f * i * k / n_fft;

re += sp.row(k)[0] * cos(angle) - sp.row(k)[1] * sin(angle);
im += sp.row(k)[0] * sin(angle) + sp.row(k)[1] * cos(angle);
re += sp.row(k)[0] * cosf(angle) - sp.row(k)[1] * sinf(angle);
im += sp.row(k)[0] * sinf(angle) + sp.row(k)[1] * cosf(angle);
}

re /= n_fft;
Expand Down
8 changes: 4 additions & 4 deletions src/layer/spectrogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ int Spectrogram::load_param(const ParamDict& pd)
// hann window
for (int i = 0; i < winlen; i++)
{
*p++ = 0.5f * (1 - cos(2 * 3.1415927f * i / winlen));
*p++ = 0.5f * (1 - cosf(2 * 3.1415927f * i / winlen));
}
}
if (window_type == 2)
{
// hamming window
for (int i = 0; i < winlen; i++)
{
*p++ = 0.54f - 0.46f * cos(2 * 3.1415927f * i / winlen);
*p++ = 0.54f - 0.46f * cosf(2 * 3.1415927f * i / winlen);
}
}
for (int i = 0; i < n_fft - winlen - (n_fft - winlen) / 2; i++)
Expand Down Expand Up @@ -146,8 +146,8 @@ int Spectrogram::forward(const Mat& bottom_blob, Mat& top_blob, const Option& op
// dft
double angle = 2 * 3.1415927f * i * k / n_fft;

re += v * cos(angle); // + imag * sin(angle);
im -= v * sin(angle); // + imag * cos(angle);
re += v * cosf(angle); // + imag * sinf(angle);
im -= v * sinf(angle); // + imag * cosf(angle);
}

if (normalized == 1)
Expand Down

0 comments on commit e32ab4c

Please sign in to comment.