1 /*
2 
3   Resample.C  -  Class
4   Using Erik de Castro Lopo libsamplerate
5   Copyright (C) 2008-2009 Josep Andreu (Holborn)
6   Author: Josep Andreu
7 
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of version 2 of the GNU General Public License
10   as published by the Free Software Foundation.
11 
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 (version 2) for more details.
16 
17   You should have received a copy of the GNU General Public License
18 (version2)
19   along with this program; if not, write to the Free Software Foundation,
20   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 
22 */
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include "Resample.h"
28 
29 
Resample(int type)30 Resample::Resample(int type)
31 {
32     statel = src_new(type , 1 , &errorl);
33     stater = src_new(type , 1 , &errorr);
34 
35 }
36 
37 
~Resample()38 Resample::~Resample()
39 {
40 	src_delete(statel);
41 	src_delete(stater);
42 };
43 
44 void
cleanup()45 Resample::cleanup()
46 {
47     src_reset(statel);
48     src_reset(stater);
49 
50 };
51 
52 
53 
54 void
out(float * inl,float * inr,float * outl,float * outr,int frames,double ratio)55 Resample::out(float *inl, float *inr, float *outl, float *outr, int frames, double ratio)
56 {
57 
58 
59     long int o_frames = lrint((double)frames*ratio);
60     srcinfol.data_in = inl;
61     srcinfol.input_frames = frames;
62     srcinfol.data_out = outl;
63     srcinfol.output_frames = o_frames;
64     srcinfol.src_ratio = ratio;
65     srcinfol.end_of_input = 0;
66 
67     srcinfor.data_in = inr;
68     srcinfor.input_frames = frames;
69     srcinfor.data_out = outr;
70     srcinfor.output_frames = o_frames;
71     srcinfor.src_ratio = ratio;
72     srcinfor.end_of_input = 0;
73 
74     errorl = src_process(statel, &srcinfol);
75     errorr = src_process(stater, &srcinfor);
76 
77 
78 }
79 
80 
81 void
mono_out(float * inl,float * outl,int frames,double ratio,int o_frames)82 Resample::mono_out(float *inl, float *outl, int frames, double ratio, int o_frames)
83 {
84 
85     srcinfol.data_in = inl;
86     srcinfol.input_frames = frames;
87     srcinfol.data_out = outl;
88     srcinfol.output_frames = o_frames;
89     srcinfol.src_ratio = ratio;
90     srcinfol.end_of_input = 0;
91 
92     errorl = src_process(statel, &srcinfol);
93 
94 }
95 
96 
97 
98 
99