annotate libaf/af_volnorm.c @ 15344:6a7adf41e4fe

Support for new vssh dll, patch by adland Use new dll only for new files, it can't decode old files (patch by me)
author rtognimp
date Wed, 04 May 2005 20:35:21 +0000
parents 815f03b7cee5
children 9352446d4fa8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
1 /*=============================================================================
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
2 //
13602
14090f7300a8 The full name of the GPL is GNU General Public License.
diego
parents: 13550
diff changeset
3 // This software has been released under the terms of the GNU General Public
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
4 // license. See http://www.gnu.org/copyleft/gpl.html for details.
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
5 //
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
6 // Copyright 2004 Alex Beregszaszi & Pierre Lombard
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
7 //
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
8 //=============================================================================
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
9 */
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
10
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
11 #include <stdio.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
12 #include <stdlib.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
13 #include <string.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
14
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
15 #include <unistd.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
16 #include <inttypes.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
17 #include <math.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
18 #include <limits.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
19
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
20 #include "af.h"
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
21
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
22 // Methods:
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
23 // 1: uses a 1 value memory and coefficients new=a*old+b*cur (with a+b=1)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
24 // 2: uses several samples to smooth the variations (standard weighted mean
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
25 // on past samples)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
26
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
27 // Size of the memory array
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
28 // FIXME: should depend on the frequency of the data (should be a few seconds)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
29 #define NSAMPLES 128
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
30
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
31 // If summing all the mem[].len is lower than MIN_SAMPLE_SIZE bytes, then we
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
32 // choose to ignore the computed value as it's not significant enough
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
33 // FIXME: should depend on the frequency of the data (0.5s maybe)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
34 #define MIN_SAMPLE_SIZE 32000
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
35
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
36 // mul is the value by which the samples are scaled
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
37 // and has to be in [MUL_MIN, MUL_MAX]
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
38 #define MUL_INIT 1.0
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
39 #define MUL_MIN 0.1
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
40 #define MUL_MAX 5.0
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
41 // "Ideal" level
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
42 #define MID_S16 (SHRT_MAX * 0.25)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
43 #define MID_FLOAT (INT_MAX * 0.25)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
44
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
45 // Silence level
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
46 // FIXME: should be relative to the level of the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
47 #define SIL_S16 (SHRT_MAX * 0.01)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
48 #define SIL_FLOAT (INT_MAX * 0.01) // FIXME
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
49
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
50 // smooth must be in ]0.0, 1.0[
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
51 #define SMOOTH_MUL 0.06
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
52 #define SMOOTH_LASTAVG 0.06
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
53
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
54 // Data for specific instances of this filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
55 typedef struct af_volume_s
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
56 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
57 int method; // method used
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
58 float mul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
59 // method 1
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
60 float lastavg; // history value of the filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
61 // method 2
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
62 int idx;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
63 struct {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
64 float avg; // average level of the sample
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
65 int len; // sample size (weight)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
66 } mem[NSAMPLES];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
67 }af_volnorm_t;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
68
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
69 // Initialization and runtime control
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
70 static int control(struct af_instance_s* af, int cmd, void* arg)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
71 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
72 af_volnorm_t* s = (af_volnorm_t*)af->setup;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
73
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
74 switch(cmd){
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
75 case AF_CONTROL_REINIT:
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
76 // Sanity check
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
77 if(!arg) return AF_ERROR;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
78
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
79 af->data->rate = ((af_data_t*)arg)->rate;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
80 af->data->nch = ((af_data_t*)arg)->nch;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
81
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
82 if(((af_data_t*)arg)->format == (AF_FORMAT_S16_NE)){
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
83 af->data->format = AF_FORMAT_S16_NE;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
84 af->data->bps = 2;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
85 }else{
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
86 af->data->format = AF_FORMAT_FLOAT_NE;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
87 af->data->bps = 4;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
88 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
89 return af_test_output(af,(af_data_t*)arg);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
90 case AF_CONTROL_COMMAND_LINE:{
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
91 int i;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
92 sscanf((char*)arg,"%d", &i);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
93 if (i != 1 && i != 2)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
94 return AF_ERROR;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
95 s->method = i-1;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
96 return AF_OK;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
97 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
98 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
99 return AF_UNKNOWN;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
100 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
101
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
102 // Deallocate memory
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
103 static void uninit(struct af_instance_s* af)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
104 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
105 if(af->data)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
106 free(af->data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
107 if(af->setup)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
108 free(af->setup);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
109 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
110
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
111 static void method1_int16(af_volnorm_t *s, af_data_t *c)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
112 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
113 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
114 int16_t *data = (int16_t*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
115 int len = c->len/2; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
116 float curavg = 0.0, newavg, neededmul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
117 int tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
118
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
119 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
120 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
121 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
122 curavg += tmp * tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
123 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
124 curavg = sqrt(curavg / (float) len);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
125
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
126 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
127 // samples level, etc
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
128
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
129 if (curavg > SIL_S16)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
130 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
131 neededmul = MID_S16 / (curavg * s->mul);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
132 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
133
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
134 // clamp the mul coefficient
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
135 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
136 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
137
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
138 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
139 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
140 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
141 tmp = s->mul * data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
142 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
143 data[i] = tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
144 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
145
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
146 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
147 newavg = s->mul * curavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
148
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
149 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
150 s->lastavg = (1.0 - SMOOTH_LASTAVG) * s->lastavg + SMOOTH_LASTAVG * newavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
151 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
152
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
153 static void method1_float(af_volnorm_t *s, af_data_t *c)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
154 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
155 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
156 float *data = (float*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
157 int len = c->len/4; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
158 float curavg = 0.0, newavg, neededmul, tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
159
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
160 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
161 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
162 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
163 curavg += tmp * tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
164 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
165 curavg = sqrt(curavg / (float) len);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
166
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
167 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
168 // samples level, etc
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
169
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
170 if (curavg > SIL_FLOAT) // FIXME
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
171 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
172 neededmul = MID_FLOAT / (curavg * s->mul);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
173 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
174
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
175 // clamp the mul coefficient
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
176 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
177 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
178
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
179 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
180 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
181 data[i] *= s->mul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
182
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
183 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
184 newavg = s->mul * curavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
185
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
186 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
187 s->lastavg = (1.0 - SMOOTH_LASTAVG) * s->lastavg + SMOOTH_LASTAVG * newavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
188 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
189
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
190 static void method2_int16(af_volnorm_t *s, af_data_t *c)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
191 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
192 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
193 int16_t *data = (int16_t*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
194 int len = c->len/2; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
195 float curavg = 0.0, newavg, avg = 0.0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
196 int tmp, totallen = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
197
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
198 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
199 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
200 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
201 curavg += tmp * tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
202 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
203 curavg = sqrt(curavg / (float) len);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
204
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
205 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
206 // samples level, etc
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
207 for (i = 0; i < NSAMPLES; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
208 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
209 avg += s->mem[i].avg * (float)s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
210 totallen += s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
211 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
212
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
213 if (totallen > MIN_SAMPLE_SIZE)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
214 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
215 avg /= (float)totallen;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
216 if (avg >= SIL_S16)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
217 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
218 s->mul = MID_S16 / avg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
219 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
220 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
221 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
222
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
223 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
224 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
225 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
226 tmp = s->mul * data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
227 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
228 data[i] = tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
229 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
230
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
231 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
232 newavg = s->mul * curavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
233
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
234 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
235 s->mem[s->idx].len = len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
236 s->mem[s->idx].avg = newavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
237 s->idx = (s->idx + 1) % NSAMPLES;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
238 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
239
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
240 static void method2_float(af_volnorm_t *s, af_data_t *c)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
241 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
242 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
243 float *data = (float*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
244 int len = c->len/4; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
245 float curavg = 0.0, newavg, avg = 0.0, tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
246 int totallen = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
247
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
248 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
249 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
250 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
251 curavg += tmp * tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
252 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
253 curavg = sqrt(curavg / (float) len);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
254
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
255 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
256 // samples level, etc
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
257 for (i = 0; i < NSAMPLES; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
258 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
259 avg += s->mem[i].avg * (float)s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
260 totallen += s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
261 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
262
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
263 if (totallen > MIN_SAMPLE_SIZE)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
264 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
265 avg /= (float)totallen;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
266 if (avg >= SIL_FLOAT)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
267 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
268 s->mul = MID_FLOAT / avg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
269 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
270 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
271 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
272
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
273 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
274 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
275 data[i] *= s->mul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
276
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
277 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
278 newavg = s->mul * curavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
279
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
280 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
281 s->mem[s->idx].len = len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
282 s->mem[s->idx].avg = newavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
283 s->idx = (s->idx + 1) % NSAMPLES;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
284 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
285
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
286 // Filter data through filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
287 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
288 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
289 af_volnorm_t *s = af->setup;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
290
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
291 if(af->data->format == (AF_FORMAT_S16_NE))
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
292 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
293 if (s->method)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
294 method2_int16(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
295 else
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
296 method1_int16(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
297 }
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
298 else if(af->data->format == (AF_FORMAT_FLOAT_NE))
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
299 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
300 if (s->method)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
301 method2_float(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
302 else
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
303 method1_float(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
304 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
305 return data;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
306 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
307
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
308 // Allocate memory and set function pointers
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
309 static int open(af_instance_t* af){
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
310 int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
311 af->control=control;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
312 af->uninit=uninit;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
313 af->play=play;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
314 af->mul.n=1;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
315 af->mul.d=1;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
316 af->data=calloc(1,sizeof(af_data_t));
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
317 af->setup=calloc(1,sizeof(af_volnorm_t));
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
318 if(af->data == NULL || af->setup == NULL)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
319 return AF_ERROR;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
320
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
321 ((af_volnorm_t*)af->setup)->mul = MUL_INIT;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
322 ((af_volnorm_t*)af->setup)->lastavg = MID_S16;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
323 ((af_volnorm_t*)af->setup)->idx = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
324 for (i = 0; i < NSAMPLES; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
325 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
326 ((af_volnorm_t*)af->setup)->mem[i].len = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
327 ((af_volnorm_t*)af->setup)->mem[i].avg = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
328 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
329 return AF_OK;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
330 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
331
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
332 // Description of this filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
333 af_info_t af_info_volnorm = {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
334 "Volume normalizer filter",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
335 "volnorm",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
336 "Alex Beregszaszi & Pierre Lombard",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
337 "",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
338 AF_FLAGS_NOT_REENTRANT,
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
339 open
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
340 };