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

#include "audioio.h"

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

using namespace std::chrono_literals;

int main(int argc, char* argv[]) {
	RIT::AudioIO audioIO;

	RIT::Tuner tuner(audioIO.size(), audioIO.sampleFrequency());

	std::cout << "Tuner range: " << tuner.fMin() << " ... " << tuner.fMax() << " Hz" << std::endl;

	while (true) {
		std::vector<std::complex<double>> dataIn = audioIO.sample();

		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;
}