Mercurial > mplayer.hg
annotate libaf/af_extrastereo.c @ 13981:3e82594ec231
correct encoding
author | diego |
---|---|
date | Fri, 19 Nov 2004 18:34:33 +0000 |
parents | 14090f7300a8 |
children | 3c56b18bbb0c |
rev | line source |
---|---|
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
1 /*============================================================================= |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
2 // |
13602
14090f7300a8
The full name of the GPL is GNU General Public License.
diego
parents:
13550
diff
changeset
|
3 // This software has been released under the terms of the GNU General Public |
13550
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
4 // license. See http://www.gnu.org/copyleft/gpl.html for details. |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
5 // |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
6 // Copyright 2004 Alex Beregszaszi & Pierre Lombard |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
7 // |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
8 //============================================================================= |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
9 */ |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
10 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
11 #include <stdio.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
12 #include <stdlib.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
13 #include <string.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
14 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
15 #include <unistd.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
16 #include <inttypes.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
17 #include <math.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
18 #include <limits.h> |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
19 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
20 #include "af.h" |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
21 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
22 // Data for specific instances of this filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
23 typedef struct af_extrastereo_s |
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 float mul; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
26 }af_extrastereo_t; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
27 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
28 // Initialization and runtime control |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
29 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
|
30 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
31 af_extrastereo_t* s = (af_extrastereo_t*)af->setup; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
32 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
33 switch(cmd){ |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
34 case AF_CONTROL_REINIT: |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
35 // Sanity check |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
36 if(!arg) return AF_ERROR; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
37 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
38 if(((af_data_t*)arg)->format != (AF_FORMAT_SI | AF_FORMAT_NE) || |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
39 (((af_data_t*)arg)->nch != 2)) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
40 return AF_ERROR; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
41 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
42 af->data->rate = ((af_data_t*)arg)->rate; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
43 af->data->nch = 2; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
44 af->data->format = AF_FORMAT_SI | AF_FORMAT_NE; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
45 af->data->bps = 2; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
46 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
47 return af_test_output(af,(af_data_t*)arg); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
48 case AF_CONTROL_COMMAND_LINE:{ |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
49 float f; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
50 sscanf((char*)arg,"%f", &f); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
51 s->mul = f; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
52 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
53 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
54 case AF_CONTROL_ES_MUL | AF_CONTROL_SET: |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
55 s->mul = *(float*)arg; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
56 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
57 case AF_CONTROL_ES_MUL | AF_CONTROL_GET: |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
58 *(float*)arg = s->mul; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
59 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
60 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
61 return AF_UNKNOWN; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
62 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
63 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
64 // Deallocate memory |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
65 static void uninit(struct af_instance_s* af) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
66 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
67 if(af->data) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
68 free(af->data); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
69 if(af->setup) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
70 free(af->setup); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
71 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
72 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
73 // Filter data through filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
74 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
|
75 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
76 af_extrastereo_t *s = af->setup; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
77 register int i = 0; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
78 int16_t *a = (int16_t*)data->audio; // Audio data |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
79 int len = data->len/2; // Number of samples |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
80 int avg, l, r; |
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 for (i = 0; i < len; i+=2) |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
83 { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
84 avg = (a[i] + a[i + 1]) / 2; |
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 l = avg + (int)(s->mul * (a[i] - avg)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
87 r = avg + (int)(s->mul * (a[i + 1] - avg)); |
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 a[i] = clamp(l, SHRT_MIN, SHRT_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
90 a[i + 1] = clamp(r, SHRT_MIN, SHRT_MAX); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
91 } |
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 return data; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
94 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
95 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
96 // Allocate memory and set function pointers |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
97 static int open(af_instance_t* af){ |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
98 af->control=control; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
99 af->uninit=uninit; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
100 af->play=play; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
101 af->mul.n=1; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
102 af->mul.d=1; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
103 af->data=calloc(1,sizeof(af_data_t)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
104 af->setup=calloc(1,sizeof(af_extrastereo_t)); |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
105 if(af->data == NULL || af->setup == NULL) |
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 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
108 ((af_extrastereo_t*)af->setup)->mul = 2.5; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
109 return AF_OK; |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
110 } |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
111 |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
112 // Description of this filter |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
113 af_info_t af_info_extrastereo = { |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
114 "Extra stereo", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
115 "extrastereo", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
116 "Alex Beregszaszi & Pierre Lombard", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
117 "", |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
118 AF_FLAGS_NOT_REENTRANT, |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
119 open |
81e62cbe57d9
reimplementation of the pl_extrastereo and pl_volnorm plugins
alex
parents:
diff
changeset
|
120 }; |