annotate libao2/pl_resample.c @ 3891:e87f69a44813

a52: CRC check for AC3 frames
author arpi
date Sun, 30 Dec 2001 04:44:20 +0000
parents 5f5189ac6a41
children d6f8feeac656
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 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
3 // This file is part of mplayer.
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
4 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
5 // mplayer is free software; you can redistribute it and/or modify
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
6 // it under the terms of the GNU General Public License as published by
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
7 // the Free Software Foundation; either version 2 of the License, or
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
8 // (at your option) any later version.
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 // mplayer is distributed in the hope that it will be useful,
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
13 // GNU General Public License for more details.
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 // You should have received a copy of the GNU General Public License
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
16 // along with mplayer; if not, write to the Free Software
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
18 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
19 // Copyright 2001 Anders Johansson ajh@atri.curtin.edu.au
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
20 //
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
21 //=============================================================================
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
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
24 /* This audio output plugin changes the sample rate. The output
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
25 samplerate from this plugin is specified by using the switch
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
26 `fout=F' where F is the desired output sample frequency
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
27 */
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 #define PLUGIN
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 #include <stdio.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
32 #include <stdlib.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
33 #include <unistd.h>
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
34 #include <inttypes.h>
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 #include "audio_out.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
37 #include "audio_plugin.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
38 #include "audio_plugin_internal.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
39 #include "afmt.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
40 //#include "../config.h"
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 static ao_info_t info =
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
43 {
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
44 "Sample frequency conversion audio plugin",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
45 "resample",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
46 "Anders",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
47 ""
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
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
50 LIBAO_PLUGIN_EXTERN(resample)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
51
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
52 #define min(a,b) (((a) < (b)) ? (a) : (b))
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
53 #define max(a,b) (((a) > (b)) ? (a) : (b))
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
54
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
55 /* Below definition selects the length of each poly phase component.
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
56 Valid definitions are L4 and L8, where the number denotes the
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
57 length of the filter. This definition affects the computational
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
58 complexity (see play()), the performance (see filter.h) and the
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
59 memory usage. For now the filterlenght is choosen to 4 and without
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
60 assembly optimization if no SSE is present.
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
61 */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
62 #ifdef HAVE_SSE
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
63 #define L8 1 // Filter bank type
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
64 #define W W8 // Filter bank parameters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
65 #define L 8 // Filter length
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
66 #else
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
67 #define L4 1
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
68 #define W W4
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
69 #define L 4
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
70 #endif
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
71
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
72 #define CH 6 // Max number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
73 #define UP 128 /* Up sampling factor. Increasing this value will
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
74 improve frequency accuracy. Think about the L1
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
75 cashing of filter parameters - how big can it be? */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
76
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
77 #include "fir.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
78 #include "filter.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
79
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
80 // local data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
81 typedef struct pl_resample_s
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 int16_t* data; // Data buffer
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
84 int16_t* w; // Current filter weights
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
85 uint16_t dn; // Down sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
86 uint16_t up; // Up sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
87 int channels; // Number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
88 int len; // Lenght of buffer
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
89 int bypass; // Bypass this plugin
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
90 int16_t ws[UP*L]; // List of all available filters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
91 int16_t xs[CH][L*2]; // Circular buffers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
92 } pl_resample_t;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
93
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
94 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
95
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
96 // to set/get/query special features/parameters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
97 static int control(int cmd,int arg){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
98 switch(cmd){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
99 case AOCONTROL_PLUGIN_SET_LEN:
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
100 if(pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
101 free(pl_resample.data);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
102 pl_resample.len = ao_plugin_data.len;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
103 pl_resample.data=(int16_t*)malloc(pl_resample.len);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
104 if(!pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
105 return CONTROL_ERROR;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
106 ao_plugin_data.len = (int)((double)ao_plugin_data.len *
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
107 ((double)pl_resample.up)/
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
108 ((double)pl_resample.dn));
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
109 return CONTROL_OK;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
110 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
111 return -1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
112 }
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 // open & setup audio device
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
115 // return: 1=success 0=fail
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
116 static int init(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
117 int fin=ao_plugin_data.rate;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
118 int fout=ao_plugin_cfg.pl_resample_fout;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
119 pl_resample.w=pl_resample.ws;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
120 pl_resample.up=UP;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
121
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
122 // Sheck input format
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
123 if(ao_plugin_data.format != AFMT_S16_LE){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
124 fprintf(stderr,"[pl_resample] Input audio format not yet suported. \n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
125 return 0;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
126 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
127 // Sanity check and calculate down sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
128 if((float)max(fin,fout)/(float)min(fin,fout) > 10){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
129 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
130 return 0;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
131 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
132 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
133 if(pl_resample.dn == pl_resample.up){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
134 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
135 pl_resample.bypass=1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
136 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
137 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
138 pl_resample.channels=ao_plugin_data.channels;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
139 if(ao_plugin_data.channels>CH){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
140 fprintf(stderr,"[pl_resample] Too many channels, max is 6.\n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
141 return 0;
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
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
144 // Tell the world what we are up to
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
145 printf("[pl_resample] Up=%i, Down=%i, True fout=%f\n",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
146 pl_resample.up,pl_resample.dn,
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
147 ((float)fin*pl_resample.up)/((float)pl_resample.dn));
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 // This plugin changes buffersize and adds some delay
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
150 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
151 ao_plugin_data.delay_fix-= ((float)L/2) * (1/fout);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
152 ao_plugin_data.rate=fout;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
153 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
154 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
155
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
156 // close plugin
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
157 static void uninit(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
158 if(pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
159 free(pl_resample.data);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
160 pl_resample.data=NULL;
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
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
163 // empty buffers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
164 static void reset(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
165 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
166
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
167 // processes 'ao_plugin_data.len' bytes of 'data'
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
168 // called for every block of data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
169 // 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
170 static int play(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
171 static uint16_t pwi = 0; // Index for w
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
172 static uint16_t pxi = 0; // Index for circular queue
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
173 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
174
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
175 uint16_t ci = pl_resample.channels; // Index for channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
176 uint16_t len = 0; // Number of output samples
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
177 uint16_t nch = pl_resample.channels; // Number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
178 uint16_t inc = pl_resample.dn/pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
179 uint16_t level = pl_resample.dn%pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
180 uint16_t up = pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
181 uint16_t dn = pl_resample.dn;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
182
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
183 register uint16_t i,wi,xi; // Temporary indexes
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 if(pl_resample.bypass)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
186 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
187
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
188 // Index current channel
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
189 while(ci--){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
190 // Temporary pointers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
191 register int16_t* x = pl_resample.xs[ci];
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
192 register int16_t* in = ((int16_t*)ao_plugin_data.data)+ci;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
193 register int16_t* out = pl_resample.data+ci;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
194 // Block loop end
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
195 register int16_t* end = in+ao_plugin_data.len/2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
196 i = pi; wi = pwi; xi = pxi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
197
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
198 LOAD_QUE(x);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
199 if(0!=i) goto L1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
200 while(in < end){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
201 // Update wi to point at the correct polyphase component
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
202 wi=(wi+dn)%up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
203
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
204 /* 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
205 for upsamling and inc or inc + 1 times for downsampling */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
206 if(wi<level) goto L3;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
207 if(0==i) goto L2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
208 L1: i--;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
209 L3: UPDATE_QUE(in);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
210 in+=nch;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
211 if(in >= end) goto L2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
212 if(i) goto L1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
213 L2: if(i) goto L5;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
214 i=inc;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
215
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
216 /* Get the correct polyphase component and the correct startpoint
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
217 in the circular bufer and run the FIR filter */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
218 FIR((&x[xi]),(&pl_resample.w[wi*L]),out);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
219 len++;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
220 out+=nch;
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 L5:
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
223 SAVE_QUE(x);
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 // Save values that needs to be kept for next time
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
227 pwi = wi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
228 pxi = xi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
229 pi = i;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
230 // Set new data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
231 ao_plugin_data.len=len*2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
232 ao_plugin_data.data=pl_resample.data;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
233 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
234 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
235
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
236
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
237
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
238
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
239