annotate libao2/pl_resample.c @ 8660:39476cbd1673

I have looked at the fullscreen code and realized that there are generally two types of layer support for window managers: - NetWM states (FULLSCREEN, STAYS_ON_TOP, ABOVE) sawfish, metacity, kwin - _WIN_LAYER IceWM, WindowMaker So we don't need any other window manager detection functions, we need only to check for these two. Code tested on lots of windowmanagers. patch by Filip Kalinski <filon@pld.org.pl>
author arpi
date Mon, 30 Dec 2002 18:50:15 +0000
parents fb88ccbc5ccc
children cd67631ae382
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"
4535
99dc749591e2 Enable SSH optimizations for FIR filter
anders
parents: 4374
diff changeset
27 #include "../config.h"
3631
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.
4725
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
43 Valid definitions are L8 and L16, where the number denotes the
3631
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
4725
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
46 memory usage. The filterlenght is choosen to 8 if the machine is
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
47 slow and to 16 if the machine is fast and has MMX.
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
48 */
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
49
4725
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
50 #if !defined(HAVE_SSE) && !defined(HAVE_3DNOW) //This machine is slow
4789
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
51
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
52 #define W W8 // Filter bank parameters
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
53 #define L 8 // Filter length
4789
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
54 #ifdef HAVE_MMX
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
55 #define FIR(x,w,y) *y=(int16_t)firn(x,w,8);
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
56 #else /* HAVE_MMX */
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
57 // Unrolled loop to speed up execution
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
58 #define FIR(x,w,y){ \
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
59 int16_t a = (w[0]*x[0]+w[1]*x[1]+w[2]*x[2]+w[3]*x[3]) >> 16; \
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
60 int16_t b = (w[4]*x[4]+w[5]*x[5]+w[6]*x[6]+w[7]*x[7]) >> 16; \
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
61 y[0] = a+b; \
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
62 }
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
63 #endif /* HAVE_MMX */
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
64
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
65 #else /* Fast machine */
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
66
4725
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
67 #define W W16
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
68 #define L 16
4789
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
69 #define FIR(x,w,y) *y=(int16_t)firn(x,w,16);
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
70
4725
534ef9323eca MMX part rewritten and 16 tap filter added for better sound qualty
anders
parents: 4535
diff changeset
71 #endif
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
72
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
73 #define CH 6 // Max number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
74 #define UP 128 /* Up sampling factor. Increasing this value will
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
75 improve frequency accuracy. Think about the L1
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
76 cashing of filter parameters - how big can it be? */
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
77
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
78 #include "fir.h"
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
79 #include "filter.h"
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 // local data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
82 typedef struct pl_resample_s
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
83 {
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
84 int16_t* data; // Data buffer
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
85 int16_t* w; // Current filter weights
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
86 uint16_t dn; // Down sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
87 uint16_t up; // Up sampling factor
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
88 int channels; // Number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
89 int len; // Lenght of buffer
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
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
94 static pl_resample_t pl_resample = {NULL,NULL,1,1,1,0,W};
3631
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 *
4374
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 4171
diff changeset
107 ((double)pl_resample.dn)/
0a95c5074c50 Fixed sig 11 caused by resampling plugin, some cosmetic changes and speed improvements
anders
parents: 4171
diff changeset
108 ((double)pl_resample.up));
3631
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));
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
133
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
134 pl_resample.channels=ao_plugin_data.channels;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
135 if(ao_plugin_data.channels>CH){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
136 fprintf(stderr,"[pl_resample] Too many channels, max is 6.\n");
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
137 return 0;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
138 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
139
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
140 // Tell the world what we are up to
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
141 printf("[pl_resample] Up=%i, Down=%i, True fout=%f\n",
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
142 pl_resample.up,pl_resample.dn,
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
143 ((float)fin*pl_resample.up)/((float)pl_resample.dn));
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
144
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
145 // This plugin changes buffersize and adds some delay
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
146 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
147 ao_plugin_data.delay_fix-= ((float)L/2) * (1/fout);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
148 ao_plugin_data.rate=fout;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
149 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
150 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
151
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
152 // close plugin
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
153 static void uninit(){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
154 if(pl_resample.data)
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
155 free(pl_resample.data);
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
156 pl_resample.data=NULL;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
157 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
158
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
159 // empty buffers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
160 static void reset(){
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
8123
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 7472
diff changeset
163 /* forward declarations */
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 7472
diff changeset
164 int upsample();
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 7472
diff changeset
165 int downsample();
9fc45fe0d444 *HUGE* set of compiler warning fixes, unused variables removal
arpi
parents: 7472
diff changeset
166
3631
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(){
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
171 if(pl_resample.up==pl_resample.dn){
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
172 register int16_t* in = ((int16_t*)ao_plugin_data.data);
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
173 register int16_t* end = in+ao_plugin_data.len/2;
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 8123
diff changeset
174 while(in < end) *(in++)>>=1;
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
175 return 1;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
176 }
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
177 if(pl_resample.up>pl_resample.dn)
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
178 return upsample();
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 4789
diff changeset
179 // if(pl_resample.up<pl_resample.dn)
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
180 return downsample();
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
181 }
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
182
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
183 int upsample(){
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
184 static uint16_t pwi = 0; // Index for w
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
185 static uint16_t pxi = 0; // Index for circular queue
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
186
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
187 uint16_t ci = pl_resample.channels; // Index for channels
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
188 uint16_t nch = pl_resample.channels; // Number of channels
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
189 uint16_t len = 0; // Number of input samples
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
190 uint16_t inc = pl_resample.up/pl_resample.dn;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
191 uint16_t level = pl_resample.up%pl_resample.dn;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
192 uint16_t up = pl_resample.up;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
193 uint16_t dn = pl_resample.dn;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
194
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
195 register int16_t* w = pl_resample.w;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
196 register uint16_t wi,xi; // Temporary indexes
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
197
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
198 // Index current channel
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
199 while(ci--){
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
200 // Temporary pointers
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
201 register int16_t* x = pl_resample.xs[ci];
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
202 register int16_t* in = ((int16_t*)ao_plugin_data.data)+ci;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
203 register int16_t* out = pl_resample.data+ci;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
204 int16_t* end = in+ao_plugin_data.len/2; // Block loop end
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
205
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
206 wi = pwi; xi = pxi;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
207
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
208 while(in < end){
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
209 register uint16_t i = inc;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
210 if(wi<level) i++;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
211
4789
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
212 xi=updateq(x,in,xi,L);
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
213 in+=nch;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
214 while(i--){
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
215 // Run the FIR filter
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
216 FIR((&x[xi]),(&w[wi*L]),out);
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
217 len++; out+=nch;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
218 // Update wi to point at the correct polyphase component
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
219 wi=(wi+dn)%up;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
220 }
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
221 }
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
222 }
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
223
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
224 // Save values that needs to be kept for next time
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
225 pwi = wi;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
226 pxi = xi;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
227
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
228 // Set new data
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
229 ao_plugin_data.len=len*2;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
230 ao_plugin_data.data=pl_resample.data;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
231 return 1;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
232 }
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
233
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
234 int downsample(){
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
235 static uint16_t pwi = 0; // Index for w
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
236 static uint16_t pxi = 0; // Index for circular queue
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
237 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
238
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
239 uint16_t ci = pl_resample.channels; // Index for channels
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
240 uint16_t len = 0; // Number of input samples
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
241 uint16_t nch = pl_resample.channels; // Number of channels
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
242 uint16_t inc = pl_resample.dn/pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
243 uint16_t level = pl_resample.dn%pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
244 uint16_t up = pl_resample.up;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
245 uint16_t dn = pl_resample.dn;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
246
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
247 register uint16_t i,wi,xi; // Temporary indexes
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
248
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
249
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
250 // Index current channel
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
251 while(ci--){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
252 // Temporary pointers
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
253 register int16_t* x = pl_resample.xs[ci];
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
254 register int16_t* in = ((int16_t*)ao_plugin_data.data)+ci;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
255 register int16_t* out = pl_resample.data+ci;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
256 // Block loop end
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
257 register int16_t* end = in+ao_plugin_data.len/2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
258 i = pi; wi = pwi; xi = pxi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
259
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
260 while(in < end){
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
261
4789
c2bb05709676 Cleanup and comment
anders
parents: 4725
diff changeset
262 xi=updateq(x,in,xi,L);
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
263 in+=nch;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
264 if(!--i){
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
265 // Run the FIR filter
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
266 FIR((&x[xi]),(&pl_resample.w[wi*L]),out);
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
267 len++; out+=nch;
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
268
4171
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
269 // Update wi to point at the correct polyphase component
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
270 wi=(wi+dn)%up;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
271
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
272 // Insert i number of new samples in queue
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
273 i = inc;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
274 if(wi<level) i++;
585f0c77d8f5 Sync problem when using fractional resampling fixed + speed increased.
anders
parents: 4049
diff changeset
275 }
3631
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
276 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
277 }
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
278 // Save values that needs to be kept for next time
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
279 pwi = wi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
280 pxi = xi;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
281 pi = i;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
282 // Set new data
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
283 ao_plugin_data.len=len*2;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
284 ao_plugin_data.data=pl_resample.data;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
285 return 1;
5f5189ac6a41 Added plugin for fractional resampling (alpha code)
anders
parents:
diff changeset
286 }