<?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>pronity.de</title>
	<atom:link href="http://www.pronity.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pronity.de</link>
	<description></description>
	<lastBuildDate>Wed, 24 Nov 2010 16:08:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Resample it yourself</title>
		<link>http://www.pronity.de/2010/06/resample-it-yourself/</link>
		<comments>http://www.pronity.de/2010/06/resample-it-yourself/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 16:17:19 +0000</pubDate>
		<dc:creator>Martin Mueller</dc:creator>
				<category><![CDATA[Xuggler]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[resample]]></category>

		<guid isPermaLink="false">http://www.pronity.de/?p=61&amp;langswitch_lang=de</guid>
		<description><![CDATA[pre { border:1px solid #AAA; background-color:#FFF; font-family:'courier new'; padding-top:10px; padding-bottom:10px; padding-left:5px; }
Did you guys ever try to resample audio-data of a clip in java? The JMF not very helpful, but today I will give you a little introduction to the xuggle library which will do that for you.
Xuggler is a library with the power of [...]]]></description>
			<content:encoded><![CDATA[<style>pre { border:1px solid #AAA; background-color:#FFF; font-family:'courier new'; padding-top:10px; padding-bottom:10px; padding-left:5px; }</style>
<p>Did you guys ever try to resample audio-data of a clip in java? The JMF not very helpful, but today I will give you a little introduction to the <a href="http://www.xuggle.com/">xuggle library</a> which will do that for you.</p>
<p>Xuggler is a library with the power of <a href="http://www.ffmpeg.org">ffmpeg</a> in your java application. A couple of weeks ago it was able to play video clips in your java application. But the real awesome stuff came with the new version of Xuggler. In version 3.0, which was released under AGPL <img src='http://www.pronity.de/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> , the MediaTools showed up. Now its possible to decode and encode your video clip from any format to any format.</p>
<p>If that is everything you need, you&#8217;ll be fine with just that. But if you need to resample the audio data (what you need, if you want to put the clip into, lets say, a FLV-Container), you need to implement a little more then just</p>
<pre>while(packet.read() == null);</pre>
<p><span id="more-61"></span></p>
<p>First step is to create your own writer. It will extend the <a href="http://build.xuggle.com/view/Stable/job/xuggler_jdk5_stable/javadoc/java/api/com/xuggle/mediatool/MediaToolAdapter.html">MediaToolAdapter</a> so we just need to override the methods we need and then give the result to the adapter.</p>
<pre>public class ConfigureListener extends MediaToolAdapter</pre>
<p>I called it &#8220;ConfigureListener&#8221; because its listening to the reader and then configuring it. But you can name it what ever you want.</p>
<p>Second step is to override the onAddStream-method which is called, when the reader gets a new stream and adds it to the listeners. If this method is called, we know there is a new stream, so we can check, what stream there is. if it is a audiostream, we can start to create a resampler.</p>
<pre>@Override
public void onAddStream(IAddStreamEvent event) {
	int streamIndex = event.getStreamIndex();
	IStreamCoder streamCoder = event.getSource().getContainer()
		.getStream(streamIndex).getStreamCoder();
	if (streamCoder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
		streamCoder.setSampleRate(44100);
	}
}</pre>
<p>If its not a audiostream, we just ignore it. After we set up the new sample rate for the stream, we got to give the event up to the parent-class, the MediaToolAdapter, so the event will got handled correctly.</p>
<pre>super.onAddStream(event);</pre>
<p>if that is done, the container, and the stream, knows that the output will be in in 44100 Hz, what you need to use to create FLV-Container.</p>
<p>But were not quite done. We need to resample <em>every</em> audiopacket. So we need to override the method onAudioSamples as well. This method get called for <em>every</em> audiopacket which is processed by the reader. So we create a <a href="http://build.xuggle.com/view/Stable/job/xuggler_jdk5_stable/javadoc/java/api/com/xuggle/xuggler/IAudioResampler.html">IAudioResampler</a> with the global instance of IAudioResampler and call its make-method. That will create us a IAudioResampler-object which will resample our audiosamples.</p>
<pre>if (resampler == null) {
	resampler = IAudioResampler.make(
	2, // output channels
	samples.getChannels(), // input channels
	44100, // new sample rate
	samples.getSampleRate() // old sample rate
	);
}</pre>
<p>We are doing that only once, because its take some time and the sample rate doesnt change in a clip.</p>
<p>If we got our resampler we will use it to resample the audiodata given by the event attribute:</p>
<pre>if (resampler != null &amp;&amp; event.getAudioSamples().getNumSamples() &gt; 0) {
	IAudioSamples out = IAudioSamples.make(
		samples.getNumSamples(), samples.getChannels());
	resampler.resample(out, samples, samples.getNumSamples());

	AudioSamplesEvent ase = new AudioSamplesEvent(
	event.getSource(), out, event.getStreamIndex());

	super.onAudioSamples(ase);
	out.delete();
}</pre>
<p>First we are creating an output object, which will hold our resampled data. Then we can finally call our resampler to resample the audio data. After that, we need to put the resampled data into a new AudioSamplesEvent, so we can give this event, with our new (resampled) audio data, to the parent-class with:</p>
<pre>super.onAudioSamples(ase);</pre>
<p>So it will be handled by the MediaToolAdapter and be put into your container with the correct (or even a different) audio sample rate.</p>
<p>Find the the complete source code <a href="http://www.pronity.de/wp-content/uploads/ConfigureListener.java">here (ConfigureListeer.java)</a></p>
<p>You just need to put it into your project and implement it in the reader-writer-chain like this:</p>
<pre>IMediaReader reader = ToolFactory.makeReader(filename);

ConfigureListener cl = new ConfigureListener();
reader.addListener(cl);

IMediaWriter writer = ToolFactory.makeWriter(outname, reader);

cl.addListener(writer);</pre>
<p>And read/write the stuff:</p>
<pre>while (reader.readPacket() == null);</pre>
<p>thanks for reader,</p>
<p>Martin</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pronity.de/2010/06/resample-it-yourself/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>proSlide &#8211; jQueryPlugin</title>
		<link>http://www.pronity.de/2010/05/hello-world/</link>
		<comments>http://www.pronity.de/2010/05/hello-world/#comments</comments>
		<pubDate>Sat, 08 May 2010 10:52:42 +0000</pubDate>
		<dc:creator>Martin Mueller</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[slide]]></category>

		<guid isPermaLink="false">http://www.pronity.de/pronityDOTde/?p=1</guid>
		<description><![CDATA[Hey,
you know these nice Slides from some ebaypages, with products which move nicely from right to left through a div and when a product is in the center of the div the product gets zoomed. I thought that would be a nice feature for shops to show a couple of products or something like that.
Thatswhy [...]]]></description>
			<content:encoded><![CDATA[<p>Hey,</p>
<p>you know these nice Slides from some ebaypages, with products which move nicely from right to left through a div and when a product is in the center of the div the product gets zoomed. I thought that would be a nice feature for shops to show a couple of products or something like that.</p>
<p>Thatswhy I statet to develope a nice plugin for jQuery which creates that kind of &#8220;SlideShow&#8221; out of a row of pictures. Unfortunately it takes more time than I thought. So I&#8217;m gonna publish the actual state of the development of this plugin here.</p>
<p>The actual state of the plugin can be find <a href="http://www.pronity.de/proSlide">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pronity.de/2010/05/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

