Mercurial > mplayer.hg
annotate libaf/af_volnorm.c @ 35684:7801d585b06c
Support fourcc ZMP4.
Based on a patch by Luca Barbato.
author | cehoyos |
---|---|
date | Fri, 18 Jan 2013 09:20:23 +0000 |
parents | 8fa2f43cb760 |
children | 1dca5ff3d3c6 |
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 | 60 #define DEFAULT_TARGET 0.25 |
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 | 75 // "Ideal" level |
76 float mid_s16; | |
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 | 93 if(((af_data_t*)arg)->format == (AF_FORMAT_S16_NE)){ |
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 | 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 | 102 int i = 0; |
103 float target = DEFAULT_TARGET; | |
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 | 108 s->mid_s16 = ((float)SHRT_MAX) * target; |
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 free(af->data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
120 free(af->setup); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
121 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
122 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
123 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
|
124 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
125 register int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
126 int16_t *data = (int16_t*)c->audio; // Audio data |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
127 int len = c->len/2; // Number of samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
128 float curavg = 0.0, newavg, neededmul; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
129 int tmp; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
130 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
131 for (i = 0; i < len; i++) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
132 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
133 tmp = data[i]; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
134 curavg += tmp * tmp; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
135 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
136 curavg = sqrt(curavg / (float) len); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
137 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
138 // Evaluate an adequate 'mul' coefficient based on previous state, current |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
139 // samples level, etc |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
140 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
141 if (curavg > SIL_S16) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
142 { |
16971 | 143 neededmul = s->mid_s16 / (curavg * s->mul); |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
144 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
145 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
146 // clamp the mul coefficient |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
147 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
148 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
149 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
150 // Scale & clamp the samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
151 for (i = 0; i < len; i++) |
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 tmp = s->mul * data[i]; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
154 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
155 data[i] = tmp; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
156 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
157 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
158 // Evaulation of newavg (not 100% accurate because of values clamping) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
159 newavg = s->mul * curavg; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
160 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
161 // Stores computed values for future smoothing |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
162 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
|
163 } |
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 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
|
166 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
167 register int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
168 float *data = (float*)c->audio; // Audio data |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
169 int len = c->len/4; // Number of samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
170 float curavg = 0.0, newavg, neededmul, tmp; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
171 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
172 for (i = 0; i < len; i++) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
173 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
174 tmp = data[i]; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
175 curavg += tmp * tmp; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
176 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
177 curavg = sqrt(curavg / (float) len); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
178 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
179 // Evaluate an adequate 'mul' coefficient based on previous state, current |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
180 // samples level, etc |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
181 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
182 if (curavg > SIL_FLOAT) // FIXME |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
183 { |
16971 | 184 neededmul = s->mid_float / (curavg * s->mul); |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
185 s->mul = (1.0 - SMOOTH_MUL) * s->mul + SMOOTH_MUL * neededmul; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
186 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
187 // clamp the mul coefficient |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
188 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
189 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
190 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
191 // Scale & clamp the samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
192 for (i = 0; i < len; i++) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
193 data[i] *= s->mul; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
194 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
195 // Evaulation of newavg (not 100% accurate because of values clamping) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
196 newavg = s->mul * curavg; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
197 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
198 // Stores computed values for future smoothing |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
199 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
|
200 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
201 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
202 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
|
203 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
204 register int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
205 int16_t *data = (int16_t*)c->audio; // Audio data |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
206 int len = c->len/2; // Number of samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
207 float curavg = 0.0, newavg, avg = 0.0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
208 int tmp, totallen = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
209 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
210 for (i = 0; i < len; i++) |
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 tmp = data[i]; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
213 curavg += tmp * tmp; |
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 curavg = sqrt(curavg / (float) len); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
216 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
217 // Evaluate an adequate 'mul' coefficient based on previous state, current |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
218 // samples level, etc |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
219 for (i = 0; i < NSAMPLES; i++) |
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 avg += s->mem[i].avg * (float)s->mem[i].len; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
222 totallen += s->mem[i].len; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
223 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
224 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
225 if (totallen > MIN_SAMPLE_SIZE) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
226 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
227 avg /= (float)totallen; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
228 if (avg >= SIL_S16) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
229 { |
16971 | 230 s->mul = s->mid_s16 / avg; |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
231 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
232 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
233 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
234 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
235 // Scale & clamp the samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
236 for (i = 0; i < len; i++) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
237 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
238 tmp = s->mul * data[i]; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
239 tmp = clamp(tmp, SHRT_MIN, SHRT_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
240 data[i] = tmp; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
241 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
242 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
243 // Evaulation of newavg (not 100% accurate because of values clamping) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
244 newavg = s->mul * curavg; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
245 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
246 // Stores computed values for future smoothing |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
247 s->mem[s->idx].len = len; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
248 s->mem[s->idx].avg = newavg; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
249 s->idx = (s->idx + 1) % NSAMPLES; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
250 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
251 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
252 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
|
253 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
254 register int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
255 float *data = (float*)c->audio; // Audio data |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
256 int len = c->len/4; // Number of samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
257 float curavg = 0.0, newavg, avg = 0.0, tmp; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
258 int totallen = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
259 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
260 for (i = 0; i < len; i++) |
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 tmp = data[i]; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
263 curavg += tmp * tmp; |
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 curavg = sqrt(curavg / (float) len); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
266 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
267 // Evaluate an adequate 'mul' coefficient based on previous state, current |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
268 // samples level, etc |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
269 for (i = 0; i < NSAMPLES; i++) |
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 avg += s->mem[i].avg * (float)s->mem[i].len; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
272 totallen += s->mem[i].len; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
273 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
274 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
275 if (totallen > MIN_SAMPLE_SIZE) |
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 avg /= (float)totallen; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
278 if (avg >= SIL_FLOAT) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
279 { |
16971 | 280 s->mul = s->mid_float / avg; |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
281 s->mul = clamp(s->mul, MUL_MIN, MUL_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
282 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
283 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
284 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
285 // Scale & clamp the samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
286 for (i = 0; i < len; i++) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
287 data[i] *= s->mul; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
288 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
289 // Evaulation of newavg (not 100% accurate because of values clamping) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
290 newavg = s->mul * curavg; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
291 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
292 // Stores computed values for future smoothing |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
293 s->mem[s->idx].len = len; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
294 s->mem[s->idx].avg = newavg; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
295 s->idx = (s->idx + 1) % NSAMPLES; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
296 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
297 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
298 // Filter data through filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
299 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
|
300 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
301 af_volnorm_t *s = af->setup; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
302 |
14245 | 303 if(af->data->format == (AF_FORMAT_S16_NE)) |
13550
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 if (s->method) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
306 method2_int16(s, data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
307 else |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
308 method1_int16(s, data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
309 } |
14245 | 310 else if(af->data->format == (AF_FORMAT_FLOAT_NE)) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
311 { |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
312 if (s->method) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
313 method2_float(s, data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
314 else |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
315 method1_float(s, data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
316 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
317 return 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 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
320 // 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
|
321 static int af_open(af_instance_t* af){ |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
322 int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
323 af->control=control; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
324 af->uninit=uninit; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
325 af->play=play; |
24888 | 326 af->mul=1; |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
327 af->data=calloc(1,sizeof(af_data_t)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
328 af->setup=calloc(1,sizeof(af_volnorm_t)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
329 if(af->data == NULL || af->setup == NULL) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
330 return AF_ERROR; |
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 ((af_volnorm_t*)af->setup)->mul = MUL_INIT; |
16971 | 333 ((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
|
334 ((af_volnorm_t*)af->setup)->idx = 0; |
16971 | 335 ((af_volnorm_t*)af->setup)->mid_s16 = ((float)SHRT_MAX) * DEFAULT_TARGET; |
336 ((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
|
337 for (i = 0; i < NSAMPLES; i++) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
338 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
339 ((af_volnorm_t*)af->setup)->mem[i].len = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
340 ((af_volnorm_t*)af->setup)->mem[i].avg = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
341 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
342 return AF_OK; |
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 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
345 // Description of this filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
346 af_info_t af_info_volnorm = { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
347 "Volume normalizer filter", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
348 "volnorm", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
349 "Alex Beregszaszi & Pierre Lombard", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
350 "", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
351 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
|
352 af_open |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
353 }; |