root/branches/streaming-rework/src/libutil/test-dll.cpp

Revision 419, 4.0 kB (checked in by pieterpalmers, 16 years ago)

namespace simplification

Line 
1 /*
2  *   FreeBob Streaming API
3  *   FreeBob = Firewire (pro-)audio for linux
4  *
5  *   http://freebob.sf.net
6  *
7  *   Copyright (C) 2005,2006 Pieter Palmers <pieterpalmers@users.sourceforge.net>
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) any later version.
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, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  *
24  *   Test for the delay locked loop class
25  *
26  */
27
28 #include "DelayLockedLoop.h"
29 #include <stdio.h>
30
31 using namespace Util;
32
33 int main() {
34     int i=0;
35     int i2=0;
36    
37     #define MAX_TEST_ORDER 2
38    
39     #define NB_VALUES 12
40     #define NB_LOOPS 50000
41
42     // this test is for a second order loop,
43    
44
45     float omega=6.28*0.001;
46     float coeffs[MAX_TEST_ORDER];
47     coeffs[0]=1.41*omega;
48     coeffs[1]=omega*omega;
49    
50     DelayLockedLoop d1(1, coeffs);
51    
52     DelayLockedLoop d2(2, coeffs);
53    
54     // this sequence represents the average deviation of the sample period
55     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};
56     float average=0.0;
57    
58     // these are the actual period times
59     float ideal_values[NB_LOOPS];
60     float actual_values[NB_LOOPS];
61     float actual_values2[NB_LOOPS];
62    
63     // we define a nominal sample time:
64     float ts_nominal=1.0/48000.0;
65     float period=100.0;
66    
67     // we calculate the deviated sample times
68     for (i=0;i<NB_LOOPS;i++) {
69         unsigned int idx=i % NB_VALUES;
70        
71         // this constructs time-between-samples type of data
72         // for testing the first order loop
73         actual_values[i]=period*ts_nominal*(1+deviation[idx]);
74        
75         // this is constructing an incrementing time line
76         ideal_values[i]=0;
77         if (i==0) ideal_values[i] = ts_nominal * period;
78         else ideal_values[i] = ideal_values[i-1] + (ts_nominal * period);
79        
80         actual_values2[i] = ideal_values[i] + (ts_nominal*deviation[idx]);
81        
82         // calculate the average deviation to check which
83         // direction the deviation sequence takes.
84         average+=deviation[idx]*ts_nominal;
85     }
86     average /= NB_LOOPS;
87    
88     d1.setIntegrator(0,period*ts_nominal);
89    
90     d2.setIntegrator(0,ideal_values[0]);
91     d2.setIntegrator(1,ideal_values[0]);
92    
93     for(i=0;i<50;i++) {
94         d1.put(actual_values[i]);
95         printf("%06d: IN = %8.4fms - OUT = %8.4fms, error output=%e\n", i, actual_values[i]*1000, d1.get()*1000, d1.getError());
96     }
97    
98     printf("--------\n");
99     for(i2=0;i2<50;i2++) {
100         d2.put(actual_values2[i2]);
101         printf("%06d: IN = %8.4fms - OUT = %8.4fms, error output=%e\n", i, actual_values2[i2]*1000, d2.get()*1000,  d2.getError());
102     }
103    
104     printf("========= CONVERGENCE =========\n");
105     for(;i<NB_LOOPS;i++) {
106         d1.put(actual_values[i]);
107     }
108     printf("%06d: OUT = %8.4fms, E=%e, ideal=%8.4fms, diff=%f%%\n", i, 
109         d1.get()*1000,
110         d1.getError(),
111         ts_nominal * period*1000,
112         (d1.get()-ts_nominal * period)/(ts_nominal * period)*100);
113    
114     printf("--------\n");
115     for(;i2<NB_LOOPS;i2++) {
116         d2.put(actual_values2[i2]);
117     }
118     printf("%06d: OUT = %8.4fms, E=%e, ideal=%8.4fms, diff=%f%%\n", i, 
119         d2.get()*1000,
120         d2.getError(),
121         ideal_values[NB_LOOPS-1]*1000,
122         (d2.get()-ideal_values[NB_LOOPS-1])/(ideal_values[NB_LOOPS-1])*100);
123      
124    
125     printf("Average deviation: %f, period time = %fms\n",average, ts_nominal * period*1000);
126
127
128 }
Note: See TracBrowser for help on using the browser.