aboutsummaryrefslogtreecommitdiffstats
path: root/src/replayGain.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-11-02 19:56:59 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-11-02 19:56:59 +0000
commit54679d9028117360e50a85a1f4b4f376f13ad6a3 (patch)
treee23dbf750251f57a6f836ca65693628916eca006 /src/replayGain.c
parent1d105d126e84f80b28bc60a742e2631a4227a101 (diff)
downloadmpd-54679d9028117360e50a85a1f4b4f376f13ad6a3.tar.gz
mpd-54679d9028117360e50a85a1f4b4f376f13ad6a3.tar.xz
mpd-54679d9028117360e50a85a1f4b4f376f13ad6a3.zip
rewrite replaygain code, needs testing
git-svn-id: https://svn.musicpd.org/mpd/trunk@2482 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/replayGain.c')
-rw-r--r--src/replayGain.c58
1 files changed, 47 insertions, 11 deletions
diff --git a/src/replayGain.c b/src/replayGain.c
index 4788d7d95..138d3a68b 100644
--- a/src/replayGain.c
+++ b/src/replayGain.c
@@ -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)
+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_sint16 *)buffer;
- mpd_sint8 * buffer8 = (mpd_sint8 *)buffer;
+ 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 */