aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java49
-rw-r--r--src/github/daneren2005/dsub/util/tags/BastpUtil.java17
2 files changed, 55 insertions, 11 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 127df768..c3eb3ef7 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -47,10 +47,13 @@ import github.daneren2005.dsub.util.ShufflePlayBuffer;
import github.daneren2005.dsub.util.SimpleServiceBinder;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.util.compat.RemoteControlClientHelper;
+import github.daneren2005.dsub.util.tags.BastpUtil;
import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.serverproxy.BufferProxy;
import java.io.File;
+import java.io.IOError;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@@ -1415,6 +1418,8 @@ public class DownloadService extends Service {
}
cachedPosition = position;
+ applyReplayGain(mediaPlayer, downloadFile);
+
if (start || autoPlayStart) {
mediaPlayer.start();
setPlayerState(STARTED);
@@ -1473,6 +1478,8 @@ public class DownloadService extends Service {
mediaPlayer.setNextMediaPlayer(nextMediaPlayer);
nextSetup = true;
}
+
+ applyReplayGain(nextMediaPlayer, downloadFile);
} catch (Exception x) {
handleErrorNext(x);
}
@@ -1922,6 +1929,48 @@ public class DownloadService extends Service {
}
}
+ private void applyReplayGain(MediaPlayer mediaPlayer, DownloadFile downloadFile) {
+ if(currentPlaying == null) {
+ return;
+ }
+
+ try {
+ float[] rg = BastpUtil.getReplayGainValues(downloadFile.getFile().getCanonicalPath()); /* track, album */
+ float adjust = 0f;
+ if (true /*mReplayGainAlbumEnabled*/) {
+ adjust = (rg[0] != 0 ? rg[0] : adjust); /* do we have track adjustment ? */
+ adjust = (rg[1] != 0 ? rg[1] : adjust); /* ..or, even better, album adj? */
+ }
+ if (/*mReplayGainTrackEnabled || (mReplayGainAlbumEnabled && */ adjust == 0) {
+ adjust = (rg[1] != 0 ? rg[1] : adjust); /* do we have album adjustment ? */
+ adjust = (rg[0] != 0 ? rg[0] : adjust); /* ..or, even better, track adj? */
+ }
+ if (adjust == 0) {
+ /* No RG value found: decrease volume for untagged song if requested by user */
+ // adjust = (mReplayGainUntaggedDeBump - 150) / 10f;
+ } else {
+ /* This song has some replay gain info, we are now going to apply the 'bump' value
+ ** The preferences stores the raw value of the seekbar, that's 0-150
+ ** But we want -15 <-> +15, so 75 shall be zero */
+ // adjust += 2 * (mReplayGainBump - 75) / 10f; /* 2* -> we want +-15, not +-7.5 */
+ }
+ /*if (mReplayGainAlbumEnabled == false && mReplayGainTrackEnabled == false) {
+ // Feature is disabled: Make sure that we are going to 100% volume
+ adjust = 0f;
+ }*/
+ float rg_result = ((float) Math.pow(10, (adjust / 20)))/* * mFadeOut*/;
+ if (rg_result > 1.0f) {
+ rg_result = 1.0f; /* android would IGNORE the change if this is > 1 and we would end up with the wrong volume */
+ } else if (rg_result < 0.0f) {
+ rg_result = 0.0f;
+ }
+ Log.d(TAG, "Applied volume of " + rg_result);
+ mediaPlayer.setVolume(rg_result, rg_result);
+ } catch(IOException e) {
+ Log.w(TAG, "Failed to apply replay gain values", e);
+ }
+ }
+
private class BufferTask extends SilentBackgroundTask<Void> {
private final DownloadFile downloadFile;
private final int position;
diff --git a/src/github/daneren2005/dsub/util/tags/BastpUtil.java b/src/github/daneren2005/dsub/util/tags/BastpUtil.java
index 99279f62..a738bbce 100644
--- a/src/github/daneren2005/dsub/util/tags/BastpUtil.java
+++ b/src/github/daneren2005/dsub/util/tags/BastpUtil.java
@@ -21,17 +21,12 @@ import android.util.LruCache;
import java.util.HashMap;
import java.util.Vector;
-public class BastpUtil {
- private RGLruCache rgCache;
-
- public BastpUtil() {
- rgCache = new RGLruCache(16); /* Cache up to 16 entries */
- }
-
-
+public final class BastpUtil {
+ private static final RGLruCache rgCache = new RGLruCache(16);
+
/** Returns the ReplayGain values of 'path' as <track,album>
*/
- public float[] getReplayGainValues(String path) {
+ public static float[] getReplayGainValues(String path) {
float[] cached = rgCache.get(path);
if(cached == null) {
@@ -45,7 +40,7 @@ public class BastpUtil {
/** Parse given file and return track,album replay gain values
*/
- private float[] getReplayGainValuesFromFile(String path) {
+ private static float[] getReplayGainValuesFromFile(String path) {
String[] keys = { "REPLAYGAIN_TRACK_GAIN", "REPLAYGAIN_ALBUM_GAIN" };
float[] adjust= { 0f , 0f };
HashMap tags = (new Bastp()).getTags(path);
@@ -68,7 +63,7 @@ public class BastpUtil {
/** LRU cache for ReplayGain values
*/
- private class RGLruCache extends LruCache<String, float[]> {
+ private static class RGLruCache extends LruCache<String, float[]> {
public RGLruCache(int size) {
super(size);
}