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: rgain.c,v 1.1 2004/02/23 21:34:53 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 "rgain.h"
31 # include "gettext.h"
32
33 /*
34 * NAME: rgain->parse()
35 * DESCRIPTION: parse a 16-bit Replay Gain field
36 */
rgain_parse(struct rgain * rgain,struct mad_bitptr * ptr)37 void rgain_parse(struct rgain *rgain, struct mad_bitptr *ptr)
38 {
39 int negative;
40
41 rgain->name = mad_bit_read(ptr, 3);
42 rgain->originator = mad_bit_read(ptr, 3);
43
44 negative = mad_bit_read(ptr, 1);
45 rgain->adjustment = mad_bit_read(ptr, 9);
46
47 if (negative)
48 rgain->adjustment = -rgain->adjustment;
49 }
50
51 /*
52 * NAME: rgain->originator()
53 * DESCRIPTION: return a string description of a Replay Gain originator
54 */
rgain_originator(struct rgain const * rgain)55 char const *rgain_originator(struct rgain const *rgain)
56 {
57 char const *originator = 0;
58
59 switch (rgain->originator) {
60 case RGAIN_ORIGINATOR_UNSPECIFIED:
61 return 0;
62 case RGAIN_ORIGINATOR_PRESET:
63 originator = _("preset");
64 break;
65 case RGAIN_ORIGINATOR_USER:
66 originator = _("user");
67 break;
68 case RGAIN_ORIGINATOR_AUTOMATIC:
69 originator = _("automatic");
70 break;
71 }
72
73 return originator ? originator : _("other");
74 }
75