summaryrefslogtreecommitdiffhomepage
path: root/tunerdemo.cpp
blob: e70afb234ba3b41cbff523f37ebf01d14de45b56 (plain)
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
#include "tuner.h"

#include <chrono>
#include <iostream>
#include <thread>

using namespace std::chrono_literals;

const int sampleFrequency = 44100;
const int fftSize = 4096;

std::vector<std::complex<double>> sample()
{
	return std::vector<std::complex<double>>(fftSize, 0.0);
}

int main(int argc, char* argv[]) {
	RIT::Tuner tuner(fftSize, sampleFrequency);

	std::vector<std::complex<double>> dataIn = sample();
	
	while (true) {
		auto start = std::chrono::high_resolution_clock::now();
		RIT::Pitch pitch = tuner(dataIn);
		auto end = std::chrono::high_resolution_clock::now();
		std::string name = pitch.name;
		if (name == "")
			name = "<none>";
		std::cout << "Detected Note: " << name
		       << " Deviation: " << pitch.deviation
		       << " Frequency: " << pitch.f
		       << ", took " << std::chrono::nanoseconds(end - start).count() * 0.000001 << "ms"
		       << std::endl;
		std::this_thread::sleep_until(start + 100ms);
	}

	return 0;
}