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

Revision 2802, 3.7 kB (checked in by jwoithe, 3 years ago)

Cosmetic: "Firewire" becomes "FireWire?".

Officially both the "F" and "W" were capitalised in the FireWire? name, so
reflect this throughout FFADO's source tree. This mostly affects comments.

This patch originated from pander on the ffado-devel mailing list. To
maintain consistency, the committed version has been expanded to include
files not originally included in the original patch.

Line 
1 /*
2  * Copyright (C) 2005-2008 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 program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
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.