README.osx wasn't easily readable in Finder. Revert back to
[sox.git] / src / rate_poly_fir.h
blob913ce714e5ec3f9302531962fb644b2c89982d40
1 /* Effect: change sample rate Copyright (c) 2008 robs@users.sourceforge.net
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.
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.
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
18 /* Up-sample by step in (0,1) using a poly-phase FIR with length LEN.*/
19 /* Input must be preceded by LEN >> 1 samples. */
20 /* Input must be followed by (LEN-1) >> 1 samples. */
22 #define a (coef(p->shared->poly_fir_coefs, COEF_INTERP, FIR_LENGTH, phase, 0,j))
23 #define b (coef(p->shared->poly_fir_coefs, COEF_INTERP, FIR_LENGTH, phase, 1,j))
24 #define c (coef(p->shared->poly_fir_coefs, COEF_INTERP, FIR_LENGTH, phase, 2,j))
25 #define d (coef(p->shared->poly_fir_coefs, COEF_INTERP, FIR_LENGTH, phase, 3,j))
26 #if COEF_INTERP == 0
27 #define _ sum += a *at[j], ++j;
28 #elif COEF_INTERP == 1
29 #define _ sum += (b *x + a)*at[j], ++j;
30 #elif COEF_INTERP == 2
31 #define _ sum += ((c *x + b)*x + a)*at[j], ++j;
32 #elif COEF_INTERP == 3
33 #define _ sum += (((d*x + c)*x + b)*x + a)*at[j], ++j;
34 #else
35 #error COEF_INTERP
36 #endif
38 static void FUNCTION(stage_t * p, fifo_t * output_fifo)
40 sample_t const * input = stage_read_p(p);
41 int i, num_in = stage_occupancy(p), max_num_out = 1 + num_in*p->out_in_ratio;
42 sample_t * output = fifo_reserve(output_fifo, max_num_out);
44 for (i = 0; p->at.parts.integer < num_in; ++i, p->at.all += p->step.all) {
45 sample_t const * at = input + p->at.parts.integer;
46 uint32_t fraction = p->at.parts.fraction;
47 int phase = fraction >> (32 - PHASE_BITS); /* high-order bits */
48 #if COEF_INTERP > 0 /* low-order bits, scaled to [0,1) */
49 sample_t x = (sample_t) (fraction << PHASE_BITS) * (1 / MULT32);
50 #endif
51 sample_t sum = 0;
52 int j = 0;
53 CONVOLVE
54 assert(j == FIR_LENGTH);
55 output[i] = sum;
57 assert(max_num_out - i >= 0);
58 fifo_trim_by(output_fifo, max_num_out - i);
59 fifo_read(&p->fifo, p->at.parts.integer, NULL);
60 p->at.parts.integer = 0;
63 #undef _
64 #undef a
65 #undef b
66 #undef c
67 #undef d
68 #undef COEF_INTERP
69 #undef CONVOLVE
70 #undef FIR_LENGTH
71 #undef FUNCTION
72 #undef PHASE_BITS