annotate libaf/af_volume.c @ 37195:ac6c37d85d65 default tip

configure: Fix initialization of variable def_local_aligned_32 It contiained the #define of HAVE_LOCAL_ALIGNED_16 instead of HAVE_LOCAL_ALIGNED_32.
author al
date Sun, 28 Sep 2014 18:38:41 +0000
parents 07e9ebd91b98
children
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)2002 Anders Johansson ajh@atri.curtin.edu.au
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 */
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
20
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
21 /* This audio filter changes the volume of the sound, and can be used
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
22 when the mixer doesn't support the PCM channel. It can handle
29826
4eae69f3f4f4 Add support for 8 channel audio.
tack
parents: 29263
diff changeset
23 between 1 and AF_NCH channels. The volume can be adjusted between -60dB
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
24 to +20dB and is set on a per channels basis. The is accessed through
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
25 AF_CONTROL_VOLUME_LEVEL.
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
26
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
27 The filter has support for soft-clipping, it is enabled by
36396
49587a84cb91 Remove unused code that costs a good bit of performance.
reimar
parents: 36395
diff changeset
28 AF_CONTROL_VOLUME_SOFTCLIPP.
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
29 */
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
30
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
31 #include <stdio.h>
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
32 #include <stdlib.h>
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
33 #include <string.h>
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
34
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
35 #include <inttypes.h>
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
36 #include <math.h>
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
37 #include <limits.h>
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
38
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 36394
diff changeset
39 #include "libavutil/common.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 32537
diff changeset
40 #include "mp_msg.h"
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
41 #include "af.h"
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
42
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
43 // Data for specific instances of this filter
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
44 typedef struct af_volume_s
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
45 {
36401
abdc52a1ab2c af_volume: Avoid pointlessly calculating the maximum volume.
reimar
parents: 36397
diff changeset
46 float max; // Max Power level [dB]
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
47 float level[AF_NCH]; // Gain level for each channel
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
48 int soft; // Enable/disable soft clipping
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
49 int fast; // Use fix-point volume control
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
50 }af_volume_t;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
51
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
52 // Initialization and runtime control
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
53 static int control(struct af_instance_s* af, int cmd, void* arg)
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
54 {
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
55 af_volume_t* s = (af_volume_t*)af->setup;
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
56
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
57 switch(cmd){
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
58 case AF_CONTROL_REINIT:
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
59 // Sanity check
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
60 if(!arg) return AF_ERROR;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
61
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
62 af->data->rate = ((af_data_t*)arg)->rate;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
63 af->data->nch = ((af_data_t*)arg)->nch;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
64
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14068
diff changeset
65 if(s->fast && (((af_data_t*)arg)->format != (AF_FORMAT_FLOAT_NE))){
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14068
diff changeset
66 af->data->format = AF_FORMAT_S16_NE;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
67 af->data->bps = 2;
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
68 }
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
69 else{
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14068
diff changeset
70 af->data->format = AF_FORMAT_FLOAT_NE;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
71 af->data->bps = 4;
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
72 }
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
73 return af_test_output(af,(af_data_t*)arg);
7993
ea0680d87f3f Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents: 7974
diff changeset
74 case AF_CONTROL_COMMAND_LINE:{
14068
f1372a7d9ee9 very old 10l, discussed a long time ago but never fixed (default should be same vol, not -10 dB)
rfelker
parents: 13602
diff changeset
75 float v=0.0;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
76 float vol[AF_NCH];
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
77 int i;
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
78 sscanf((char*)arg,"%f:%i", &v, &s->soft);
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
79 for(i=0;i<AF_NCH;i++) vol[i]=v;
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
80 return control(af,AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET, vol);
7993
ea0680d87f3f Changing the behavour of the commandline parameter -af to conform with -vop. Adding new commanline parameter -af-adv for advanced af options. Adding changes to volume control to support commandline parameters.
anders
parents: 7974
diff changeset
81 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
82 case AF_CONTROL_POST_CREATE:
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
83 s->fast = ((((af_cfg_t*)arg)->force & AF_INIT_FORMAT_MASK) ==
8868
398e3fb7c103 10l bug for float conversion control + feature fix in volume control
anders
parents: 8867
diff changeset
84 AF_INIT_FLOAT) ? 0 : 1;
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
85 return AF_OK;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
86 case AF_CONTROL_VOLUME_SOFTCLIP | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
87 s->soft = *(int*)arg;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
88 return AF_OK;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
89 case AF_CONTROL_VOLUME_SOFTCLIP | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
90 *(int*)arg = s->soft;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
91 return AF_OK;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
92 case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
93 return af_from_dB(AF_NCH,(float*)arg,s->level,20.0,-200.0,60.0);
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
94 case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
95 return af_to_dB(AF_NCH,s->level,(float*)arg,20.0);
36401
abdc52a1ab2c af_volume: Avoid pointlessly calculating the maximum volume.
reimar
parents: 36397
diff changeset
96 case AF_CONTROL_PRE_DESTROY:
8868
398e3fb7c103 10l bug for float conversion control + feature fix in volume control
anders
parents: 8867
diff changeset
97 if(!s->fast){
36401
abdc52a1ab2c af_volume: Avoid pointlessly calculating the maximum volume.
reimar
parents: 36397
diff changeset
98 float m = s->max;
12641
61f3fce1e933 remove the latest use of log10 in favor of the better af_to_dB helper function, patch by Reimar Doffinger
alex
parents: 9043
diff changeset
99 af_to_dB(1, &m, &m, 10.0);
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28229
diff changeset
100 mp_msg(MSGT_AFILTER, MSGL_INFO, "[volume] The maximum volume was %0.2fdB \n", m);
8868
398e3fb7c103 10l bug for float conversion control + feature fix in volume control
anders
parents: 8867
diff changeset
101 }
8186
b56fd4b1738d Printing of max volume on exit
anders
parents: 8167
diff changeset
102 return AF_OK;
b56fd4b1738d Printing of max volume on exit
anders
parents: 8167
diff changeset
103 }
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
104 return AF_UNKNOWN;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
105 }
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
106
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
107 // Deallocate memory
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
108 static void uninit(struct af_instance_s* af)
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
109 {
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
110 free(af->data);
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
111 free(af->setup);
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
112 }
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
113
36402
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
114 static av_always_inline void s16_inner_loop(int16_t *data, int len, int offset, int step, float level)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
115 {
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
116 int i;
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
117 register int vol = (int)(255.0 * level);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
118 for (i = offset; i < len; i += step)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
119 {
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
120 register int x = (data[i] * vol) >> 8;
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
121 data[i] = av_clip_int16(x);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
122 }
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
123 }
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
124
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
125 static av_always_inline void float_inner_loop(float *data, int len, int offset, int step, float level, int softclip)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
126 {
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
127 int i;
36403
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
128 #if HAVE_NEON
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
129 if (offset == 0 && step == 1 && !softclip && len >= 8)
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
130 {
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
131 __asm__(
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
132 "vmov.32 d2[0], %2\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
133 "vdup.32 q8, %3\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
134 "vneg.f32 q9, q8\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
135 "0:\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
136 "vld1.32 {q0}, [%0]\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
137 "vmul.f32 q0, q0, d2[0]\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
138 "cmp %0, %1\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
139 "vmin.f32 q0, q0, q8\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
140 "vmax.f32 q0, q0, q9\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
141 "vst1.32 {q0}, [%0]!\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
142 "blo 0b\n\t"
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
143 : "+&r"(data)
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
144 : "r"(data + len - 7), "r"(level), "r"(0x3f800000)
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
145 : "cc", "q0", "d2", "q8", "q9", "memory");
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
146 len &= 3;
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
147 }
07e9ebd91b98 af_volume: add NEON optimization for common float case.
reimar
parents: 36402
diff changeset
148 #endif
36402
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
149 for (i = offset; i < len; i += step)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
150 {
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
151 register float x = data[i];
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
152 // Set volume
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
153 x *= level;
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
154 /* Soft clipping, the sound of a dream, thanks to Jon Wattes
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
155 post to Musicdsp.org */
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
156 if (softclip)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
157 x = af_softclip(x);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
158 // Hard clipping
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
159 else
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
160 x = av_clipf(x,-1.0,1.0);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
161 data[i] = x;
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
162 }
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
163 }
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
164
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
165 // Filter data through filter
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
166 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
167 {
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
168 af_data_t* c = data; // Current working data
36394
2f815fdd521c Remove pointless cast.
reimar
parents: 34174
diff changeset
169 af_volume_t* s = af->setup; // Setup for this instance
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
170 int ch = 0; // Channel counter
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
171 register int nch = c->nch; // Number of channels
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
172 register int i = 0;
36402
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
173 int same_vol = 1;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
174
36402
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
175 for (ch = 1; ch < nch; ch++)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
176 {
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
177 same_vol &= s->level[ch] == s->level[ch - 1];
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
178 }
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
179 // Basic operation volume control only (used on slow machines)
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 14068
diff changeset
180 if(af->data->format == (AF_FORMAT_S16_NE)){
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
181 int16_t* a = (int16_t*)c->audio; // Audio data
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
182 int len = c->len/2; // Number of samples
36402
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
183 if (same_vol)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
184 s16_inner_loop(a, len, 0, 1, s->level[0]);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
185 else for (ch = 0; ch < nch; ch++)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
186 s16_inner_loop(a, len, ch, nch, s->level[ch]);
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
187 }
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
188 // Machine is fast and data is floating point
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
189 else if(af->data->format == (AF_FORMAT_FLOAT_NE)){
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
190 float* a = (float*)c->audio; // Audio data
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
191 int len = c->len/4; // Number of samples
36401
abdc52a1ab2c af_volume: Avoid pointlessly calculating the maximum volume.
reimar
parents: 36397
diff changeset
192 for (i = 0; !s->fast && i < len; i++)
abdc52a1ab2c af_volume: Avoid pointlessly calculating the maximum volume.
reimar
parents: 36397
diff changeset
193 // Check maximum power value
abdc52a1ab2c af_volume: Avoid pointlessly calculating the maximum volume.
reimar
parents: 36397
diff changeset
194 s->max = FFMAX(s->max, a[i] * a[i]);
36402
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
195 if (same_vol && s->soft)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
196 float_inner_loop(a, len, 0, 1, s->level[0], 1);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
197 else if (same_vol)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
198 float_inner_loop(a, len, 0, 1, s->level[0], 0);
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
199 else for (ch = 0; ch < nch; ch++)
2c9356ac0d01 af_volume: optimize for common case where all channels
reimar
parents: 36401
diff changeset
200 float_inner_loop(a, len, ch, nch, s->level[ch], s->soft);
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
201 }
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
202 return c;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
203 }
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
204
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
205 // 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: 14623
diff changeset
206 static int af_open(af_instance_t* af){
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
207 int i = 0;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
208 af->control=control;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
209 af->uninit=uninit;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
210 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22748
diff changeset
211 af->mul=1;
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
212 af->data=calloc(1,sizeof(af_data_t));
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
213 af->setup=calloc(1,sizeof(af_volume_t));
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
214 if(af->data == NULL || af->setup == NULL)
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
215 return AF_ERROR;
9043
1d75a7ecf3b8 Changing initial volume level to 0dB after loud intensive complaints
anders
parents: 8868
diff changeset
216 // Enable volume control and set initial volume to 0dB.
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
217 for(i=0;i<AF_NCH;i++){
9043
1d75a7ecf3b8 Changing initial volume level to 0dB after loud intensive complaints
anders
parents: 8868
diff changeset
218 ((af_volume_t*)af->setup)->level[i] = 1.0;
8607
d6f40a06867b Changes includes:
anders
parents: 8186
diff changeset
219 }
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
220 return AF_OK;
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
221 }
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
222
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
223 // Description of this filter
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
224 af_info_t af_info_volume = {
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
225 "Volume control audio filter",
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
226 "volume",
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
227 "Anders",
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
228 "",
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
229 AF_FLAGS_NOT_REENTRANT,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 14623
diff changeset
230 af_open
7745
1d3a3dc1f488 Adding volume control and moving control() call parameters to a seperate file
anders
parents:
diff changeset
231 };