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
37 /* main output frequency */
40 /* linear interpolation flag */
41 int _linear_interpolation
=1;
47 int get_sample(int * wave
, double size
, double offset
)
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
)
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
);
85 /* free the old wave */