summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/pi_controller.h
blob: 8daf7a70680c0a59090125fdace12520d98fb7fb (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
  Copyright (C) 2008 Torben Hohn

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __libardour_pi_controller__
#define __libardour_pi_controller__

#include "ardour/libardour_visibility.h"
#include "ardour/types.h"

class LIBARDOUR_API PIController {
public:
	PIController (double resample_factor, int fir_size);
	~PIController();

	void reset (double resample_factor) {
		resample_mean = resample_factor;
		static_resample_factor = resample_factor;
		out_of_bounds ();
	}

	double get_ratio (int fill_level, int period_size);
	void out_of_bounds();

public:
	double  resample_mean;
	double  static_resample_factor;
	double* offset_array;
	double* window_array;
	int     offset_differential_index;
	double  offset_integral;
	double  catch_factor;
	double  catch_factor2;
	double  pclamp;
	double  controlquant;
	int     smooth_size;
	double  smooth_offset;
	double  current_resample_factor;
	bool    fir_empty;
};

#define ESTIMATOR_SIZE 16

class LIBARDOUR_API PIChaser {
public:
	PIChaser();
	~PIChaser();

	double get_ratio( framepos_t chasetime_measured, framepos_t chasetime, framepos_t slavetime_measured, framepos_t slavetime, bool in_control, int period_size );
	void reset();
	framepos_t want_locate() { return want_locate_val; }

private:
	PIController *pic;
	framepos_t realtime_stamps[ESTIMATOR_SIZE];
	framepos_t chasetime_stamps[ESTIMATOR_SIZE];
	int array_index;
	framepos_t want_locate_val;

	void feed_estimator( framepos_t realtime, framepos_t chasetime );
	double get_estimate();

	double speed;

	double speed_threshold;
	framepos_t pos_threshold;
};

#endif /* __libardour_pi_controller__ */