root/trunk/libffado/src/libutil/test-dll.cpp

Revision 445, 3.7 kB (checked in by pieterpalmers, 17 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

Line 
1 /*
2  * Copyright (C) 2005-2007 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB.
8  *
9  * This is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2
11  * as published by the Free Software Foundation.
12  *
13  * FFADO is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with FFADO; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA.
22  */
23
24 #include "DelayLockedLoop.h"
25 #include <stdio.h>
26
27 using namespace Util;
28
29 int main() {
30     int i=0;
31     int i2=0;
32
33     #define MAX_TEST_ORDER 2
34
35     #define NB_VALUES 12
36     #define NB_LOOPS 50000
37
38     // this test is for a second order loop,
39
40
41     float omega=6.28*0.001;
42     float coeffs[MAX_TEST_ORDER];
43     coeffs[0]=1.41*omega;
44     coeffs[1]=omega*omega;
45
46     DelayLockedLoop d1(1, coeffs);
47
48     DelayLockedLoop d2(2, coeffs);
49
50     // this sequence represents the average deviation of the sample period
51     float deviation[NB_VALUES]={-0.001, 0.0, 0.001, 0.001, -0.001, 0.001, -0.001, 0.001, -0.001, 0.00, 0.001, -0.001};
52     float average=0.0;
53
54     // these are the actual period times
55     float ideal_values[NB_LOOPS];
56     float actual_values[NB_LOOPS];
57     float actual_values2[NB_LOOPS];
58
59     // we define a nominal sample time:
60     float ts_nominal=1.0/48000.0;
61     float period=100.0;
62
63     // we calculate the deviated sample times
64     for (i=0;i<NB_LOOPS;i++) {
65         unsigned int idx=i % NB_VALUES;
66
67         // this constructs time-between-samples type of data
68         // for testing the first order loop
69         actual_values[i]=period*ts_nominal*(1+deviation[idx]);
70
71         // this is constructing an incrementing time line
72         ideal_values[i]=0;
73         if (i==0) ideal_values[i] = ts_nominal * period;
74         else ideal_values[i] = ideal_values[i-1] + (ts_nominal * period);
75
76         actual_values2[i] = ideal_values[i] + (ts_nominal*deviation[idx]);
77
78         // calculate the average deviation to check which
79         // direction the deviation sequence takes.
80         average+=deviation[idx]*ts_nominal;
81     }
82     average /= NB_LOOPS;
83
84     d1.setIntegrator(0,period*ts_nominal);
85
86     d2.setIntegrator(0,ideal_values[0]);
87     d2.setIntegrator(1,ideal_values[0]);
88
89     for(i=0;i<50;i++) {
90         d1.put(actual_values[i]);
91         printf("%06d: IN = %8.4fms - OUT = %8.4fms, error output=%e\n", i, actual_values[i]*1000, d1.get()*1000, d1.getError());
92     }
93
94     printf("--------\n");
95     for(i2=0;i2<50;i2++) {
96         d2.put(actual_values2[i2]);
97         printf("%06d: IN = %8.4fms - OUT = %8.4fms, error output=%e\n", i, actual_values2[i2]*1000, d2.get()*1000,  d2.getError());
98     }
99
100     printf("========= CONVERGENCE =========\n");
101     for(;i<NB_LOOPS;i++) {
102         d1.put(actual_values[i]);
103     }
104     printf("%06d: OUT = %8.4fms, E=%e, ideal=%8.4fms, diff=%f%%\n", i,
105         d1.get()*1000,
106         d1.getError(),
107         ts_nominal * period*1000,
108         (d1.get()-ts_nominal * period)/(ts_nominal * period)*100);
109
110     printf("--------\n");
111     for(;i2<NB_LOOPS;i2++) {
112         d2.put(actual_values2[i2]);
113     }
114     printf("%06d: OUT = %8.4fms, E=%e, ideal=%8.4fms, diff=%f%%\n", i,
115         d2.get()*1000,
116         d2.getError(),
117         ideal_values[NB_LOOPS-1]*1000,
118         (d2.get()-ideal_values[NB_LOOPS-1])/(ideal_values[NB_LOOPS-1])*100);
119
120
121     printf("Average deviation: %f, period time = %fms\n",average, ts_nominal * period*1000);
122
123
124 }
Note: See TracBrowser for help on using the browser.