diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-10-06 13:54:44 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-10-06 13:54:44 -0700 |
commit | 76a45b603fac943732d1eb8e219bd10e03f2fb69 (patch) | |
tree | 209a4bc825d52c8020700d69e756587f5e446bc8 /src | |
parent | be75b266a7c1d44b33b7cc93e39469f61c715999 (diff) | |
download | dsub-76a45b603fac943732d1eb8e219bd10e03f2fb69.tar.gz dsub-76a45b603fac943732d1eb8e219bd10e03f2fb69.tar.bz2 dsub-76a45b603fac943732d1eb8e219bd10e03f2fb69.zip |
Make smart replay gain optional, smart replay gain to check if current playing part of at least 4 consequetive songs of same album
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadService.java | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 588df901..a03f056c 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -98,6 +98,7 @@ public class DownloadService extends Service { public static final int FAST_FORWARD = 30000; public static final int REWIND = 10000; private static final double DELETE_CUTOFF = 0.84; + private static final int REQUIRED_ALBUM_MATCHES = 4; private RemoteControlClientHelper mRemoteControl; @@ -138,8 +139,6 @@ public class DownloadService extends Service { private int cachedPosition = 0; private boolean downloadOngoing = false; private float volume = 1.0f; - private boolean singleAlbum = false; - private String singleAlbumName; private AudioEffectsController effectsController; private RemoteControlState remoteState = RemoteControlState.LOCAL; @@ -362,20 +361,6 @@ public class DownloadService extends Service { } else { downloadList.add(offset, file); } - - // Check if we are still dealing with a single album - // Don't bother with check if it is already false - if(singleAlbum) { - // If first download, set album to it - if(singleAlbumName == null) { - singleAlbumName = file.getSong().getAlbum(); - } else { - // Otherwise, check again previous album name - if(!singleAlbumName.equals(file.getSong().getAlbum())) { - singleAlbum = false; - } - } - } } public synchronized void downloadBackground(List<MusicDirectory.Entry> songs, boolean save) { for (MusicDirectory.Entry song : songs) { @@ -639,8 +624,6 @@ public class DownloadService extends Service { suggestedPlaylistName = null; suggestedPlaylistId = null; - singleAlbum = true; - singleAlbumName = null; } public synchronized void remove(int which) { @@ -1821,7 +1804,6 @@ public class DownloadService extends Service { } } currentPlayingIndex = downloadList.indexOf(currentPlaying); - singleAlbum = false; if (revisionBefore != revision) { updateJukeboxPlaylist(); @@ -1972,6 +1954,49 @@ public class DownloadService extends Service { float[] rg = BastpUtil.getReplayGainValues(downloadFile.getFile().getCanonicalPath()); /* track, album */ float adjust = 0f; if (prefs.getBoolean(Constants.PREFERENCES_KEY_REPLAY_GAIN, false)) { + boolean singleAlbum = false; + + String replayGainType = prefs.getString(Constants.PREFERENCE_KEY_REPLAY_GAIN_TYPE, "1"); + // 1 => Smart replay gain + if("1".equals(replayGainType)) { + // Check if part of at least <REQUIRED_ALBUM_MATCHES> consequetive songs of the same album + + int index = downloadList.indexOf(downloadFile); + if(index != -1) { + String albumName = downloadFile.getSong().getAlbum(); + int matched = 0; + + // Check forwards + for(int i = index + 1; i < downloadList.size() && matched < REQUIRED_ALBUM_MATCHES; i++) { + if(albumName.equals(downloadList.get(i).getSong().getAlbum())) { + matched++; + } else { + break; + } + } + + // Check backwards + for(int i = index - 1; i >= 0 && matched < REQUIRED_ALBUM_MATCHES; i--) { + if(albumName.equals(downloadList.get(i).getSong().getAlbum())) { + matched++; + } else { + break; + } + } + + if(matched >= REQUIRED_ALBUM_MATCHES) { + singleAlbum = true; + } + } + } + // 2 => Use album tags + else if("2".equals(replayGainType)) { + singleAlbum = true; + } + // 3 => Use track tags + // Already false, no need to do anything here + + // If playing a single album or no track gain, use album gain if((singleAlbum || rg[0] == 0) && rg[1] != 0) { adjust = rg[1]; |