-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.cpp
36 lines (29 loc) · 862 Bytes
/
main.cpp
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 <iostream>
#include <cmath>
#include <vector>
// This code demonstrates using the C++ interface to LibPyin from C++
#include "source/libpyincpp.h"
int main() {
int SAMPLE_RATE = 44100;
int SAMPLE_COUNT = 2048*2;
int BLOCK_SIZE = 2048;
int STEP_SIZE = 512;
// Prepare objects
PyinCpp my_pyin(SAMPLE_RATE);
my_pyin.setCutOff(0.99);
std::vector<float> samples(SAMPLE_COUNT);
// Generate a 440 herz sine wave
float freq = 440;
float angle_speed = 2 * M_PI * (freq / SAMPLE_RATE);
for (int i = 0; i < SAMPLE_COUNT; i++) {
samples[i] = sin(angle_speed * i);
}
// Mine pitches
std::vector<float> pitches = my_pyin.feed(samples);
// Go through and print the pitches
for (const float pitch : pitches)
{
std::cout << pitch << " ";
}
std::cout << std::endl;
}