1
/* the Music Player Daemon (MPD)
2
* (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
3
* (c)2004 replayGain code by AliasMrJones
4
* This project's homepage is: http://www.musicpd.org
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
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
20
#include "replayGain.h"
29
/* Added 4/14/2004 by AliasMrJones */
30
static int replayGainState = REPLAYGAIN_OFF;
32
static float replayGainPreamp = 1.0;
34
void initReplayGainState() {
35
if(!getConf()[CONF_REPLAYGAIN]) return;
37
if(strcmp(getConf()[CONF_REPLAYGAIN],"track")==0) {
38
replayGainState = REPLAYGAIN_TRACK;
40
else if(strcmp(getConf()[CONF_REPLAYGAIN],"album")==0) {
41
replayGainState = REPLAYGAIN_ALBUM;
44
ERROR("replaygain value \"%s\" is invalid\n",
45
getConf()[CONF_REPLAYGAIN]);
49
if(getConf()[CONF_REPLAYGAIN_PREAMP]) {
51
float f = strtod(getConf()[CONF_REPLAYGAIN_PREAMP], &test);
54
ERROR("Replaygain preamp \"%s\" is not a number\n",
55
getConf()[CONF_REPLAYGAIN_PREAMP]);
59
if(f < -15 || f > 15) {
60
ERROR("Replaygain preamp \"%s\" is not between -15 and"
62
getConf()[CONF_REPLAYGAIN_PREAMP]);
66
replayGainPreamp = pow(10, f/20.0);
70
int getReplayGainState() {
71
return replayGainState;
74
float computeReplayGainScale(float gain, float peak) {
77
if(gain == 0.0) return(1);
78
scale = pow(10.0, gain/20.0);
79
scale*= replayGainPreamp;
80
if(scale > 15.0) scale = 15.0;
82
if (scale * peak > 1.0) {
88
void doReplayGain(char * buffer, int bufferSize, AudioFormat * format,
91
mpd_sint16 * buffer16 = (mpd_sint16 *)buffer;
92
mpd_sint8 * buffer8 = (mpd_sint8 *)buffer;
95
if(scale == 1.0) return;
96
switch(format->bits) {
98
while(bufferSize > 0){
101
*buffer16 = temp32>32767 ? 32767 :
102
(temp32<-32768 ? -32768 : temp32);
111
*buffer8 = temp32>127 ? 127 :
112
(temp32<-128 ? -128 : temp32);
118
ERROR("%i bits not supported by doReplaygain!\n", format->bits);
121
/* End of added code */