Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Commit

Permalink
make replay gain a config option
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-bl committed Mar 23, 2013
1 parent 4b36615 commit 6c225a1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions res/values/translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ THE SOFTWARE.
<string name="headset_pause_summary">Pause when the headphones are unplugged.</string>
<string name="headset_play_title">Play When Plugged</string>
<string name="headset_play_summary">Play when the headphones are plugged in. (Only works when the service is running.)</string>
<string name="replaygain_title">Enable replay gain</string>
<string name="replaygain_summary">Read replay gain information from tags and decrease volume if needed</string>

<string name="notifications">Notifications</string>
<string name="notification_mode_title">Notification Mode</string>
Expand Down
5 changes: 5 additions & 0 deletions res/xml/preference_audio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ THE SOFTWARE.
android:title="@string/headset_play_title"
android:summary="@string/headset_play_summary"
android:defaultValue="false" />
<CheckBoxPreference
android:key="enable_replaygain"
android:title="@string/replaygain_title"
android:summary="@string/replaygain_summary"
android:defaultValue="false" />
</PreferenceScreen>
23 changes: 18 additions & 5 deletions src/ch/blinkenlights/android/vanilla/PlaybackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ public final class PlaybackService extends Service
* of user settings.
*/
private boolean mForceNotificationVisible;

/**
* Enables or disables Replay Gain
*/
private boolean mReplayGainEnabled;

@Override
public void onCreate()
{
Expand Down Expand Up @@ -399,6 +403,7 @@ public void onCreate()
mHeadsetPause = getSettings(this).getBoolean(PrefKeys.HEADSET_PAUSE, true);
mShakeAction = settings.getBoolean(PrefKeys.ENABLE_SHAKE, false) ? Action.getAction(settings, PrefKeys.SHAKE_ACTION, Action.NextSong) : Action.Nothing;
mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f;
mReplayGainEnabled = settings.getBoolean(PrefKeys.ENABLE_REPLAYGAIN, false);

PowerManager powerManager = (PowerManager)getSystemService(POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VanillaMusicLock");
Expand Down Expand Up @@ -562,7 +567,15 @@ private MediaPlayer getNewMediaPlayer() {
public void prepareMediaPlayer(MediaPlayer mp, String path) throws IOException{

mp.setDataSource(path);
/*

if(mReplayGainEnabled == true) {
applyReplayGain(mp, path);
}

mp.prepare();
}

private void applyReplayGain(MediaPlayer mp, String path) {
Hashtable tags = (new Bastp()).getTags(path);
float adjust = 1.0f;

Expand All @@ -576,12 +589,10 @@ public void prepareMediaPlayer(MediaPlayer mp, String path) throws IOException{
} catch(Exception e) {}

adjust = (float)Math.pow(10, (rg_float/20) );
Toast.makeText(this, path+"\n"+" PX "+rg_raw+" adj = "+adjust, Toast.LENGTH_LONG).show();
Toast.makeText(this, path+"\n"+" PX "+rg_raw+" adj = "+adjust, Toast.LENGTH_SHORT).show();
}

mp.setVolume(adjust, adjust);
*/
mp.prepare();
}

/**
Expand Down Expand Up @@ -697,6 +708,8 @@ private void loadPreference(String key)
setupSensor();
} else if (PrefKeys.SHAKE_THRESHOLD.equals(key)) {
mShakeThreshold = settings.getInt(PrefKeys.SHAKE_THRESHOLD, 80) / 10.0f;
} else if (PrefKeys.ENABLE_REPLAYGAIN.equals(key)) {
mReplayGainEnabled = settings.getBoolean(PrefKeys.ENABLE_REPLAYGAIN, false);
}

CompatFroyo.dataChanged(this);
Expand Down
1 change: 1 addition & 0 deletions src/ch/blinkenlights/android/vanilla/PrefKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ public class PrefKeys {
public static final String USE_IDLE_TIMEOUT = "use_idle_timeout";
public static final String VISIBLE_CONTROLS = "visible_controls";
public static final String VISIBLE_EXTRA_INFO = "visible_extra_info";
public static final String ENABLE_REPLAYGAIN = "enable_replaygain";
}

0 comments on commit 6c225a1

Please sign in to comment.