Mercurial > audlegacy
annotate Plugins/Input/mpg123/psycho.c @ 1112:73631b1e8611 trunk
[svn] - new tunings, please test
author | nenolod |
---|---|
date | Tue, 30 May 2006 21:55:51 -0700 |
parents | dec5caa8768b |
children | f7563194112d |
rev | line source |
---|---|
1090
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
1 /* libmpgdec: An advanced MPEG layer 1/2/3 decoder. |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
2 * psycho.c: Psychoaccoustic modeling. |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
3 * |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
4 * Copyright (C) 2005-2006 William Pitcock <nenolod@nenolod.net> |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
5 * Portions copyright (C) 2001 Rafal Bosak <gyver@fanthom.irc.pl> |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
6 * Portions copyright (C) 1999 Michael Hipp |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
7 * |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
8 * This program is free software; you can redistribute it and/or modify |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
11 * (at your option) any later version. |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
12 * |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
16 * GNU General Public License for more details. |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
17 * |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
21 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
22 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
23 #include <stdio.h> |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
24 #include <stdlib.h> |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
25 #include <math.h> |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
26 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
27 #include "common.h" |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
28 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
29 int bext_level; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
30 int echo_level; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
31 int stereo_level; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
32 int filter_level; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
33 int feedback_level; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
34 int harmonics_level; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
35 int bext_sfactor; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
36 int echo_sfactor; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
37 int stereo_sfactor; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
38 int feedback_sfactor; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
39 int harmonics_sfactor; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
40 int enable_plugin = 1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
41 int lsine[65536]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
42 int rsine[65536]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
43 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
44 /* |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
45 * Initialize and configure the psychoaccoustics engine. |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
46 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
47 void psycho_init(void) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
48 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
49 int i, x; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
50 double lsum; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
51 double rsum; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
52 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
53 bext_level = 28; |
1112 | 54 echo_level = echo_sfactor = 0; |
1093
cb5780140f43
[svn] - stereo seperation hysterisis of 16dB vs 20dB
nenolod
parents:
1092
diff
changeset
|
55 stereo_level = stereo_sfactor = 16; |
1090
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
56 filter_level = 3; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
57 feedback_level = 30; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
58 harmonics_level = harmonics_sfactor = 43; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
59 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
60 bext_sfactor = (float)(((float)16384 * 10) / (float)(bext_level + 1)) + (float)(102 - bext_level) * 128; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
61 feedback_sfactor = (feedback_level * 3) / 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
62 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
63 #define COND 0 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
64 /* calculate sinetables */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
65 for (i = 0; i < 32768; ++i) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
66 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
67 lsum = rsum = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
68 if (COND || i < 32768 )lsum+= ((cos((double)i * 3.141592535 / 32768/2 )) + 0) / 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
69 if (COND || i < 16384 )rsum-= ((cos((double)i * 3.141592535 / 16384/2 )) + 0) / 4; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
70 rsum = lsum; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
71 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
72 if (COND || i < 8192 ) lsum += ((cos((double)i * 3.141592535 / 8192/2 )) + 0) / 8; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
73 if (COND || i < 5641 ) rsum += ((cos((double)i * 3.141592535 / 5641.333333/2)) + 0) / 8; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
74 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
75 lsine[32768 + i] = (double)(lsum - 0.5) * 32768 * 1.45; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
76 lsine[32768 - i] = lsine[32768 + i]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
77 rsine[32768 + i] = (double)(rsum - 0.5) * 32768 * 1.45; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
78 rsine[32768 - i] = rsine[32768 + i]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
79 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
80 x = i; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
81 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
82 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
83 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
84 /* |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
85 * This routine computes a reverb for the track. |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
86 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
87 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
88 #define DELAY2 21000 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
89 #define DELAY1 35000 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
90 #define DELAY3 14000 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
91 #define DELAY4 5 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
92 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
93 #define BUF_SIZE DELAY1+DELAY2+DELAY3+DELAY4 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
94 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
95 void echo3d(gint16 *data, int datasize) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
96 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
97 int x; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
98 int left, right, dif, left0, right0, left1, right1, left2, right2, left3, right3, left4, right4, leftc, rightc, lsf, rsf; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
99 static int left0p = 0, right0p = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
100 static int rangeErrorsUp = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
101 static int rangeErrorsDown = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
102 gint16 *dataptr; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
103 static int l0, l1, l2, r0, r1, r2, ls, rs, ls1, rs1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
104 static int ll0, ll1, ll2, rr0, rr1, rr2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
105 static int lharmb = 0, rharmb = 0, lhfb = 0, rhfb = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
106 int lharm0, rharm0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
107 static gint16 buf[BUF_SIZE]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
108 static int bufPos = BUF_SIZE - 1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
109 static int bufPos1 = 1 + BUF_SIZE - DELAY1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
110 static int bufPos2 = 1 + BUF_SIZE - DELAY1 - DELAY2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
111 static int bufPos3 = 1 + BUF_SIZE - DELAY1 - DELAY2 - DELAY3; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
112 static int bufPos4 = 1 + BUF_SIZE - DELAY1 - DELAY2 - DELAY3 - DELAY4; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
113 dataptr = data; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
114 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
115 for (x = 0; x < datasize; x += 4) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
116 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
117 // ************ load sample ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
118 left0 = dataptr[0]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
119 right0 = dataptr[1]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
120 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
121 // ************ slightly expand stereo for direct input ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
122 ll0=left0;rr0=right0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
123 dif = (ll0+ll1+ll2 - rr0-rr1-rr2) * stereo_sfactor / 256; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
124 left0 += dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
125 right0 -= dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
126 ll2= ll1; ll1= ll0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
127 rr2= rr1; rr1= rr0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
128 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
129 // ************ echo from buffer - first echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
130 // ************ ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
131 left1 = buf[bufPos1++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
132 if (bufPos1 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
133 bufPos1 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
134 right1 = buf[bufPos1++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
135 if (bufPos1 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
136 bufPos1 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
137 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
138 // ************ highly expand stereo for first echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
139 dif = (left1 - right1); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
140 left1 = left1 + dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
141 right1 = right1 - dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
142 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
143 // ************ second echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
144 left2 = buf[bufPos2++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
145 if (bufPos2 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
146 bufPos2 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
147 right2 = buf[bufPos2++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
148 if (bufPos2 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
149 bufPos2 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
150 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
151 // ************ expand stereo for second echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
152 dif = (left2 - right2); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
153 left2 = left2 - dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
154 right2 = right2 - dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
155 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
156 // ************ third echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
157 left3 = buf[bufPos3++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
158 if (bufPos3 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
159 bufPos3 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
160 right3 = buf[bufPos3++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
161 if (bufPos3 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
162 bufPos3 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
163 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
164 // ************ fourth echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
165 left4 = buf[bufPos4++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
166 if (bufPos4 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
167 bufPos4 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
168 right4 = buf[bufPos4++]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
169 if (bufPos4 == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
170 bufPos4 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
171 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
172 left3 = (left4+left3) / 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
173 right3 = (right4+right3) / 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
174 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
175 // ************ expand stereo for second echo ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
176 dif = (left4 - right4); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
177 left3 = left3 - dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
178 right3 = right3 - dif; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
179 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
180 // ************ a weighted sum taken from reverb buffer ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
181 leftc = left1 / 9 + right2 /8 + left3 / 8; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
182 rightc = right1 / 11 + left2 / 9 + right3 / 10; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
183 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
184 left = left0p + leftc * echo_sfactor / 16; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
185 right = right0p + rightc * echo_sfactor / 16; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
186 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
187 l0 = leftc + left0 / 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
188 r0 = rightc + right0 / 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
189 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
190 ls = l0 + l1 + l2; // do not reverb high frequencies (filter) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
191 rs = r0 + r1 + r2; // |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
192 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
193 buf[bufPos++] = ls * feedback_sfactor / 256; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
194 if (bufPos == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
195 bufPos = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
196 buf[bufPos++] = rs * feedback_sfactor / 256; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
197 if (bufPos == BUF_SIZE) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
198 bufPos = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
199 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
200 // ************ add some extra even harmonics ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
201 // ************ or rather specific nonlinearity |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
202 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
203 lhfb = lhfb + (ls * 32768 - lhfb) / 32; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
204 rhfb = rhfb + (rs * 32768 - rhfb) / 32; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
205 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
206 lsf = ls - lhfb / 32768; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
207 rsf = rs - rhfb / 32768; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
208 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
209 lharm0 = 0 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
210 + ((lsf + 10000) * ((((lsine[((lsf/4) + 32768 + 65536) % 65536] * harmonics_sfactor)) / 64))) / 32768 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
211 - ((lsine[((lsf/4) + 32768 +65536) % 65536]) * harmonics_sfactor) / 128 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
212 ; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
213 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
214 rharm0 = |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
215 + ((rsf + 10000) * ((((lsine[((rsf/4) + 32768 + 65536) % 65536] * harmonics_sfactor)) / 64))) / 32768 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
216 - ((rsine[((rsf/4) + 32768 +65536) % 65536]) * harmonics_sfactor) / 128 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
217 ; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
218 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
219 lharmb = lharmb + (lharm0 * 32768 - lharmb) / 16384; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
220 rharmb = rharmb + (rharm0 * 32768 - rharmb) / 16384; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
221 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
222 // ************ for convolution filters ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
223 l2= l1; r2= r1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
224 l1 = l0; r1 = r0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
225 ls1 = ls; rs1 = rs; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
226 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
227 left = 0 + lharm0 - lharmb / 32768 + left; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
228 right = 0 + rharm0 - rharmb / 32768 + right; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
229 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
230 left0p = left0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
231 right0p = right0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
232 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
233 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
234 // ************ limiter ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
235 if (left < -32768) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
236 left = -32768; // limit |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
237 rangeErrorsDown++; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
238 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
239 else if (left > 32767) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
240 left = 32767; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
241 rangeErrorsUp++; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
242 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
243 if (right < -32768) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
244 right = -32768; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
245 rangeErrorsDown++; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
246 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
247 else if (right > 32767) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
248 right = 32767; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
249 rangeErrorsUp++; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
250 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
251 // ************ store sample ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
252 dataptr[0] = left; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
253 dataptr[1] = right; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
254 dataptr += 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
255 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
256 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
257 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
258 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
259 /* |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
260 * simple pith shifter, plays short fragments at 1.5 speed |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
261 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
262 void pitchShifter(const int lin, const int rin, int *lout, int *rout) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
263 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
264 #define SH_BUF_SIZE 100 * 3 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
265 static gint16 shBuf[SH_BUF_SIZE]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
266 static int shBufPos = SH_BUF_SIZE - 6; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
267 static int shBufPos1 = SH_BUF_SIZE - 6; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
268 static int cond; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
269 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
270 shBuf[shBufPos++] = lin; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
271 shBuf[shBufPos++] = rin; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
272 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
273 if (shBufPos == SH_BUF_SIZE) shBufPos = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
274 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
275 switch (cond){ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
276 case 1: |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
277 *lout = (shBuf[shBufPos1 + 0] * 2 + shBuf[shBufPos1 + 2])/4; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
278 *rout = (shBuf[shBufPos1 + 1] * 2 + shBuf[shBufPos1 + 3])/4; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
279 break; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
280 case 0: |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
281 *lout = (shBuf[shBufPos1 + 4] * 2 + shBuf[shBufPos1 + 2])/4; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
282 *rout = (shBuf[shBufPos1 + 5] * 2 + shBuf[shBufPos1 + 3])/4; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
283 cond = 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
284 shBufPos1 += 6; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
285 if (shBufPos1 == SH_BUF_SIZE) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
286 shBufPos1 = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
287 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
288 break; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
289 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
290 cond--; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
291 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
292 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
293 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
294 struct Interpolation{ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
295 int acount; // counter |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
296 int lval, rval; // value |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
297 int sal, sar; // sum |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
298 int al, ar; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
299 int a1l, a1r; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
300 }; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
301 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
302 /* |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
303 * interpolation routine for ampliude and "energy" |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
304 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
305 static inline void interpolate(struct Interpolation *s, int l, int r) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
306 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
307 #define AMPL_COUNT 64 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
308 int a0l, a0r, dal = 0, dar = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
309 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
310 if (l < 0) l = -l; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
311 if (r < 0) r = -r; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
312 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
313 s->lval += l / 8; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
314 s->rval += r / 8; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
315 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
316 s->lval = (s->lval * 120) / 128; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
317 s->rval = (s->rval * 120) / 128; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
318 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
319 s->sal += s->lval; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
320 s->sar += s->rval; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
321 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
322 s->acount++; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
323 if (s->acount == AMPL_COUNT){ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
324 s->acount = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
325 a0l = s->a1l; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
326 a0r = s->a1r; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
327 s->a1l = s->sal / AMPL_COUNT; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
328 s->a1r = s->sar / AMPL_COUNT; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
329 s->sal = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
330 s->sar = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
331 dal = s->a1l - a0l; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
332 dar = s->a1r - a0r; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
333 s->al = a0l * AMPL_COUNT; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
334 s->ar = a0r * AMPL_COUNT; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
335 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
336 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
337 s->al += dal; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
338 s->ar += dar; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
339 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
340 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
341 /* |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
342 * calculate scalefactor for mixer |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
343 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
344 inline int calc_scalefactor(int a, int e) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
345 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
346 int x; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
347 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
348 if (a > 8192) a = 8192; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
349 else if (a < 0) a = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
350 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
351 if (e > 8192) e = 8192; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
352 else if (e < 0) e = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
353 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
354 x = ((e+500) * 4096 )/ (a + 300) + e; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
355 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
356 if (x > 16384) x = 16384; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
357 else if (x < 0) x = 0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
358 return x; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
359 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
360 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
361 static struct Interpolation bandext_energy; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
362 static struct Interpolation bandext_amplitude; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
363 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
364 /* |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
365 * exact bandwidth extender ("exciter") routine |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
366 */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
367 static void bandext(gint16 *data, const int datasize) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
368 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
369 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
370 int x; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
371 static int saw; // test stuff |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
372 int left, right; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
373 gint16 *dataptr = data; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
374 static int lprev0, rprev0, lprev1, rprev1, lprev2, rprev2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
375 int left0, right0, left1, right1, left2, right2, left3, right3; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
376 static int lamplUp, lamplDown; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
377 static int ramplUp, ramplDown; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
378 int lampl, rampl; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
379 int tmp; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
380 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
381 for (x = 0; x < datasize; x += 4) { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
382 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
383 // ************ load sample ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
384 left0 = dataptr[0]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
385 right0 = dataptr[1]; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
386 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
387 // ************ highpass filter part 1 ********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
388 left1 = (left0 - lprev0) * 56880 / 65536; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
389 right1 = (right0 - rprev0) * 56880 / 65536; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
390 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
391 left2 = (left1 - lprev1) * 56880 / 65536; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
392 right2 = (right1 - rprev1) * 56880 / 65536; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
393 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
394 left3 = (left2 - lprev2) * 56880 / 65536; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
395 right3 = (right2 - rprev2) * 56880 / 65536; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
396 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
397 switch (filter_level){ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
398 case 1: |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
399 pitchShifter(left1, right1, &left, &right); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
400 break; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
401 case 2: |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
402 pitchShifter(left2, right2, &left, &right); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
403 break; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
404 case 3: |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
405 pitchShifter(left3, right3, &left, &right); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
406 break; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
407 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
408 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
409 // ************ amplitude detector ************ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
410 tmp = left1 + lprev1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
411 if (tmp * 16 > lamplUp ) lamplUp += (tmp - lamplUp ); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
412 else if (tmp * 16 < lamplDown) lamplDown += (tmp - lamplDown); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
413 lamplUp = (lamplUp * 1000) /1024; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
414 lamplDown = (lamplDown * 1000) /1024; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
415 lampl = lamplUp - lamplDown; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
416 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
417 tmp = right1 + rprev1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
418 if (tmp * 16 > ramplUp ) ramplUp += (tmp - ramplUp ); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
419 else if (tmp * 16 < ramplDown) ramplDown += (tmp - ramplDown); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
420 ramplUp = (ramplUp * 1000) /1024; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
421 ramplDown = (ramplDown * 1000) /1024; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
422 rampl = ramplUp - ramplDown; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
423 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
424 interpolate(&bandext_amplitude, lampl, rampl); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
425 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
426 // ************ "sound energy" detector (approx. spectrum complexity) *********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
427 interpolate(&bandext_energy, left0 - lprev0, right0 - rprev0); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
428 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
429 // ************ mixer *********** |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
430 left = left0 + left * calc_scalefactor(bandext_amplitude.lval, bandext_energy.lval) / bext_sfactor; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
431 right = right0 + right * calc_scalefactor(bandext_amplitude.rval, bandext_energy.rval) / bext_sfactor; //16384 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
432 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
433 saw = (saw + 2048) & 0x7fff; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
434 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
435 lprev0 = left0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
436 rprev0 = right0; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
437 lprev1 = left1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
438 rprev1 = right1; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
439 lprev2 = left2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
440 rprev2 = right2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
441 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
442 if (left < -32768) left = -32768; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
443 else if (left > 32767) left = 32767; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
444 if (right < -32768) right = -32768; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
445 else if (right > 32767) right = 32767; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
446 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
447 dataptr[0] = left; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
448 dataptr[1] = right; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
449 dataptr += 2; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
450 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
451 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
452 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
453 int psycho_process(void *data, int length, int nch) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
454 { |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
455 if (nch != 2) |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
456 return length; /* XXX: we cant process mono yet */ |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
457 |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
458 echo3d((gint16 *)data, length); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
459 bandext((gint16 *)data, length); |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
460 return length; |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
461 } |
09eb2c83097a
[svn] Psychoaccoustics support (to disable, temporarily add -UPSYCHO to your CFLAGS.):
nenolod
parents:
diff
changeset
|
462 |