1 /* Effect: change sample rate  Copyright (c) 2008,12 robs@users.sourceforge.net
2  *
3  * This library is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU Lesser General Public License as published by
5  * the Free Software Foundation; either version 2.1 of the License, or (at
6  * your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
16  */
17 
18 /* Resample using a non-interpolated poly-phase FIR with length LEN.*/
19 /* Input must be followed by LEN-1 samples. */
20 
21 #define _ sum += (coef(p->shared->poly_fir_coefs, 0, FIR_LENGTH, divided.rem, 0, j)) *at[j], ++j;
22 
FUNCTION(stage_t * p,fifo_t * output_fifo)23 static void FUNCTION(stage_t * p, fifo_t * output_fifo)
24 {
25   sample_t const * input = stage_read_p(p);
26   int i, num_in = stage_occupancy(p), max_num_out = 1 + num_in*p->out_in_ratio;
27   sample_t * output = fifo_reserve(output_fifo, max_num_out);
28   div_t divided2;
29 
30   for (i = 0; p->at.parts.integer < num_in * p->L; ++i, p->at.parts.integer += p->step.parts.integer) {
31     div_t divided = div(p->at.parts.integer, p->L);
32     sample_t const * at = input + divided.quot;
33     sample_t sum = 0;
34     int j = 0;
35     CONVOLVE
36     output[i] = sum;
37   }
38   assert(max_num_out - i >= 0);
39   fifo_trim_by(output_fifo, max_num_out - i);
40   divided2 = div(p->at.parts.integer, p->L);
41   fifo_read(&p->fifo, divided2.quot, NULL);
42   p->at.parts.integer = divided2.rem;
43 }
44 
45 #undef _
46 #undef CONVOLVE
47 #undef FIR_LENGTH
48 #undef FUNCTION
49