2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2010-01-01 05:55:13 +01:00
|
|
|
* Copyright (C) 2003-2010 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-05-08 14:04:23 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2004-05-08 00:42:54 +02:00
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2010-01-04 20:58:17 +01:00
|
|
|
#include "replay_gain_config.h"
|
2004-05-08 00:42:54 +02:00
|
|
|
#include "conf.h"
|
2009-11-01 15:44:56 +01:00
|
|
|
#include "idle.h"
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-11-11 16:24:27 +01:00
|
|
|
#include <glib.h>
|
2009-10-17 22:40:50 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
2008-11-11 16:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
2008-11-11 16:24:27 +01:00
|
|
|
|
|
|
|
static const char *const replay_gain_mode_names[] = {
|
|
|
|
[REPLAY_GAIN_ALBUM] = "album",
|
|
|
|
[REPLAY_GAIN_TRACK] = "track",
|
|
|
|
};
|
|
|
|
|
2008-11-11 16:18:31 +01:00
|
|
|
enum replay_gain_mode replay_gain_mode = REPLAY_GAIN_OFF;
|
2004-05-08 00:42:54 +02:00
|
|
|
|
2010-01-04 13:31:20 +01:00
|
|
|
float replay_gain_preamp = 1.0;
|
|
|
|
float replay_gain_missing_preamp = 1.0;
|
2004-07-17 16:54:22 +02:00
|
|
|
|
2009-10-17 22:58:19 +02:00
|
|
|
const char *
|
|
|
|
replay_gain_get_mode_string(void)
|
|
|
|
{
|
|
|
|
switch (replay_gain_mode) {
|
2010-04-25 13:42:23 +02:00
|
|
|
case REPLAY_GAIN_AUTO:
|
|
|
|
return "auto";
|
|
|
|
|
2009-10-17 22:58:19 +02:00
|
|
|
case REPLAY_GAIN_OFF:
|
|
|
|
return "off";
|
|
|
|
|
|
|
|
case REPLAY_GAIN_TRACK:
|
|
|
|
return "track";
|
|
|
|
|
|
|
|
case REPLAY_GAIN_ALBUM:
|
|
|
|
return "album";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* unreachable */
|
|
|
|
assert(false);
|
|
|
|
return "off";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-10-17 22:40:50 +02:00
|
|
|
replay_gain_set_mode_string(const char *p)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-10-17 22:40:50 +02:00
|
|
|
assert(p != NULL);
|
2004-05-08 00:42:54 +02:00
|
|
|
|
2009-10-17 22:40:50 +02:00
|
|
|
if (strcmp(p, "off") == 0)
|
2009-10-17 21:38:32 +02:00
|
|
|
replay_gain_mode = REPLAY_GAIN_OFF;
|
2009-10-17 22:40:50 +02:00
|
|
|
else if (strcmp(p, "track") == 0)
|
2008-11-11 15:55:34 +01:00
|
|
|
replay_gain_mode = REPLAY_GAIN_TRACK;
|
2009-10-17 22:40:50 +02:00
|
|
|
else if (strcmp(p, "album") == 0)
|
2008-11-11 15:55:34 +01:00
|
|
|
replay_gain_mode = REPLAY_GAIN_ALBUM;
|
2010-04-25 13:42:23 +02:00
|
|
|
else if (strcmp(p, "auto") == 0)
|
|
|
|
replay_gain_mode = REPLAY_GAIN_AUTO;
|
2009-10-17 22:40:50 +02:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2009-11-01 15:44:56 +01:00
|
|
|
idle_add(IDLE_OPTIONS);
|
|
|
|
|
2009-10-17 22:40:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void replay_gain_global_init(void)
|
|
|
|
{
|
|
|
|
const struct config_param *param = config_get_param(CONF_REPLAYGAIN);
|
|
|
|
|
|
|
|
if (param != NULL && !replay_gain_set_mode_string(param->value)) {
|
2008-11-11 16:38:26 +01:00
|
|
|
g_error("replaygain value \"%s\" at line %i is invalid\n",
|
|
|
|
param->value, param->line);
|
2004-05-08 00:42:54 +02:00
|
|
|
}
|
2004-07-17 16:54:22 +02:00
|
|
|
|
2009-01-17 20:23:27 +01:00
|
|
|
param = config_get_param(CONF_REPLAYGAIN_PREAMP);
|
2004-10-28 07:14:55 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (param) {
|
|
|
|
char *test;
|
2004-10-28 07:14:55 +02:00
|
|
|
float f = strtod(param->value, &test);
|
2004-07-17 16:54:22 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (*test != '\0') {
|
2008-11-11 16:38:26 +01:00
|
|
|
g_error("Replaygain preamp \"%s\" is not a number at "
|
|
|
|
"line %i\n", param->value, param->line);
|
2004-07-17 16:54:22 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (f < -15 || f > 15) {
|
2008-11-11 16:38:26 +01:00
|
|
|
g_error("Replaygain preamp \"%s\" is not between -15 and"
|
|
|
|
"15 at line %i\n", param->value, param->line);
|
2004-07-17 16:54:22 +02:00
|
|
|
}
|
|
|
|
|
2008-11-11 15:55:34 +01:00
|
|
|
replay_gain_preamp = pow(10, f / 20.0);
|
2004-07-17 16:54:22 +02:00
|
|
|
}
|
2009-06-19 09:02:12 +02:00
|
|
|
|
|
|
|
param = config_get_param(CONF_REPLAYGAIN_MISSING_PREAMP);
|
|
|
|
|
|
|
|
if (param) {
|
|
|
|
char *test;
|
|
|
|
float f = strtod(param->value, &test);
|
|
|
|
|
|
|
|
if (*test != '\0') {
|
|
|
|
g_error("Replaygain missing preamp \"%s\" is not a number at "
|
|
|
|
"line %i\n", param->value, param->line);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f < -15 || f > 15) {
|
|
|
|
g_error("Replaygain missing preamp \"%s\" is not between -15 and"
|
|
|
|
"15 at line %i\n", param->value, param->line);
|
|
|
|
}
|
|
|
|
|
|
|
|
replay_gain_missing_preamp = pow(10, f / 20.0);
|
|
|
|
}
|
2004-05-08 00:42:54 +02:00
|
|
|
}
|