tweaks to curvetest to help track down interpolation bug at high timecodes
[ardour.git] / gtk2_ardour / curvetest.cc
1 /*
2     Copyright (C) 2000-2007 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <iomanip>
22 #include <fstream>
23 #include <cfloat>
24 #include <unistd.h>
25
26 #include <pbd/id.h>
27
28 #include <ardour/curve.h>
29
30 using namespace std;
31 using namespace ARDOUR;
32 using namespace PBD;
33
34 int
35 curvetest (string filename)
36 {
37         // needed to initialize ID objects/counter used
38         // by Curve et al.
39         PBD::ID::init ();
40
41         ifstream in (filename.c_str());
42         stringstream line;
43         Curve c (-1.0, +1.0, 0, true);
44         double minx = DBL_MAX;
45         double maxx = DBL_MIN;
46
47         while (in) {
48                 double x, y;
49
50                 in >> x;
51                 in >> y;
52                 
53                 if (!in) {
54                         break;
55                 }
56
57                 if (x < minx) {
58                         minx = x;
59                 }
60                 
61                 if (x > maxx) {
62                         maxx = x;
63                 }
64                 
65                 c.add (x, y);
66         }
67
68
69         float foo[1024];
70
71         c.get_vector (minx, maxx, foo, 1024);
72         
73         for (int i = 0; i < 1024; ++i) {
74                 cout << setw(20) << setprecision(20) << minx + (((double) i / 1024.0) * (maxx - minx)) << ' ' << foo[i] << endl;
75         }
76         
77         return 0;
78 }