annotate libao2/pl_resample.c @ 4130:c0b9e4a12df0

CYUV credits to Tim Ferguson
author gabucino
date Sun, 13 Jan 2002 09:37:35 +0000
parents d6f8feeac656
children 585f0c77d8f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
1 /*=============================================================================
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
2 //
4049
d6f8feeac656 Correction of lisensing comment
anders
parents: 3631
diff changeset
3 // This software has been released under the terms of the GNU Public
d6f8feeac656 Correction of lisensing comment
anders
parents: 3631
diff changeset
4 // license. See http://www.gnu.org/copyleft/gpl.html for details.
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
5 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
6 // Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
7 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
8 //=============================================================================
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
9 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
10
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
11 /* This audio output plugin changes the sample rate. The output
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
12 samplerate from this plugin is specified by using the switch
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
13 `fout=F' where F is the desired output sample frequency
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
14 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
15
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
16 #define PLUGIN
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
17
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
18 #include <stdio.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
19 #include <stdlib.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
20 #include <unistd.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
21 #include <inttypes.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
22
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
23 #include "audio_out.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
24 #include "audio_plugin.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
25 #include "audio_plugin_internal.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
26 #include "afmt.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
27 //#include "../config.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
28
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
29 static ao_info_t info =
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
30 {
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
31 "Sample frequency conversion audio plugin",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
32 "resample",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
33 "Anders",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
34 ""
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
35 };
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
36
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
37 LIBAO_PLUGIN_EXTERN(resample)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
38
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
39 #define min(a,b) (((a) < (b)) ? (a) : (b))
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
40 #define max(a,b) (((a) > (b)) ? (a) : (b))
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
41
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
42 /* Below definition selects the length of each poly phase component.
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
43 Valid definitions are L4 and L8, where the number denotes the
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
44 length of the filter. This definition affects the computational
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
45 complexity (see play()), the performance (see filter.h) and the
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
46 memory usage. For now the filterlenght is choosen to 4 and without
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
47 assembly optimization if no SSE is present.
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
48 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
49 #ifdef HAVE_SSE
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
50 #define L8 1 // Filter bank type
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
51 #define W W8 // Filter bank parameters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
52 #define L 8 // Filter length
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
53 #else
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
54 #define L4 1
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
55 #define W W4
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
56 #define L 4
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
57 #endif
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
58
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
59 #define CH 6 // Max number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
60 #define UP 128 /* Up sampling factor. Increasing this value will
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
61 improve frequency accuracy. Think about the L1
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
62 cashing of filter parameters - how big can it be? */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
63
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
64 #include "fir.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
65 #include "filter.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
66
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
67 // local data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
68 typedef struct pl_resample_s
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
69 {
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
70 int16_t* data; // Data buffer
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
71 int16_t* w; // Current filter weights
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
72 uint16_t dn; // Down sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
73 uint16_t up; // Up sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
74 int channels; // Number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
75 int len; // Lenght of buffer
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
76 int bypass; // Bypass this plugin
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
77 int16_t ws[UP*L]; // List of all available filters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
78 int16_t xs[CH][L*2]; // Circular buffers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
79 } pl_resample_t;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
80
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
81 static pl_resample_t pl_resample = {NULL,NULL,1,1,1,0,0,W};
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
82
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
83 // to set/get/query special features/parameters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
84 static int control(int cmd,int arg){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
85 switch(cmd){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
86 case AOCONTROL_PLUGIN_SET_LEN:
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
87 if(pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
88 free(pl_resample.data);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
89 pl_resample.len = ao_plugin_data.len;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
90 pl_resample.data=(int16_t*)malloc(pl_resample.len);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
91 if(!pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
92 return CONTROL_ERROR;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
93 ao_plugin_data.len = (int)((double)ao_plugin_data.len *
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
94 ((double)pl_resample.up)/
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
95 ((double)pl_resample.dn));
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
96 return CONTROL_OK;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
97 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
98 return -1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
99 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
100
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
101 // open & setup audio device
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
102 // return: 1=success 0=fail
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
103 static int init(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
104 int fin=ao_plugin_data.rate;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
105 int fout=ao_plugin_cfg.pl_resample_fout;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
106 pl_resample.w=pl_resample.ws;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
107 pl_resample.up=UP;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
108
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
109 // Sheck input format
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
110 if(ao_plugin_data.format != AFMT_S16_LE){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
111 fprintf(stderr,"[pl_resample] Input audio format not yet suported. \n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
112 return 0;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
113 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
114 // Sanity check and calculate down sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
115 if((float)max(fin,fout)/(float)min(fin,fout) > 10){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
116 fprintf(stderr,"[pl_resample] The difference between fin and fout is too large.\n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
117 return 0;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
118 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
119 pl_resample.dn=(int)(0.5+((float)(fin*pl_resample.up))/((float)fout));
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
120 if(pl_resample.dn == pl_resample.up){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
121 fprintf(stderr,"[pl_resample] Fin is too close to fout no conversion is needed.\n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
122 pl_resample.bypass=1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
123 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
124 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
125 pl_resample.channels=ao_plugin_data.channels;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
126 if(ao_plugin_data.channels>CH){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
127 fprintf(stderr,"[pl_resample] Too many channels, max is 6.\n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
128 return 0;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
129 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
130
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
131 // Tell the world what we are up to
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
132 printf("[pl_resample] Up=%i, Down=%i, True fout=%f\n",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
133 pl_resample.up,pl_resample.dn,
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
134 ((float)fin*pl_resample.up)/((float)pl_resample.dn));
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
135
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
136 // This plugin changes buffersize and adds some delay
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
137 ao_plugin_data.sz_mult/=((float)pl_resample.up)/((float)pl_resample.dn);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
138 ao_plugin_data.delay_fix-= ((float)L/2) * (1/fout);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
139 ao_plugin_data.rate=fout;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
140 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
141 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
142
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
143 // close plugin
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
144 static void uninit(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
145 if(pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
146 free(pl_resample.data);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
147 pl_resample.data=NULL;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
148 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
149
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
150 // empty buffers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
151 static void reset(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
152 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
153
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
154 // processes 'ao_plugin_data.len' bytes of 'data'
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
155 // called for every block of data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
156 // FIXME: this routine needs to be optimized (it is probably possible to do a lot here)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
157 static int play(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
158 static uint16_t pwi = 0; // Index for w
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
159 static uint16_t pxi = 0; // Index for circular queue
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
160 static uint16_t pi = 1; // Number of new samples to put in x queue
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
161
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
162 uint16_t ci = pl_resample.channels; // Index for channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
163 uint16_t len = 0; // Number of output samples
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
164 uint16_t nch = pl_resample.channels; // Number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
165 uint16_t inc = pl_resample.dn/pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
166 uint16_t level = pl_resample.dn%pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
167 uint16_t up = pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
168 uint16_t dn = pl_resample.dn;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
169
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
170 register uint16_t i,wi,xi; // Temporary indexes
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
171
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
172 if(pl_resample.bypass)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
173 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
174
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
175 // Index current channel
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
176 while(ci--){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
177 // Temporary pointers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
178 register int16_t* x = pl_resample.xs[ci];
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
179 register int16_t* in = ((int16_t*)ao_plugin_data.data)+ci;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
180 register int16_t* out = pl_resample.data+ci;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
181 // Block loop end
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
182 register int16_t* end = in+ao_plugin_data.len/2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
183 i = pi; wi = pwi; xi = pxi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
184
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
185 LOAD_QUE(x);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
186 if(0!=i) goto L1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
187 while(in < end){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
188 // Update wi to point at the correct polyphase component
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
189 wi=(wi+dn)%up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
190
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
191 /* Update circular buffer x. This loop will be updated 0 or 1 time
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
192 for upsamling and inc or inc + 1 times for downsampling */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
193 if(wi<level) goto L3;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
194 if(0==i) goto L2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
195 L1: i--;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
196 L3: UPDATE_QUE(in);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
197 in+=nch;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
198 if(in >= end) goto L2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
199 if(i) goto L1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
200 L2: if(i) goto L5;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
201 i=inc;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
202
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
203 /* Get the correct polyphase component and the correct startpoint
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
204 in the circular bufer and run the FIR filter */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
205 FIR((&x[xi]),(&pl_resample.w[wi*L]),out);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
206 len++;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
207 out+=nch;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
208 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
209 L5:
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
210 SAVE_QUE(x);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
211 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
212
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
213 // Save values that needs to be kept for next time
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
214 pwi = wi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
215 pxi = xi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
216 pi = i;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
217 // Set new data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
218 ao_plugin_data.len=len*2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
219 ao_plugin_data.data=pl_resample.data;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
220 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
221 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
222
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
223
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
224
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
225
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
226