annotate libaf/af_stats.c @ 36190:153031444853

Remove unused variable.
author ib
date Sun, 26 May 2013 12:40:44 +0000
parents a93891202051
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
1 /*
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
2 * Copyright (C) 2009 Nicolas George <nicolas.george@normalesup.org>
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
3 *
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
4 * This file is part of MPlayer.
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
5 *
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
9 * (at your option) any later version.
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
10 *
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
14 * GNU General Public License for more details.
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
15 *
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
19 */
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
20
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
21 #include <stdio.h>
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
22 #include <stdlib.h>
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
23 #include <inttypes.h>
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
24 #include <math.h>
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
25
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 28663
diff changeset
26 #include "mp_msg.h"
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
27 #include "af.h"
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
28
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
29 #define MAX_DB 80
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
30 #define MIN_VAL 1E-8
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
31
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
32 struct af_stats {
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
33 long long n_samples;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
34 double tsquare;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
35 int max;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
36 long long histogram[65536];
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
37 };
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
38
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
39 static inline int logdb(double v)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
40 {
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
41 if (v > 1)
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
42 return 0;
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
43 if (v <= MIN_VAL)
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
44 return MAX_DB - 1;
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
45 return log(v) / -0.23025850929940456840179914546843642076;
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
46 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
47
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
48 static int stats_init(af_instance_t *af, struct af_stats *s, af_data_t *data)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
49 {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
50 int i;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
51
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
52 if (!data)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
53 return AF_ERROR;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
54 *(af->data) = *data;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
55 af->data->format = AF_FORMAT_S16_NE;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
56 af->data->bps = 2;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
57 s->n_samples = 0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
58 s->tsquare = 0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
59 s->max = 0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
60 for (i = 0; i < 65536; i++)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
61 s->histogram[i] = 0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
62 return af_test_output(af, data);
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
63 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
64
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
65 static void stats_print(struct af_stats *s)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
66 {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
67 int i;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
68 long long sum;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
69 float v;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
70 long long h[MAX_DB];
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
71
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
72 s->tsquare /= 32768 * 32768;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
73 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: n_samples: %lld\n", s->n_samples);
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
74 if (s->n_samples == 0)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
75 return;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
76 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: mean_volume: -%d dB\n",
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
77 logdb(s->tsquare / s->n_samples));
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
78 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: max_volume: -%d dB\n",
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
79 logdb(s->max / (32768.0 * 32768.0)));
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
80 for (i = 0; i < MAX_DB; i++)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
81 h[i] = 0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
82 for (i = 0; i < 65536; i++) {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
83 v = (i - 32768) / 32768.0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
84 h[logdb(v * v)] += s->histogram[i];
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
85 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
86 for (i = 0; i < MAX_DB; i++)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
87 if (h[i] != 0)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
88 break;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
89 sum = 0;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
90 for (; i < MAX_DB; i++) {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
91 sum += h[i];
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
92 mp_msg(MSGT_AFILTER, MSGL_INFO, "stats: histogram_%ddb: %lld\n",
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
93 i, h[i]);
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
94 if (sum > s->n_samples / 1000)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
95 break;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
96 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
97 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
98
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
99 static int control(struct af_instance_s *af, int cmd, void *arg)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
100 {
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
101 struct af_stats *s = af->setup;
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
102
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
103 switch(cmd) {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
104 case AF_CONTROL_REINIT:
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
105 return stats_init(af, s, arg);
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
106
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
107 case AF_CONTROL_PRE_DESTROY:
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
108 stats_print(s);
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
109 return AF_OK;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
110 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
111 return AF_UNKNOWN;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
112 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
113
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
114 static void uninit(struct af_instance_s *af)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
115 {
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
116 free(af->data);
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
117 free(af->setup);
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
118 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
119
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
120 static af_data_t *play(struct af_instance_s *af, af_data_t *data)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
121 {
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
122 struct af_stats *s = af->setup;
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
123 int16_t *a, *aend;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
124 int v, v2;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
125
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
126 a = data->audio;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
127 aend = (int16_t *)((char *)data->audio + data->len);
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
128 s->n_samples += aend - a;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
129 for (; a < aend; a++) {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
130 v = *a;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
131 v2 = v * v;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
132 s->tsquare += v2;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
133 s->histogram[v + 32768]++;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
134 if (v2 > s->max)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
135 s->max = v2;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
136 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
137 return data;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
138 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
139
28663
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
140 static int af_open(af_instance_t *af)
8e9f6dfd7580 af_stats: Some fixes to the new filter
uau
parents: 28661
diff changeset
141 {
28661
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
142 af->control = control;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
143 af->uninit = uninit;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
144 af->play = play;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
145 af->mul = 1;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
146 af->data = malloc(sizeof(af_data_t));
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
147 af->setup = malloc(sizeof(struct af_stats));
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
148 if (af->data == NULL || af->setup == NULL)
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
149 return AF_ERROR;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
150 return AF_OK;
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
151 }
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
152
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
153 af_info_t af_info_stats = {
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
154 "Statistics audio filter",
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
155 "stats",
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
156 "Nicolas George",
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
157 "",
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
158 0,
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
159 af_open
20787bd5c506 Add statistics audio filter that prints information about the audio stream.
diego
parents:
diff changeset
160 };