<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>xscDevBlog - LastSharp &#38; Co. &#187; Batch</title>
	<atom:link href="http://dev.xscheme.de/tag/batch/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.xscheme.de</link>
	<description>Der xscheme-DevelopmentBlog</description>
	<lastBuildDate>Sun, 23 May 2010 11:40:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>mp3Gain-Wrapper (C#)</title>
		<link>http://dev.xscheme.de/2008/08/mp3gain-codesnippet-c-batch/</link>
		<comments>http://dev.xscheme.de/2008/08/mp3gain-codesnippet-c-batch/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 15:48:32 +0000</pubDate>
		<dc:creator>xsc</dc:creator>
				<category><![CDATA[Batch]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[part of lastsharp]]></category>

		<guid isPermaLink="false">http://dev.xscheme.de/?p=101</guid>
		<description><![CDATA[mp3Gain ist ein Programm zur (reversiblen!) Normalisierung der Lautstärke in MP3-Dateien. Die folgende Klasse kann mithilfe der Kommandozeilenversion von mp3Gain einen MP3-Titel normalisieren.

using System;
/*
 * [class] mp3Gain: Klasse zur Normalisierung von MP3-Dateien mithilfe von mp3Gain
 *
 * Copyright (C) 2008 Yannick Scherer
 * This program is free software; you can redistribute it and/or modify it [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://dev.xscheme.de/wp-content/uploads/2008/08/mp3gainlogosmall.gif" align="left" style="margin-right: 1em;" /><a href="http://mp3gain.sourceforge.net">mp3Gain</a> ist ein Programm zur (reversiblen!) Normalisierung der Lautstärke in MP3-Dateien. Die folgende Klasse kann mithilfe der <a href="http://prdownloads.sourceforge.net/mp3gain/mp3gain-dos-1_4_6.zip?download">Kommandozeilenversion von mp3Gain</a> einen MP3-Titel normalisieren.<br />
<span id="more-101"></span></p>
<pre class="c#" name="code">using System;
/*
 * [class] mp3Gain: Klasse zur Normalisierung von MP3-Dateien mithilfe von mp3Gain
 *
 * Copyright (C) 2008 Yannick Scherer
 * 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 the Free Software Foundation; either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, see http://www.gnu.org/licenses/.
 * */

using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using System.IO;

class mp3Gain
    {
        // mp3Gain-Daten
        private static Process          mp3GainProcess = null;
        private static ProcessStartInfo mp3GainProcessInfo = new ProcessStartInfo(mp3GainPath);
        private static string           mp3GainCurrentFile = "";
        public static bool              mp3GainIsRunning = false;
        public static string            mp3GainPath    { get { return System.Windows.Forms.Application.StartupPath+"/mp3gain/mp3gain.exe"; } }
        public static string            mp3GainParams { get { return "/r /d 20 /k /c /q"; } }
        // Lautstärke normalisieren
        public static void NormalizeVolume(string mp3File) {
            if (!mp3GainIsRunning &amp;&amp; File.Exists(mp3GainPath) &amp;&amp; File.Exists(mp3File)) {
                // Prozess läuft
                mp3GainIsRunning   = true;
                mp3GainCurrentFile = mp3File;
                // Datei, an der gearbeitet wird
                string mp3Work = mp3File+"_work.mp3";
                File.Copy(mp3File, mp3Work);
                // mp3GainProcessInfo initialisieren
                mp3GainProcessInfo.Arguments = mp3GainParams+" \""+mp3Work+"\"";
                mp3GainProcessInfo.WindowStyle = ProcessWindowStyle.Hidden;
                // mp3Gain aufrufen
                mp3GainProcess = new Process();
                mp3GainProcess.StartInfo = mp3GainProcessInfo;
                mp3GainProcess.EnableRaisingEvents = true;
                mp3GainProcess.Exited += new EventHandler(mp3GainExited);
                mp3GainProcess.Start();
            }
        }
        public static void mp3GainExited(object sender, EventArgs e)
        {
            // Daten rückkopieren
            string mp3Work = mp3GainCurrentFile + "_work.mp3";
            if (new FileInfo(mp3Work).Length &gt; 0)
            {
                File.Copy(mp3Work, mp3GainCurrentFile, true);
                File.Delete(mp3Work);
            }
            // Reset
            mp3GainIsRunning = false;
            mp3GainCurrentFile = "";
            return;
        }

    }</pre>
<p>Eine MP3-Datei wird normalisiert, durch den Aufruf <code>mp3Gain.NormalizeVolume(&lt;MP3-Datei&gt;)</code>.</p>
<p>Innerhalb der Klasse müssen noch der Pfad zu mp3gain.exe (<em>mp3GainPath</em>) angepasst werden, sowie die gewünschten Parameter (<em>mp3GainParams</em>). Eine Übersicht über die Parameter von mp3Gain gibt es <a href="http://wiki.ubuntuusers.de/MP3Gain?rev=66766">hier</a>.</p>
<p><strong>Batch</strong></p>
<p>Ein BatchFile, das mp3Gain verwendet, könnte folgendermaßen aussehen (vorrausgesetzt, es befindet sich im selben Verzeichnis wie mp3gain.exe):</p>
<pre>@rem // Ziehen Sie eine MP3-Datei auf dieses Batchfile, um sie zu normalisieren.

@rem // In aktuelles Verzeichnis wechseln
@cd /D %~d0%~p0

@echo --------------------------------------------------------------------
@echo Normalisieren von %1 ...
@echo --------------------------------------------------------------------
@ "%cd%/mp3gain.exe" &lt;Parameter&gt; %1
@echo --------------------------------------------------------------------
@echo Prozess abgeschlossen...
@echo --------------------------------------------------------------------
@pause</pre>
<p>Dieser Code lässt sich natürlich erweitern, sodass ganze Ordner bearbeitet werden. Das überlasse ich aber jedem, der fleißig genug dafür ist&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.xscheme.de/2008/08/mp3gain-codesnippet-c-batch/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
