Mercurial > mplayer.hg
annotate libaf/af_extrastereo.c @ 36959:97a4746e7888
Utilize item defaults given in the skin configuration as start values.
Do so for movie position, volume and balance (and hence show these
values before playback).
Add new btnValue() to retrieve the value and replace the btnModify()
calls with btnValue() calls. (The btnModify() calls will be performed
in the windows' draw handler prior to rendering anyway.)
Initialize last_balance with -1 in order to be able to initialize
balance (and volume) with the start values prior to playback (in
GUI_SET_AUDIO).
author | ib |
---|---|
date | Mon, 24 Mar 2014 10:48:55 +0000 |
parents | 2b9bc3c2933d |
children |
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 |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
32537
diff
changeset
|
29 #include "libavutil/common.h" |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
30 #include "af.h" |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
31 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
32 // Data for specific instances of this filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
33 typedef struct af_extrastereo_s |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
34 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
35 float mul; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
36 }af_extrastereo_t; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
37 |
14624 | 38 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data); |
39 static af_data_t* play_float(struct af_instance_s* af, af_data_t* data); | |
40 | |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
41 // Initialization and runtime control |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
42 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
|
43 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
44 af_extrastereo_t* s = (af_extrastereo_t*)af->setup; |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
45 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
46 switch(cmd){ |
14624 | 47 case AF_CONTROL_REINIT:{ |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
48 // Sanity check |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
49 if(!arg) return AF_ERROR; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
50 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
51 af->data->rate = ((af_data_t*)arg)->rate; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
52 af->data->nch = 2; |
14624 | 53 if (((af_data_t*)arg)->format == AF_FORMAT_FLOAT_NE) |
54 { | |
55 af->data->format = AF_FORMAT_FLOAT_NE; | |
56 af->data->bps = 4; | |
57 af->play = play_float; | |
58 }// else | |
59 { | |
60 af->data->format = AF_FORMAT_S16_NE; | |
61 af->data->bps = 2; | |
62 af->play = play_s16; | |
63 } | |
13550
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 return af_test_output(af,(af_data_t*)arg); |
14624 | 66 } |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
67 case AF_CONTROL_COMMAND_LINE:{ |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
68 float f; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
69 sscanf((char*)arg,"%f", &f); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
70 s->mul = f; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
71 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
72 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
73 case AF_CONTROL_ES_MUL | AF_CONTROL_SET: |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
74 s->mul = *(float*)arg; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
75 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
76 case AF_CONTROL_ES_MUL | AF_CONTROL_GET: |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
77 *(float*)arg = s->mul; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
78 return AF_OK; |
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 return AF_UNKNOWN; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
81 } |
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 // Deallocate memory |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
84 static void uninit(struct af_instance_s* af) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
85 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
86 free(af->data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
87 free(af->setup); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
88 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
89 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
90 // Filter data through filter |
14624 | 91 static af_data_t* play_s16(struct af_instance_s* af, af_data_t* data) |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
92 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
93 af_extrastereo_t *s = af->setup; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
94 register int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
95 int16_t *a = (int16_t*)data->audio; // Audio data |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
96 int len = data->len/2; // Number of samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
97 int avg, l, r; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
98 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
99 for (i = 0; i < len; i+=2) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
100 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
101 avg = (a[i] + a[i + 1]) / 2; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
102 |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
103 l = avg + (int)(s->mul * (a[i] - avg)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
104 r = avg + (int)(s->mul * (a[i + 1] - avg)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
105 |
36395
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
32537
diff
changeset
|
106 a[i] = av_clip_int16(l); |
2b9bc3c2933d
Remove some macros and switch to libavutil equivalents.
reimar
parents:
32537
diff
changeset
|
107 a[i + 1] = av_clip_int16(r); |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
108 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
109 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
110 return data; |
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 |
14624 | 113 static af_data_t* play_float(struct af_instance_s* af, af_data_t* data) |
114 { | |
115 af_extrastereo_t *s = af->setup; | |
116 register int i = 0; | |
117 float *a = (float*)data->audio; // Audio data | |
118 int len = data->len/4; // Number of samples | |
119 float avg, l, r; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
120 |
14624 | 121 for (i = 0; i < len; i+=2) |
122 { | |
123 avg = (a[i] + a[i + 1]) / 2; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
124 |
14624 | 125 l = avg + (s->mul * (a[i] - avg)); |
126 r = avg + (s->mul * (a[i + 1] - avg)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
127 |
14624 | 128 a[i] = af_softclip(l); |
129 a[i + 1] = af_softclip(r); | |
130 } | |
131 | |
132 return data; | |
133 } | |
134 | |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
135 // 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:
14624
diff
changeset
|
136 static int af_open(af_instance_t* af){ |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
137 af->control=control; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
138 af->uninit=uninit; |
14624 | 139 af->play=play_s16; |
24888 | 140 af->mul=1; |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
141 af->data=calloc(1,sizeof(af_data_t)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
142 af->setup=calloc(1,sizeof(af_extrastereo_t)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
143 if(af->data == NULL || af->setup == NULL) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
144 return AF_ERROR; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
145 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
146 ((af_extrastereo_t*)af->setup)->mul = 2.5; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
147 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
148 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
149 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
150 // Description of this filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
151 af_info_t af_info_extrastereo = { |
31478 | 152 "Increase difference between audio channels", |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
153 "extrastereo", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
154 "Alex Beregszaszi & Pierre Lombard", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
155 "", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
156 AF_FLAGS_NOT_REENTRANT, |
22746
fd6f824ef894
Rename open to af_open so as not to conflict with a previous header definition.
diego
parents:
14624
diff
changeset
|
157 af_open |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
158 }; |