Add Russian translation provided by Валерий Крувялис <valkru@mail.ru>
[xiph-mirror.git] / sushivision / example_chirp.c
bloba0ba234e90ec7df655afb9f7a8190e3adc5d2eb2
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 #define _GNU_SOURCE
23 #include <stdio.h>
24 #include <math.h>
25 #include "sushivision.h"
27 static void chirp(double *d, double *ret){
28 double freq = d[0];
29 double ampl = d[1];
30 double phas = d[2];
31 double damp = d[3];
32 double dpha = d[4];
33 double t = d[5];
35 /* 0: sin
36 2: ph
37 3: a */
38 double phase_t = (phas + freq*t*M_PI*2 + dpha*t*t);
39 double cycles = floor(phase_t/(M_PI*2));
40 double norm_phase = phase_t - cycles*M_PI*2;
41 if(norm_phase > M_PI) norm_phase -= M_PI*2;
43 ret[2] = (ampl + damp*t);
44 ret[1] = norm_phase / M_PI;
45 ret[0] = sin(phase_t) * (ampl + damp*t);
48 int sv_submain(int argc, char *argv[]){
50 sv_instance_t *s = sv_new(0,"chirp");
52 sv_dim_t *d0 = sv_dim_new(s,0,"initial Hz",SV_DIM_NO_X);
53 sv_dim_make_scale(d0,4,(double []){1,10,100,1000},NULL,0);
55 sv_dim_t *d1 = sv_dim_new(s,1,"initial amplitude",SV_DIM_NO_X);
56 sv_dim_make_scale(d1,3,(double []){0,.1,1},NULL,0);
57 sv_dim_set_value(d1,1,1.0);
59 sv_dim_t *d2 = sv_dim_new(s,2,"initial phase",SV_DIM_NO_X);
60 sv_dim_make_scale(d2,3,(double []){-M_PI,0,M_PI},NULL,0);
62 sv_dim_t *d3 = sv_dim_new(s,3,"delta amplitude",SV_DIM_NO_X);
63 sv_dim_make_scale(d3,3,(double []){0,-.1,-1},NULL,0);
65 sv_dim_t *d4 = sv_dim_new(s,4,"delta frequency",SV_DIM_NO_X);
66 sv_dim_make_scale(d4,7,(double []){-100*M_PI,-10*M_PI,-M_PI,0,M_PI,10*M_PI,100*M_PI},
67 (char *[]){"-100pi","-10pi","-pi","0","pi","10pi","100pi"}, 0);
69 sv_dim_t *d5 = sv_dim_new(s,5,"seconds",0);
70 sv_dim_make_scale(d5,5,(double []){0,.001,.01,.1,1},NULL,0);
72 sv_func_t *f = sv_func_new(s, 0, 3, chirp, 0);
74 sv_obj_t *o0 = sv_obj_new(s,0,"sin",
75 (sv_func_t *[]){f},
76 (int []){0},
77 "Y", 0);
78 sv_obj_make_scale(o0, 2,(double []){-1.5, 1.5}, NULL, 0);
80 sv_obj_t *o1 = sv_obj_new(s,1,"phase",
81 (sv_func_t *[]){f},
82 (int []){1},
83 "Y", 0);
84 sv_obj_make_scale(o1, 2,(double []){-1.0, 1.0}, NULL, 0);
86 sv_obj_t *o2 = sv_obj_new(s,2,"amplitude",
87 (sv_func_t *[]){f},
88 (int []){2},
89 "Y", 0);
90 sv_obj_make_scale(o2, 2,(double []){-1.0, 1.0}, NULL, 0);
92 sv_panel_new_1d(s,2,"chirp",
93 s->objective_list[0]->scale,
94 (sv_obj_t *[]){o0,o1,o2,NULL},
95 (sv_dim_t *[]){d0,d1,d2,d3,d4,d5,NULL},
96 0);
98 return 0;