Loading...
Searching...
No Matches
Pitch.hpp
1#pragma once
2#include <Analysis/GistState.hpp>
3#include <Analysis/Helpers.hpp>
4#include <halp/audio.hpp>
5#include <halp/callback.hpp>
6#include <halp/controls.hpp>
7#include <halp/meta.hpp>
8
9#if defined(OSSIA_ENABLE_KFR)
10#include <kfr/base.hpp>
11#include <kfr/dsp.hpp>
12#include <kfr/dsp/iir_design.hpp>
13#endif
14
15namespace Analysis
16{
17#if defined(OSSIA_ENABLE_KFR)
18struct PitchState : Analysis::GistState
19{
20 PitchState()
21 : hipass{kfr::to_sos(kfr::iir_highpass(kfr::butterworth(12), 200, this->rate))}
22 {
23 }
24
25 void filter(halp::dynamic_audio_bus_base<double>& in, int d)
26 {
27 while(hipass.size() < in.channels)
28 {
29 hipass.emplace_back(
30 kfr::to_sos(kfr::iir_highpass(kfr::butterworth(12), 200, this->rate)));
31 }
32
33 int c = 0;
34 for(double* chan : in)
35 {
36 hipass[c++].apply(chan, d);
37 }
38 }
39
40 std::vector<kfr::iir_filter<double>> hipass;
41};
42#else
43using PitchState = GistState;
44#endif
45
47{
48 halp_meta(name, "Pitch detector")
49 halp_meta(c_name, "Pitch")
50 halp_meta(category, "Analysis/Pitch")
51 halp_meta(author, "ossia score, Gist library")
52 halp_meta(manual_url, "https://ossia.io/score-docs/processes/analysis.html#pitch-detection")
53 halp_meta(description, "Get the pitch of a signal")
54 halp_meta(uuid, "ed511605-8265-4b2c-8c4b-d3b189539b3b");
55
56 struct
57 {
58 audio_in audio;
59 } inputs;
60 struct
61 {
62 value_out result;
63 } outputs;
64
65 void operator()(int frames)
66 {
67 if(inputs.audio.channels == 0)
68 return;
69
70#if defined(OSSIA_ENABLE_KFR)
71 filter(inputs.audio, frames);
72#endif
73 process<&Gist<double>::pitch>(inputs.audio, outputs.result, frames);
74 }
75};
76}
Definition GistState.hpp:26
Definition Pitch.hpp:47
Definition Helpers.hpp:27
Definition Helpers.hpp:19