-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_conditioners.cpp
More file actions
51 lines (43 loc) · 1.68 KB
/
Copy pathtest_conditioners.cpp
File metadata and controls
51 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <cmath>
#include <cstdio>
#include <vector>
#include "mel.h"
static int g_fails = 0;
#define CHECK(cond) do { if (!(cond)) { std::fprintf(stderr, "FAIL %s:%d %s\n", __FILE__, __LINE__, #cond); ++g_fails; } } while(0)
int main() {
using namespace muscriptor;
auto fb = melscale_fbanks(1025, 0.f, 8000.f, 512, 16000);
CHECK(fb.size() == 1025 * 512);
// Hann window
const int n_fft = 2048;
std::vector<float> window(n_fft);
for (int i = 0; i < n_fft; ++i) {
window[i] = 0.5f * (1.f - std::cos(2.f * static_cast<float>(M_PI) * i /
static_cast<float>(n_fft - 1)));
}
// 5s of silence → finite log-mel
std::vector<float> wav(80000, 0.f);
MelSpectrogramConfig cfg;
int n_frames = 0;
auto mel = compute_mel_spectrogram(wav.data(), wav.size(), window.data(), fb.data(), cfg,
&n_frames);
CHECK(n_frames > 400); // ~501 for 5s
CHECK(static_cast<int>(mel.size()) == n_frames * 512);
// log(eps) ≈ log(1e-6)
CHECK(std::isfinite(mel[0]));
// sine should produce energy
for (size_t i = 0; i < wav.size(); ++i) {
wav[i] = 0.5f * std::sin(2.f * static_cast<float>(M_PI) * 440.f * i / 16000.f);
}
auto mel2 = compute_mel_spectrogram(wav.data(), wav.size(), window.data(), fb.data(), cfg,
&n_frames);
float maxv = -1e30f;
for (float v : mel2) maxv = std::max(maxv, v);
CHECK(maxv > mel[0]); // louder than silence floor
if (g_fails) {
std::fprintf(stderr, "%d failures\n", g_fails);
return 1;
}
std::printf("ok conditioners (mel)\n");
return 0;
}