From d0221587e9d332c522f7ac429781d4ccaa7f5ce9 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Tue, 5 Apr 2022 18:06:43 +0200 Subject: sync bastp to upstream/ vanilla-music --- .../daneren2005/dsub/util/tags/BastpUtil.java | 126 +++++++++++++++------ 1 file changed, 91 insertions(+), 35 deletions(-) (limited to 'app/src/main/java/github/daneren2005/dsub/util/tags/BastpUtil.java') diff --git a/app/src/main/java/github/daneren2005/dsub/util/tags/BastpUtil.java b/app/src/main/java/github/daneren2005/dsub/util/tags/BastpUtil.java index 7ff517fd..802aa5ad 100644 --- a/app/src/main/java/github/daneren2005/dsub/util/tags/BastpUtil.java +++ b/app/src/main/java/github/daneren2005/dsub/util/tags/BastpUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Adrian Ulrich + * Copyright (C) 2013-2019 Adrian Ulrich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,59 +14,115 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package github.daneren2005.dsub.util.tags; -import android.support.v4.util.LruCache; +import android.util.LruCache; +import java.util.ArrayList; import java.util.HashMap; -import java.util.Vector; -public final class BastpUtil { - private static final RGLruCache rgCache = new RGLruCache(16); +public class BastpUtil { + /** + * Our global instance cache + */ + private RGLruCache rgCache; + /** + * What we return & cache + */ + public class GainValues { + public float album; + public float track; + public boolean found; + } + /** + * LRU cache for ReplayGain values + */ + private class RGLruCache extends LruCache { + public RGLruCache(int size) { + super(size); + } + } + - /** Returns the ReplayGain values of 'path' as + public BastpUtil() { + rgCache = new RGLruCache(64); + } + + /** + * Returns a GainValues object for `path' */ - public static float[] getReplayGainValues(String path) { - float[] cached = rgCache.get(path); + public GainValues getReplayGainValues(String path) { + if(path == null) { + // path must not be null + path = "//null\\"; + } + GainValues cached = rgCache.get(path); if(cached == null) { cached = getReplayGainValuesFromFile(path); rgCache.put(path, cached); } return cached; } - - - - /** Parse given file and return track,album replay gain values + + /** + * Parse given file and return track,album replay gain values */ - private static float[] getReplayGainValuesFromFile(String path) { - String[] keys = { "REPLAYGAIN_TRACK_GAIN", "REPLAYGAIN_ALBUM_GAIN" }; - float[] adjust= { 0f , 0f }; + private GainValues getReplayGainValuesFromFile(String path) { HashMap tags = (new Bastp()).getTags(path); - - for (int i=0; i { - public RGLruCache(int size) { - super(size); - } + private float getFloatFromString(String rg_raw) { + float rg_float = 0f; + try { + String nums = rg_raw.replaceAll("[^0-9.-]",""); + rg_float = Float.parseFloat(nums); + } catch(Exception e) {} + return rg_float; } } -- cgit v1.2.3