rewrite replaygain code, needs testing

git-svn-id: https://svn.musicpd.org/mpd/trunk@2482 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes
2004-11-02 19:56:59 +00:00
parent 1d105d126e
commit 54679d9028
12 changed files with 136 additions and 98 deletions

View File

@@ -71,11 +71,7 @@ void initReplayGainState() {
}
}
int getReplayGainState() {
return replayGainState;
}
float computeReplayGainScale(float gain, float peak) {
static float computeReplayGainScale(float gain, float peak) {
float scale;
if(gain == 0.0) return(1);
@@ -89,14 +85,55 @@ float computeReplayGainScale(float gain, float peak) {
return(scale);
}
void doReplayGain(char * buffer, int bufferSize, AudioFormat * format,
float scale)
{
mpd_sint16 * buffer16 = (mpd_sint16 *)buffer;
mpd_sint8 * buffer8 = (mpd_sint8 *)buffer;
mpd_sint32 temp32;
ReplayGainInfo * newReplayGainInfo() {
ReplayGainInfo * ret = malloc(sizeof(ReplayGainInfo));
ret->albumGain = 0.0;
ret->albumPeak = 1.0;
ret->trackGain = 0.0;
ret->trackPeak = 1.0;
/* set to -1 so that we know in doReplayGain to compute the scale */
ret->scale = -1.0;
return ret;
}
void freeReplayGainInfo(ReplayGainInfo * info) {
free(info);
}
void doReplayGain(ReplayGainInfo * info, char * buffer, int bufferSize,
AudioFormat * format)
{
mpd_sint16 * buffer16;
mpd_sint8 * buffer8;
mpd_sint32 temp32;
float scale;
if(replayGainState == REPLAYGAIN_OFF || !info) return;
if(info->scale < 0) {
switch(replayGainState) {
case REPLAYGAIN_TRACK:
info->scale = computeReplayGainScale(info->trackGain,
info->trackPeak);
break;
default:
info->scale = computeReplayGainScale(info->albumGain,
info->albumPeak);
break;
}
}
if(info->scale <= 1.01 && info->scale >= 0.99) return;
buffer16 = (mpd_sint16 *)buffer;
buffer8 = (mpd_sint8 *)buffer;
scale = info->scale;
if(scale == 1.0) return;
switch(format->bits) {
case 16:
while(bufferSize > 0){
@@ -122,4 +159,3 @@ void doReplayGain(char * buffer, int bufferSize, AudioFormat * format,
ERROR("%i bits not supported by doReplaygain!\n", format->bits);
}
}
/* End of added code */