Work on flangers.
[ahxm.git] / core.c
bloba4a2627b12c369c20420d80701e6d0ee5eac7028
1 /*
3 PROGRAM_NAME PROGRAM_VERSION - PROGRAM_DESCRIPTION
5 Copyright (C) 2003 Angel Ortega <angel@triptico.com>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 http://www.triptico.com
25 #include "config.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <math.h>
31 #include "core.h"
33 /*******************
34 Data
35 ********************/
37 /* main output frequency */
38 int _frequency=44100;
40 /* linear interpolation flag */
41 int _linear_interpolation=1;
43 /*******************
44 Code
45 ********************/
47 int get_sample(int * wave, double size, double offset)
49 double d;
50 double s1,s2;
52 if(!_linear_interpolation)
53 return(wave[(int) offset]);
55 if(offset > size) return(wave[(int)size]);
57 d=offset - floor(offset);
58 s1=(double) (wave[(int)offset]) * (1 - d);
59 s2=(double) (wave[(int)offset + 1]) * d;
61 return((int) (s1 + s2));
65 int * wave_resample(int * wave, int freq, int * size)
67 double ratio;
68 int new_size;
69 int * new_wave;
70 int n;
71 double i;
73 ratio=(double) freq / (double) _frequency;
74 new_size=(int)((double) (*size) / ratio);
76 new_wave=(int *)malloc(new_size * sizeof(int));
78 printf("wave_resample: ratio %f\n", (float)ratio);
80 for(n=i=0;n < new_size;n++,i+=ratio)
81 new_wave[n]=get_sample(wave, *size, i);
83 *size=new_size;
85 /* free the old wave */
86 free(wave);
88 return(new_wave);