
ReplayGain
Source (link to git-repo or to original if based on someone elses unmodified work):
v1.0.0-beta5 by Miguel Angel Alvarez (maacruz at gmail.com)
October 20, 2007
An amaroK script to normalize volume using the replaygain method
Now on your language: english, spanish, german, hungarian, french, russian, slovak, finnish, polish, portuguesse, italian, turkish, swedish
(more translators wanted!!!)
Using replaygain will make all your songs have the same perceived volume, making unnecesary to adjust the volume on each song change (specially if they are from different albums/artists)
--Release Notes--
1.0.0beta5: Workaround for amarok saving playlist with non valid utf8 characters, which in turn would cause the script to crash. The internal scanner for wma/asf files is now x10 faster.
1.0.0-beta series:
Major enhancements and new features.
Support for streams: now streams can be scanned. The scan must be manually started in track mode. It will rip 60 seconds and set the gain accordingly, so some variance can be expected. The stream must broadcast normalized somewhat for this to have any sense. Requires mplayer.
Support for wma: Using a new internal scanner (only for wma for now, but soon to be expanded for all filetypes). It is quite experimental but since beta5 it is very fast and will use 3dnow on AMD cpu's. Requires mplayer.
Autoscan mode: now replaygain will autoscan the playlist when it is modified (files are added or removed). The autoscan only can do track mode. Streams are not autoscanned (by now). The autoscan starts after a configurable amount of time once the playlist has changed, to avoid putting the cpu under high load during track change in dynamic playlists. Autoscan runs in a separated thread, so replaygain works while the scan is in progress; beware that the manual scan still runs in the main thread (the script will not work on anything else). Autoscan can be enabled/disabled using the playlist context menu, if you want to stop a running autoscan simply disable it; starting a manual scan will also stop a running autoscan; changing the playlist while autoscan is running will let it finish the current file and start a new autoscan. Requires amarok>=1.4.6 and python-xml
New anti-lag meassure: the script follows the playlist and will guess the next track to be played, avoiding to query amarok. Only works if amarok is not playing in random track mode. Requires amarok>=1.4.6 and python-xml.
Minor improvements:
The scripts keeps you informed while a scan is in progress (previous versions only informed when the scan started and finished).
The configuration dialog now informs you of what's supported and any dependency unmet.
Memory usage has been reduced
Files are checked if writeable before scanning them (many thanks to dAniel hAhler http://daniel.hahler.de/ for suggestion and patch)
Volume is updated if the current playing file hadn't replaygain tags after it is scanned (manually or automatically)
More bugs
--End of notes--
Please report any bug
Files supported:
vorbis (ogg), mp3, aac (mp4/m4a), flac, musepack (mpc), wma/asf
Dependencies:
Needed:
kdebase3 (kdialog and dcop), python 2.3 or later, and UTF8 filesystem character set (to use national characters in the filename).
Optional:
pygtk (python-gtk) for the advanced configuration interface.
python-xml for easy playlist album scanning, autoscan, lag-reduction
mplayer, oggenc (vorbis-tools), vorbisgain for streams and wma support.
kdebindings3-python for lag-reduction
The following external utilities:
. metaflac (flac): to apply replaygain tags on flac files. This is likely a standard package on your distribution
. vorbisgain: to apply replaygain tags on vorbis ogg files
. aacgain: to apply replaygain tags on mp4/m4a aac files (works for mp3 too)
. mp3gain: to apply replaygain tags on mp3 files. Not needed if you have aacgain
. replaygain (musepack): to apply replaygain info on mpc (musepack) files.
. mplayer plus oggenc (vorbis-tools) and vorbisgain: to apply replaygain tags on wma/asf files and streams.
Where you can get the needed utilities:
Check your distribution's software repositories first.
Guru's page for SuSE Linux has mp3gain and vorbisgain. (http://linux01.gwdg.de/~pbleser/rpm-navigation.php?cat=Sound/)
Packman has musepack packages (they include replaygain) for SuSE Linux (http://packman.links2linux.de/)
Musepack home page (http://www.musepack.net/index.php?pg=lin)
Vorbisgain home page (http://sjeng.org/vorbisgain.html)
mp3gain home page (http://mp3gain.sourceforge.net/download.php)
aacgain home page (http://altosdesign.com/aacgain/).
mplayer home page (http://mplayerhq.hu
How to use
First you need to analyze all your song files using replaygain. The replaygain algorithm calculates a perceptual volume (gain) for each track (track mode) and album (album mode) and uses this information to correct the playback volume so all tracks or albums sound equally loud. In album mode the relative differences between tracks of an album are preserved, so more quiet tracks will sound more quiet, and louder tracks will sound louder. Album mode is better for live recordings and albums meant to be more than a collection of tracks, while track mode is better for heterogeneus mixes and compillations.
This analysis will not change your file's sound data, it will store the information in tags.
You can analyze a stream, file, album or your whole collection from the playlist's context menu:
Apply Replaygain tags->
-- To selected files in track mode: tag one or more files (as selected in playlist) with their respective track gain (track mode).
-- To playlist in album mode: tag all files in the playlist with both album and track gain tags (album mode), as if the playlist is one album.
-- To entire collection using album tags: the script will group the files in the database using their "Album" tag, and scan each group in album mode.
-- Autoscan: if this is activated, files in the playlist will be automatically tagged (track mode tags only).
It is recommended to have python-xml installed for album tagging (if not installed, playlist tagging as such and autoscan will not be available).
Once a file is tagged with replaygain data, the script will be able to read such tags and it will update the volume as needed.
The mode tags used are selected from the playlist context menu:
- Replaygain mode: which mode will use (track or album)
If a file doesn't have replaygain tags or it is of an unsupported type, it will be played at the default gain.
You can configure the script's operation in the configure script dialog. The most important parameters are:
- Pregain: this is the reference gain in dB (from the 0 point set at 55% volume in amarok). The range goes aproximately from 11 dB to -17 dB. Any replaygain volume correction will be relative to this gain, so you should leave enough space in the range for the script to work. The recommended value is 6.0 dB.
- Peak protection: If enabled, the volume may be adjusted to avoid clipping.
- Default gain: this is the assumed gain for files with no replaygain information. A good value could be -6.0 dB.
- Autoscan delay: amount of time in seconds between the playlist change and the autoscan start. Avoids reacting too quickly to manual playlist changes, and most important, clogging the CPU at track change when using dynamic playlists.
Crossfade is supported, so the volume changes slowly when crossfading.
You have also the option of sudden or smooth volume change when crossfade is disabled in amarok.
Lag reducing howto
Some people are affected by large lag between track change and the replaygain volume update
Lag seems caused by amarok itself by taking too much time to return from dcop calls.
This has been related to high cpu load caused by sqllite and cover image rendering.
So, if you are affected, what can you do?
In amarok 1.4.6 and later the script keeps track of playlist changes, to guess what the next song is and tell amarok to adjust volume inmediatly, needs python-xml and only works if track are played secuentially.
The cpu load for using sqllite has been reduced in 1.4.0 and later, and if you are using 1.3.9 you can apply the patch included in the amarok replaygain script package. Install either of those. Using a external database may be a good idea if you have a large collection, too.
Install kdebindings3-python to take advantage of new script's code.
If you are using the script's OSD control (the "Disable OSD during...." option) disable the OSD or uncheck the script option, it couldn't be optimized because of bugs in pykde
To see how cover rendering affects you, you can move your covers elsewere (try with an author or two) so they are not found. Large cover files may have a big impact, if this is the case, use gimp to reduce them.
Run amarok minimized in the tray, it will not update visual elements saving much time.
Resource intensive software affects too (some screensavers, p2p, ...)
During this beta release debug output is enabled. Have a look at your lag (in seconds) by typing in a konsole/xterm:
tail -f ~/.kde/share/apps/amarok/scripts-data/replayggain.log|grep time
As a reference, my lag is well under 0.1 s (usually 0.01-0.05)
Feedback appreciated.
Enjoy!
Miguel Angel
0.1-0.3.3
Old vorbisgain releases
0.5-beta "Reborn"
Major rewriting, now it is python
Renamed to replaygain
Add Album and peak support
New nice pygtk interface
Thanks to Kevin Radloff and Jocke "Firetech" for their suggestions and testing
0.5
Uses the new (since amarok 1.3.2) readConfig dcop calls if available, now the script is aware of amarok configuration changes
Added support for musepack (mpc) files
0.5.5
Added support for AAC (mp4/m4a) files
The script checks for external utilities when closing the configure dialog
0.6 "Clean OSD"
New option to disable osd updates during volume changes solving the annoying quick osd changes
Changed detection of external utilities since mp3gain has different behaviour depending on its version (thanks Jocke for pointing this out)
Settings are reread only when the engine starts playing, not at every song change
Fixed the check for external utilities so it solves the "mp3gain not found" missleading message, and a typo which prevented using aacgain when present.
Fixed flac on latest flac releases (thanks Gary Virta)
Changed the "utility not found" dialog to a less annoying notification
Many optimizations and speedups
Thanks Jocke and Roberto for all your testing
0.6.1
Hotfix: fix script breaking on amarok older than 1.3.2 when osd is disabled
0.7
Many new configuration options, not all can be accesed through the kdialog interface
Clipping protection may be disabled so volume doesn't go to 0 on some broken mp3 files
Pregain (volume reference level) may be adjusted by moving the volume slider
Pregain is now adjusted to tenths of dB instead of integer dB
The volume transitions may be smoothed over any specified amount of time when crossfade is disabled
Accurate timing so crossfaded/smoothed volume changes don't take longer than they should
Pygtk interface now has help as tooltips
Changes in script configuration take effect inmediately instead of waiting till next song
Script configuration is saved when amarok stops playing
0.7.1
Added support for mp3 files tagged with foobar (id3v2 tags), it requires id3v2 installed
SIGTERM handler
0.7.2
Added context menu shortcut to change replaygain mode
0.8.0
Internacionalization. Spanish translation.
New option to set the gain (volume) for files without replaygain info (or unsupported files).
Context menu options to apply/delete replaygain tags to playlist/collection. It is recommended to have python-xml installed for almbum tagging.
Some bugfixes
0.8.1
German, french and hungarian translations
0.8.2
Hotfix: do not break while scanning collection if unsupported file has no album tag.
0.8.3
Fix problems with special shell characters in filenames
0.8.4
Fix breaking if enviroment LANG variable is not set (assumes ISO8859-1 charset)
0.8.5
Fix encoding strings headache caused by gettext not returning unicode strings
0.8.6
Couple of small fixes
0.9.0
This release is designed to reduce lag (thanks Stewie for all your testing). Requires installing kdebindings3-python (aka python-kde) to take advantage of new code. Uses pykde for dcop calls if possible
Finnish GUI translation thanks to Samu Voutilainen
Slovak GUI translation thanks to Jozef Říha
Russian translation thanks to Anton Chumak.
Reworked kdialog interface to fix problems caused by X error messages
Corrects collection scanning if using dynamic collection (patch by Frederic Dinh).
Use mutagen-1.4 library (http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen) to read tags, except on mp4/m4a and mpc. Code for mpc and mp4 tag reading thanks to Justus Pendleton and QuodLibet player (needs ctypes python module). Dropped dependency on external utilities for tag reading.
Added support for RVA2 tags (used by QuodLibet and normalize)
Many bugfixes
0.9.1 Add portuguesse and polish GUI translations, updated finnish translation, thanks to Candido Lopes, Jaroslaw Gorny and Samu Voutilainen.
0.9.2: Add italian and turkish GUI translations. Many thanks to Davide "DuffyDac" and Fatih í‡iroglu
0.9.3: Add swedish GUI and README translation. Many thanks to Göran Jartin
Ratings & Comments
274 Comments
Hi, I have a multimedia keyboard (g15), and I want to configure the volume-"keys" (it's a wheel, but doesn't matter) to adjust amaroks volume (if I push e.g. the shift key in addition), instead of the global volume. I think I can manage configuring the keys - but since I can't speak python, I would ask you for this feature. I think it can't be very hard to code if you know the script ;). I'd be happy with a simple startable executable with an argument for the volume-change-amount :) (e.g. -2dB or -2%). Thanks for your help :).
For that you can just use the "dcop" executable. "dcop amarok default setVolumeRelative +20" , for example.
Hi ! I run mythbuntu which has xfce as standard desktop and is basically ubuntu intrepid. I have installed kdebase and all the other dependencies. Amarok works fine. Replaygain seems to work as it complains about no tags in the mp3's. However, when I try to add replaygain-tags via the context menu (add tags to whole collection) nothing happens apart from the "no replaygain tag" messagebox. I am happy to do the tagging from command line if that would be easier. kdebase seems to be kde4, i cant find a kdebase3 package in aptitude however. Do you think this can be made to work or should i switch to kde as desktop. (which i dread as this is my main tv box which was a nightmare to set up...) Thanks for your help, Cheers, Karl
Are you sure you have installed mp3gain or aacgain? Open the configuration dialog and look in the dependencies tab.
This script was invaluable to me in Amarok 1.x, I greatly look forward to its debut in 2.x but in the meantime, I still have rippin' to do! Can you advise me what commands I'd need to run on a folder of mp3 files in order to get the same result as running "smart gain" (album + track gain) in Amarok? I run these: mp3gain -rkp *.mp3 mp3gain -akp *.mp3 But I don't know if there's more that your script does (pregain etc. which I just leave on default settings in Amarok). How can I be sure to get the same results? Thanks!
The way you are using mp3gain modifies the mp3 sound data. I use it in a different way, just writing to the replaygain tags. mp3gain *.mp3 Just with that, you'll get the same effect as running the script's scanner.
i found kde with kdialig progressbar and dcop to be no longer working in the old way - at least on intrepid - when scanning the entire collection. The expected result is replaygain to open a kdialog progress window but the actual result is a crash because some index do no longer exist. The solution is the change some lines in the kdialog_gui.py file replacing the ProgresDialog class to use qdbus. class ProgressDialog: def __init__(self,steps): self.dcopref=command_getoutput('kdialog --title "Amarok replaygain script" --progressbar "'+_('Scanning...').encode(LC,'replace')+'" ' +str(steps)) def setprogress(self,step): command_getoutput('qdbus '+self.dcopref+' org.freedesktop.DBus.Properties.Set org.kde.kdialog.ProgressDialog value '+str(step)) def close(self): command_getoutput('qdbus '+self.dcopref+' org.kde.kdialog.ProgressDialog.close') The information was acquired from http://forum.kde.org/dcop-progress-bar-with-kdialog-t-13521.html I've tested it locally and it works.
Thanks :)
I don't know where to get kdebindings3-python. I'm using openSUSE 11.1 with KDE4, and it's not in the repositories. It seems it's necessary to get rid of the very noticeable lag I have.
It seems the package is now named python-kde3
I've since found this and it did stop that error from popping up, but I still have errors popping up at times saying something like "try removing or reducing covers"? (Can't remember exact wording)
That's because the script detect's a lag too big: amarok takes too much time in responding to the script One reason for lagging is cover rendering, if you have covers, you can try removing the covers to see if it helps.
Does replaygain work in Amarok 2.0? If not, do you have any plan to make it happen? Thanks
It seems amarok 2.1 will support replaygain tags, but will be unable of tagging the files. That being the case, I'll port the tagging part of the script, but not before amarok's replaygaing support is in place.
Nice touch for a great music player. Since I've tracks from assorted albums, makes it convenient & pleasant to enjoy the music. Thank you so much.
When I try to configure replaygain it stop and i get this error message : /home/emualynk/.kde/share/apps/amarok/scripts/amarok_replaygain/gui_gtk.py:66: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated gladeTree = gtk.glade.XML(sys.path[0]+'/amarok_replaygain.glade') Traceback (most recent call last): File "/home/emualynk/.kde/share/apps/amarok/scripts/amarok_replaygain/amarok_replaygain.py", line 1241, in <module> configdialog(replaygain_config,check_dependencies()) File "/home/emualynk/.kde/share/apps/amarok/scripts/amarok_replaygain/gui_gtk_wrapper.py", line 25, in configdialog cdict1 = eval(gui_out.readline()) File "<string>", line 1 /usr/bin/scim ^ SyntaxError: invalid syntax Anyone knows how to fix it ?
Open a xterm/konsole and cd to /home/emualynk/.kde/share/apps/amarok/scripts/amarok_replaygain There, run the following command (copy and paste): echo "{'pregain':'+6', 'gain_default':'-3.0', 'use_slider':'false', 'no_peak':'false','mode':'track', 'no_osd':'false', 'smooth':'true', 'smooth_time':'0.5', 'autoscan':'true', 'no_guess':'false', 'autoscan_delay':'1.0', 'external_scanner':'false'}" | python gui_gtk.py >/tmp/gui_gtk.out The dialog should open, press ok and send me the /tmp/gui_gtk.out Tell me also what messages appear on the xterm.
I have that on xterm : gui_gtk.py:66: GtkWarning: GtkSpinButton: setting an adjustment with non-zero page size is deprecated gladeTree = gtk.glade.XML(sys.path[0]+'/amarok_replaygain.glade') The messenger is now down The messenger is now down The messenger is now down The messenger is now down The messenger is now down An IOException occurred at scim_bridge_client_imcontext_set_cursor_location () An IOException occurred at scim_bridge_client_imcontext_set_cursor_location () An IOException occurred at scim_bridge_client_imcontext_set_cursor_location () An IOException occurred at scim_bridge_client_imcontext_set_cursor_location () The messenger is now down The messenger is now down The messenger is now down The messenger is now down The messenger is now down and inside the gui_gtk.out I have : /usr/bin/scim {'no_peak': 'true', 'pregain': 6.0, 'no_osd': 'true', 'external_scanner': 'false', 'smooth': 'true', 'gain_default': -3.0, 'use_slider': 'true', 'autoscan': 'true', 'mode': 'track', 'autoscan_delay': 1.0, 'no_guess': 'false', 'smooth_time': 0.5} Also when i run the cmd it opens me replaygain settings.
Without editing the settings it writes /usr/bin/scim {'no_peak': 'false', 'pregain': 6.0, 'no_osd': 'false', 'external_scanner': 'false', 'smooth': 'true', 'gain_default': -3.0, 'use_slider': 'false', 'autoscan': 'true', 'mode': 'track', 'autoscan_delay': 1.0, 'no_guess': 'false', 'smooth_time': 0.5} into the guy_gtk.out
The script is working as expected, but it seems scim (do you write in chinesse?) messes with the stdio communication between the gui module and the script. Let's try to disable scim and see if it works. Edit the file ~/.kde/share/apps/amarok/scripts/amarok_replaygain/gui_gtk_wrapper.py Look for the line with the text: gui_in,gui_out = os.popen2('python '+sys.path[0]+'/gui_gtk.py') Modify it so it says: gui_in,gui_out = os.popen2('GTK_IM_MODULE=gtk-im-context-simple python '+sys.path[0]+'/gui_gtk.py') Save it, run amarok and see if the script works as it should.
It worked, thanks a lot.
hi, I'm using this script for a long time, but couldn't find it in the "Get more scripts" window of Amarok. Maybe it is badly submitted to this site?
I don't know why. The site selects what get shown in amarok, but I don't know how the selection is made.
hi there, first thank you for your creating such a great piece of software! unfortunately replaygain stopped working for me :/ it now claims there is no replaygain information on any file and fails to process a file (mp3, whatever) when rightclicking on a file in the playlist and choosing "add replaygain information for this title". the message is simply: "The following files failed: file:///home/bazza/mp3/200805/03%20street%20players.mp3" i am using opensuse 11 and installed amarok from the packman repository via the metapackage amarok-packman-1.4.9.1-104.pm.1. furthermore i am using the latest version of replaygain being 1.0.0-beta5. I have installed all needed dependencies. i would like to provide more details on this, i don't know how to get a proper debugging output though. any help on this would be highly appreciated! cheers sebastian
Hi again, sorry for the noise, this was absolutely my fault. i actually compiled aacgain but missed to install it. i thought it worked before because some of my mp3s already had replaygain tags ^^;; your script rocks!! cheers, sebastian