File: downsample_interpolate.patch

package info (click to toggle)
line6-usb 0.7.3-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 324 kB
  • ctags: 648
  • sloc: ansic: 4,215; sh: 120; makefile: 90; perl: 69
file content (50 lines) | stat: -rw-r--r-- 1,616 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--- alsa-lib-1.0.6-orig/src/pcm/pcm_rate.c	2004-08-09 08:31:41.000000000 +0200
+++ alsa-lib-1.0.6/src/pcm/pcm_rate.c	2004-09-05 22:46:17.947253031 +0200
@@ -45,7 +45,8 @@
 #ifndef DOC_HIDDEN
 
 /* LINEAR_DIV needs to be large enough to handle resampling from 192000 -> 8000 */
-#define LINEAR_DIV (1<<19)
+#define LINEAR_DIV_SHIFT 19
+#define LINEAR_DIV (1<<LINEAR_DIV_SHIFT)
 
 enum rate_type {
 	RATE_TYPE_LINEAR,		/* linear interpolation */
@@ -206,9 +207,12 @@
 		const char *src;
 		char *dst;
 		int src_step, dst_step;
+		int16_t old_sample = 0;
+		int16_t new_sample = 0;
+		int old_weight, new_weight;
 		sum = states->u.linear.sum;
 		//int16_t old_sample = states->u.linear.old_sample;
-		pos = LINEAR_DIV/2; /* Start at 0.5 */
+		pos = LINEAR_DIV - get_increment; /* Force first sample to be copied */
 		states->u.linear.init = 0;
 		src = snd_pcm_channel_area_addr(src_area, src_offset);
 		dst = snd_pcm_channel_area_addr(dst_area, dst_offset);
@@ -223,11 +227,15 @@
 #include "plugin_ops.h"
 #undef GET16_END
 		after_get:
+			new_sample = sample;
 			src += src_step;
 			src_frames1++;
 			pos += get_increment;
 			if (pos >= LINEAR_DIV) {
 				pos -= LINEAR_DIV;
+				old_weight = (pos << (32 - LINEAR_DIV_SHIFT)) / (get_increment >> (LINEAR_DIV_SHIFT - 16));
+				new_weight = 0x10000 - old_weight;
+				sample = (old_sample * old_weight + new_sample * new_weight) >> 16;
 				goto *put;
 #define PUT16_END after_put
 #include "plugin_ops.h"
@@ -237,6 +245,7 @@
 				dst_frames1++;
 				assert(dst_frames1 <= dst_frames);
 			}
+			old_sample = new_sample;
 		}
 
 		states->u.linear.sum = sum;