Add dl infrastructure for an optional sushiv_atexit()
[xiph/unicode.git] / sushivision / example_chirpfit.c
blobc28770ceb5840823a67f9896610adb1cdf8c63f3
1 /*
3 * sushivision copyright (C) 2006-2007 Monty <monty@xiph.org>
5 * sushivision is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * sushivision is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with sushivision; see the file COPYING. If not, write to the
17 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <stdio.h>
23 #include <math.h>
24 #include "sushivision.h"
26 sushiv_instance_t *s;
27 #define todB(x) ((x)==0?-400.f:log((x)*(x))*4.34294480f)
29 /* time, blocksz, amp_0, amp_del, freq_0, phase_0, phase_del */
30 int funcsize=64;
31 double function[64];
32 static void fourier_objective(double *d, double *ret){
33 int i;
34 double re_obj=0;
35 double im_obj=0;
36 double obj;
38 for(i=0;i<funcsize;i++){
39 im_obj += function[i] * sin(i*d[4]*2*M_PI);
40 re_obj += function[i] * cos(i*d[4]*2*M_PI);
43 im_obj/=funcsize;
44 re_obj/=funcsize;
46 obj = sqrt(im_obj*im_obj + re_obj*re_obj);
47 *ret = todB(obj);
52 static double objective(double *d){
54 return .5;
59 static int time_callback(sushiv_dimension_t *d){
62 return 1; // indicate that default processing chain should continue
65 static int blocksize_callback(sushiv_dimension_t *d){
68 return 1; // indicate that default processing chain should continue
71 int sushiv_submain(int argc, char *argv[]){
72 int i;
75 double phasechirp = 0;
76 double phi = 0;
78 for(i=0;i<funcsize;i++){
79 phasechirp +=.005;
80 phi += .1+phasechirp;
82 function[i]=sin(phi)*.1;
86 s=sushiv_new_instance();
88 sushiv_new_dimension(s,0,"time",
89 4,(double []){0,1024,2048,4096},
90 time_callback,
91 SUSHIV_DIM_NO_X|SUSHIV_DIM_NO_Y);
92 sushiv_new_dimension(s,1,"blocksize",
93 8,(double []){64,128,256,512,1024,2048,4096,8192},
94 blocksize_callback,
95 SUSHIV_DIM_NO_X|SUSHIV_DIM_NO_Y);
97 sushiv_new_dimension(s,2,"amplitude",
98 9,(double []){-96,-84,-72,-60,-48,-36,-24,-12,0},
99 NULL,0);
100 sushiv_new_dimension(s,3,"amplitude delta",
101 9,(double []){-96,-48,-24,-12,0,12,24,48,96},
102 NULL,0);
103 sushiv_new_dimension(s,4,"frequency",
104 6,(double []){0,.1,.2,.3,.4,.5},
105 NULL,0);
106 sushiv_new_dimension(s,5,"phase",
107 3,(double []){-.5,0,.5},
108 NULL,0);
109 sushiv_new_dimension(s,6,"phase delta",
110 3,(double []){-10,0,10},
111 NULL,0);
113 sushiv_new_objective(s,0,"fourier",
114 8,(double []){-96,-48,-36,-24,-12,-6,0,6},
115 fourier_objective,0);
116 //sushiv_new_objective(s,1,"fit",fit_objective,0);
117 //sushiv_new_objective(s,2,"waveform",fourier_objective,0);
119 sushiv_new_panel_2d(s,0,"fourier objective",
120 (int []){0,-1},
121 (int []){2,3,4,5,6,-1},
124 /*sushiv_linked_panel_1d(s,1,"fourier x slice",8,
125 (double []){-96,-48,-36,-24,-12,-6,0,6},
126 0,0,
128 sushiv_linked_panel_1d(s,2,"fourier y slice",8,
129 (double []){-96,-48,-36,-24,-12,-6,0,6},
130 0,1,
132 sushiv_new_panel_1d(s,3,"input block",8,
133 (double []){-96,-48,-36,-24,-12,-6,0,6},
134 (int *){2,-1},
135 NULL,
136 0);*/
138 return 0;