annotate libaf/af_volnorm.c @ 29997:997ae534ebfe

Add missing #includes to fix a bunch of 'implicit declaration of..' warnings. patch by Peter Hjalmarsson, xake rymdraket net
author diego
date Mon, 14 Dec 2009 11:54:49 +0000
parents 0f1b5b68af32
children 8fa2f43cb760
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28229
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
1 /*
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
2 * Copyright (C) 2004 Alex Beregszaszi & Pierre Lombard
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
3 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
4 * This file is part of MPlayer.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
5 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
7 * it under the terms of the GNU General Public License as published by
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
9 * (at your option) any later version.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
10 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
14 * GNU General Public License for more details.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
15 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
16 * You should have received a copy of the GNU General Public License along
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
19 */
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
20
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
21 #include <stdio.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
22 #include <stdlib.h>
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
23 #include <string.h>
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
24
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
25 #include <inttypes.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
26 #include <math.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
27 #include <limits.h>
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
28
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
29 #include "af.h"
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 // Methods:
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
32 // 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
33 // 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
34 // on past samples)
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 // Size of the memory array
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
37 // 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
38 #define NSAMPLES 128
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
39
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
40 // 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
41 // 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
42 // 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
43 #define MIN_SAMPLE_SIZE 32000
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 // mul is the value by which the samples are scaled
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
46 // and has to be in [MUL_MIN, MUL_MAX]
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
47 #define MUL_INIT 1.0
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
48 #define MUL_MIN 0.1
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
49 #define MUL_MAX 5.0
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
50
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
51 // Silence level
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
52 // FIXME: should be relative to the level of the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
53 #define SIL_S16 (SHRT_MAX * 0.01)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
54 #define SIL_FLOAT (INT_MAX * 0.01) // FIXME
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
55
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
56 // smooth must be in ]0.0, 1.0[
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
57 #define SMOOTH_MUL 0.06
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
58 #define SMOOTH_LASTAVG 0.06
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
59
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
60 #define DEFAULT_TARGET 0.25
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
61
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
62 // Data for specific instances of this filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
63 typedef struct af_volume_s
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
64 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
65 int method; // method used
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
66 float mul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
67 // method 1
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
68 float lastavg; // history value of the filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
69 // method 2
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
70 int idx;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
71 struct {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
72 float avg; // average level of the sample
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
73 int len; // sample size (weight)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
74 } mem[NSAMPLES];
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
75 // "Ideal" level
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
76 float mid_s16;
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
77 float mid_float;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
78 }af_volnorm_t;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
79
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
80 // Initialization and runtime control
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
81 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
82 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
83 af_volnorm_t* s = (af_volnorm_t*)af->setup;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
84
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
85 switch(cmd){
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
86 case AF_CONTROL_REINIT:
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
87 // Sanity check
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
88 if(!arg) return AF_ERROR;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
89
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
90 af->data->rate = ((af_data_t*)arg)->rate;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
91 af->data->nch = ((af_data_t*)arg)->nch;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
92
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
93 if(((af_data_t*)arg)->format == (AF_FORMAT_S16_NE)){
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
94 af->data->format = AF_FORMAT_S16_NE;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
95 af->data->bps = 2;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
96 }else{
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
97 af->data->format = AF_FORMAT_FLOAT_NE;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
98 af->data->bps = 4;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
99 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
100 return af_test_output(af,(af_data_t*)arg);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
101 case AF_CONTROL_COMMAND_LINE:{
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
102 int i = 0;
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
103 float target = DEFAULT_TARGET;
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
104 sscanf((char*)arg,"%d:%f", &i, &target);
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
105 if (i != 1 && i != 2)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
106 return AF_ERROR;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
107 s->method = i-1;
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
108 s->mid_s16 = ((float)SHRT_MAX) * target;
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
109 s->mid_float = ((float)INT_MAX) * target;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
110 return AF_OK;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
111 }
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 return AF_UNKNOWN;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
114 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
115
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
116 // Deallocate memory
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
117 static void uninit(struct af_instance_s* af)
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 if(af->data)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
120 free(af->data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
121 if(af->setup)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
122 free(af->setup);
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
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
125 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
126 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
127 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
128 int16_t *data = (int16_t*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
129 int len = c->len/2; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
130 float curavg = 0.0, newavg, neededmul;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
131 int tmp;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
132
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
133 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
134 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
135 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
136 curavg += tmp * tmp;
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 curavg = sqrt(curavg / (float) len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
139
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
140 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
141 // samples level, etc
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
142
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
143 if (curavg > SIL_S16)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
144 {
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
145 neededmul = s->mid_s16 / (curavg * s->mul);
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
146 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
147
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
148 // clamp the mul coefficient
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
149 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
150 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
151
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
152 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
153 for (i = 0; i < len; i++)
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 tmp = s->mul * data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
156 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
157 data[i] = tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
158 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
159
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
160 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
161 newavg = s->mul * curavg;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
162
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
163 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
164 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
165 }
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 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
168 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
169 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
170 float *data = (float*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
171 int len = c->len/4; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
172 float curavg = 0.0, newavg, neededmul, tmp;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
173
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
174 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
175 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
176 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
177 curavg += tmp * tmp;
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 curavg = sqrt(curavg / (float) len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
180
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
181 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
182 // samples level, etc
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
183
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
184 if (curavg > SIL_FLOAT) // FIXME
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
185 {
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
186 neededmul = s->mid_float / (curavg * s->mul);
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
187 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
188
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
189 // clamp the mul coefficient
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
190 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
191 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
192
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
193 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
194 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
195 data[i] *= s->mul;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
196
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
197 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
198 newavg = s->mul * curavg;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
199
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
200 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
201 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
202 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
203
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
204 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
205 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
206 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
207 int16_t *data = (int16_t*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
208 int len = c->len/2; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
209 float curavg = 0.0, newavg, avg = 0.0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
210 int tmp, totallen = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
211
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
212 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
213 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
214 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
215 curavg += tmp * tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
216 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
217 curavg = sqrt(curavg / (float) len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
218
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
219 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
220 // samples level, etc
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
221 for (i = 0; i < NSAMPLES; i++)
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 avg += s->mem[i].avg * (float)s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
224 totallen += s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
225 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
226
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
227 if (totallen > MIN_SAMPLE_SIZE)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
228 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
229 avg /= (float)totallen;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
230 if (avg >= SIL_S16)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
231 {
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
232 s->mul = s->mid_s16 / avg;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
233 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
234 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
235 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
236
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
237 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
238 for (i = 0; i < len; i++)
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 tmp = s->mul * data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
241 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
242 data[i] = tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
243 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
244
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
245 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
246 newavg = s->mul * curavg;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
247
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
248 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
249 s->mem[s->idx].len = len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
250 s->mem[s->idx].avg = newavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
251 s->idx = (s->idx + 1) % NSAMPLES;
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
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
254 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
255 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
256 register int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
257 float *data = (float*)c->audio; // Audio data
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
258 int len = c->len/4; // Number of samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
259 float curavg = 0.0, newavg, avg = 0.0, tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
260 int totallen = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
261
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
262 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
263 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
264 tmp = data[i];
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
265 curavg += tmp * tmp;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
266 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
267 curavg = sqrt(curavg / (float) len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
268
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
269 // Evaluate an adequate 'mul' coefficient based on previous state, current
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
270 // samples level, etc
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
271 for (i = 0; i < NSAMPLES; i++)
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 avg += s->mem[i].avg * (float)s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
274 totallen += s->mem[i].len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
275 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
276
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
277 if (totallen > MIN_SAMPLE_SIZE)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
278 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
279 avg /= (float)totallen;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
280 if (avg >= SIL_FLOAT)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
281 {
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
282 s->mul = s->mid_float / avg;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
283 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX);
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 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
286
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
287 // Scale & clamp the samples
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
288 for (i = 0; i < len; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
289 data[i] *= s->mul;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
290
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
291 // Evaulation of newavg (not 100% accurate because of values clamping)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
292 newavg = s->mul * curavg;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
293
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
294 // Stores computed values for future smoothing
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
295 s->mem[s->idx].len = len;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
296 s->mem[s->idx].avg = newavg;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
297 s->idx = (s->idx + 1) % NSAMPLES;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
298 }
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 // Filter data through filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
301 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
302 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
303 af_volnorm_t *s = af->setup;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
304
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
305 if(af->data->format == (AF_FORMAT_S16_NE))
13550
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 if (s->method)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
308 method2_int16(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
309 else
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
310 method1_int16(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
311 }
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14213
diff changeset
312 else if(af->data->format == (AF_FORMAT_FLOAT_NE))
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 28229
diff changeset
313 {
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
314 if (s->method)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
315 method2_float(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
316 else
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
317 method1_float(s, data);
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
318 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
319 return data;
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
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
322 // Allocate memory and set function pointers
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 16971
diff changeset
323 static int af_open(af_instance_t* af){
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
324 int i = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
325 af->control=control;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
326 af->uninit=uninit;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
327 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22748
diff changeset
328 af->mul=1;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
329 af->data=calloc(1,sizeof(af_data_t));
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
330 af->setup=calloc(1,sizeof(af_volnorm_t));
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
331 if(af->data == NULL || af->setup == NULL)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
332 return AF_ERROR;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
333
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
334 ((af_volnorm_t*)af->setup)->mul = MUL_INIT;
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
335 ((af_volnorm_t*)af->setup)->lastavg = ((float)SHRT_MAX) * DEFAULT_TARGET;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
336 ((af_volnorm_t*)af->setup)->idx = 0;
16971
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
337 ((af_volnorm_t*)af->setup)->mid_s16 = ((float)SHRT_MAX) * DEFAULT_TARGET;
9352446d4fa8 Adds a target parameter to the volnorm filter.
joey
parents: 14245
diff changeset
338 ((af_volnorm_t*)af->setup)->mid_float = ((float)INT_MAX) * DEFAULT_TARGET;
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
339 for (i = 0; i < NSAMPLES; i++)
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
340 {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
341 ((af_volnorm_t*)af->setup)->mem[i].len = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
342 ((af_volnorm_t*)af->setup)->mem[i].avg = 0;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
343 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
344 return AF_OK;
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
345 }
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
346
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
347 // Description of this filter
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
348 af_info_t af_info_volnorm = {
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
349 "Volume normalizer filter",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
350 "volnorm",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
351 "Alex Beregszaszi & Pierre Lombard",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
352 "",
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
353 AF_FLAGS_NOT_REENTRANT,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 16971
diff changeset
354 af_open
13550
81e62cbe57d9 reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff changeset
355 };