1 /*
2 * madplay - MPEG audio decoder and player
3 * Copyright (C) 2000-2004 Robert Leslie
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * $Id: audio_null.c,v 1.17 2004/01/23 09:41:31 rob Exp $
20 */
21
22 # ifdef HAVE_CONFIG_H
23 # include "config.h"
24 # endif
25
26 # include "global.h"
27
28 # include <mad.h>
29
30 # include "audio.h"
31
32 static
init(struct audio_init * init)33 int init(struct audio_init *init)
34 {
35 return 0;
36 }
37
38 static
config(struct audio_config * config)39 int config(struct audio_config *config)
40 {
41 return 0;
42 }
43
44 static
update_stats(struct audio_stats * stats,unsigned int nsamples,mad_fixed_t const * sample)45 void update_stats(struct audio_stats *stats,
46 unsigned int nsamples, mad_fixed_t const *sample)
47 {
48 enum {
49 MIN = -MAD_F_ONE,
50 MAX = MAD_F_ONE - 1
51 };
52
53 while (nsamples--) {
54 if (*sample >= stats->peak_sample) {
55 stats->peak_sample = *sample;
56
57 if (*sample > MAX && *sample - MAX > stats->peak_clipping)
58 stats->peak_clipping = *sample - MAX;
59 }
60 else if (*sample < -stats->peak_sample) {
61 stats->peak_sample = -*sample;
62
63 if (*sample < MIN && MIN - *sample > stats->peak_clipping)
64 stats->peak_clipping = MIN - *sample;
65 }
66
67 ++sample;
68 }
69 }
70
71 static
play(struct audio_play * play)72 int play(struct audio_play *play)
73 {
74 update_stats(play->stats, play->nsamples, play->samples[0]);
75 if (play->samples[1])
76 update_stats(play->stats, play->nsamples, play->samples[1]);
77
78 return 0;
79 }
80
81 static
stop(struct audio_stop * stop)82 int stop(struct audio_stop *stop)
83 {
84 return 0;
85 }
86
87 static
finish(struct audio_finish * finish)88 int finish(struct audio_finish *finish)
89 {
90 return 0;
91 }
92
audio_null(union audio_control * control)93 int audio_null(union audio_control *control)
94 {
95 audio_error = 0;
96
97 switch (control->command) {
98 case AUDIO_COMMAND_INIT:
99 return init(&control->init);
100
101 case AUDIO_COMMAND_CONFIG:
102 return config(&control->config);
103
104 case AUDIO_COMMAND_PLAY:
105 return play(&control->play);
106
107 case AUDIO_COMMAND_STOP:
108 return stop(&control->stop);
109
110 case AUDIO_COMMAND_FINISH:
111 return finish(&control->finish);
112 }
113
114 return 0;
115 }
116