<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 9.00.8112.16430"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>Hi Karl!</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>You should always place an audioconvert +&nbsp;audioresample 
right before the audiosink, see:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial><A 
href="http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-directsoundsink.html">http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-directsoundsink.html</A></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>I would remove the audioresample from the first pipeline. In 
the 2nd:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>adder audioconvert audioresample 
autosoundsink</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>You can try your pipelines via gst-launch before implementing 
them right away-</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>cheers,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial>mat</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=683082707-24112011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV><BR>
<DIV dir=ltr lang=de class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>Von:</B> 
gstreamer-devel-bounces+mdodt=xion-medical.com@lists.freedesktop.org 
[mailto:gstreamer-devel-bounces+mdodt=xion-medical.com@lists.freedesktop.org] 
<B>Im Auftrag von </B>Karl Phillip<BR><B>Gesendet:</B> 23 November 2011 
14:00<BR><B>An:</B> gstreamer-devel@lists.freedesktop.org<BR><B>Betreff:</B> 
Audio mixing with ADDER results in broken sound<BR></FONT><BR></DIV>
<DIV></DIV>Hi all, <BR><BR>I'm using QtGStreamer-0.10 to play a mp3 file and I'm 
having difficulties finding out why the resulting sound is so horrible. I wrote 
the smallest application possible to reproduce the problem I'm 
facing.<BR><BR>I'm working on a "audio mixer" component that allows you to have 
multiple audio players instantiated and running. It's job is to mix all audio 
received by the players and chose to do this task myself because the soundcard I 
have is terrible and can't deal with 8, 9 audio players simultaneously. So I'm 
hoping to make it's job easier by sending it only one audio stream.<BR><BR>Let's 
jump into the code! The application below sets up 2 pipelines: the first named 
"_ms_pipeline" (as in master pipeline), and its responsible for mixing the audio 
using only 2 elements: an ADDER linked to AUTOAUDIOSINK. <BR><BR>The second 
pipeline, named only "pipeline", loads the file from the disk through FILESRC, 
decodes it, does some stuff using the following elements: APPSRC &gt; VOLUME 
&gt; AUDIOCONVERT &gt; AUDIORESAMPLE &gt; CAPSFILTER.<BR><BR>At the end I 
connect the src pad of CAPSFILTER to a sink pad of the ADDER, then set the state 
of the pipelines to QGst::StatePlaying to start playing the audio.<BR><BR>The 
result is awful.<BR><BR>#include &lt;QtGui/QApplication&gt;<BR><BR>#include 
&lt;QList&gt;<BR>#include &lt;QPointer&gt;<BR>#include 
&lt;QObject&gt;<BR><BR>#include &lt;QGlib/Error&gt;<BR>#include 
&lt;QGlib/Connect&gt;<BR>#include &lt;QGst/Init&gt;<BR>#include 
&lt;QGst/Bus&gt;<BR>#include &lt;QGst/Pipeline&gt;<BR>#include 
&lt;QGst/Parse&gt;<BR>#include &lt;QGst/Message&gt;<BR>#include 
&lt;QGst/Utils/ApplicationSink&gt;<BR>#include 
&lt;QGst/Utils/ApplicationSource&gt;<BR>#include 
&lt;QGst/ElementFactory&gt;<BR>#include &lt;QGst/Element&gt;<BR>#include 
&lt;QGst/Pad&gt;<BR>#include &lt;QGst/Bin&gt;<BR><BR>#include 
&lt;iostream&gt;<BR><BR>QGst::PipelinePtr _ms_pipeline;<BR>QGst::ElementPtr 
_ms_adder;<BR>QGst::ElementPtr _ms_output;<BR><BR>QGst::ElementPtr 
appsink;<BR><BR>class MySink : public 
QGst::Utils::ApplicationSink<BR>{<BR>public:<BR>&nbsp;&nbsp;&nbsp; 
MySink(QGst::Utils::ApplicationSource *src)<BR>&nbsp;&nbsp;&nbsp; : 
QGst::Utils::ApplicationSink(), m_src(src) 
{}<BR><BR>protected:<BR>&nbsp;&nbsp;&nbsp; virtual void 
eos()<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
m_src-&gt;endOfStream();<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; 
virtual QGst::FlowReturn newBuffer()<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
m_src-&gt;pushBuffer(pullBuffer());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return QGst::FlowOk;<BR>&nbsp;&nbsp;&nbsp; 
}<BR><BR>private:<BR>&nbsp;&nbsp;&nbsp; QGst::Utils::ApplicationSource 
*m_src;<BR>};<BR><BR><BR>class Player : 
QObject<BR>{<BR>public:<BR>&nbsp;&nbsp;&nbsp; Player(const char* 
filename);<BR>&nbsp;&nbsp;&nbsp; ~Player() {};<BR><BR>&nbsp;&nbsp;&nbsp; MySink 
m_sink; <BR>&nbsp;&nbsp;&nbsp; QGst::Utils::ApplicationSource 
m_src;<BR><BR>&nbsp;&nbsp;&nbsp; void onNewDecodedPad(QGst::PadPtr 
pad)&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; 
"Player::onNewDecodePad\n";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
QGst::CapsPtr caps = 
pad-&gt;caps();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QGst::StructurePtr 
structure = 
caps-&gt;internalStructure(0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
(structure-&gt;name().contains("audio/x-raw")) 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout 
&lt;&lt; "Player::onNewDecodePad 
audio/x-raw\n";<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; QGst::PadPtr 
saidaDecoder = 
appsink-&gt;getStaticPad("sink");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
if (pad-&gt;link(saidaDecoder) != 
QGst::PadLinkOk)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
std::cout &lt;&lt; "Player::onNewDecodePad: Failed link 
!!!\n";<BR><BR>&nbsp;&nbsp;&nbsp; }<BR>};<BR><BR><BR>int main(int argc, char 
*argv[])<BR>{<BR>&nbsp;&nbsp;&nbsp; if (argc &lt; 2) <BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Usage: 
qtplayer &lt;file.mp3&gt;\n";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return -1;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; QApplication 
app(argc, argv);<BR><BR>&nbsp;&nbsp;&nbsp; Player 
player(argv[1]);<BR><BR>&nbsp;&nbsp;&nbsp; return 
app.exec();<BR>}<BR><BR><BR>Player::Player(const char* filename)<BR>: 
m_sink(&amp;m_src)<BR>{<BR>&nbsp;&nbsp;&nbsp; QGst::init(0, 
NULL);<BR><BR>&nbsp;&nbsp; // Master pipeline setup<BR><BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline = QGst::Pipeline::create("mypipe");<BR>&nbsp;&nbsp;&nbsp; if 
(!_ms_pipeline)<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "MasterSink: 
Failed creating pipeline !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;setState(QGst::StateNull);<BR><BR>&nbsp;&nbsp;&nbsp; _ms_adder 
= QGst::ElementFactory::make("adder","audiomixer");<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(_ms_adder);<BR><BR>&nbsp;&nbsp;&nbsp; _ms_output = 
QGst::ElementFactory::make("autoaudiosink","audio_out");<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(_ms_output);<BR><BR>&nbsp;&nbsp;&nbsp; if 
(!_ms_adder-&gt;link(_ms_output))<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "MasterSink: 
Failed linking to _output !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;setState(QGst::StateReady);<BR>&nbsp;&nbsp;&nbsp; std::cout 
&lt;&lt; "_ms_pipeline: StateReady\n";<BR><BR><BR>&nbsp;&nbsp;&nbsp; // This 2nd 
pipeline loads the file, decodes it and sends the audio stream to the master 
pipeline <BR><BR>&nbsp;&nbsp;&nbsp; QGst::PipelinePtr pipeline = 
QGst::Pipeline::create();<BR><BR>&nbsp;&nbsp;&nbsp; QGst::ElementPtr filesrc = 
QGst::ElementFactory::make("filesrc");<BR>&nbsp;&nbsp;&nbsp; 
filesrc-&gt;setProperty("location", filename);<BR>&nbsp;&nbsp;&nbsp; 
pipeline-&gt;add(filesrc);&nbsp;&nbsp;&nbsp; <BR><BR>&nbsp;&nbsp;&nbsp; 
QGst::BinPtr decodebin = 
QGst::ElementFactory::make("decodebin2").dynamicCast&lt;QGst::Bin&gt;();<BR>&nbsp;&nbsp;&nbsp; 
pipeline-&gt;add(decodebin);<BR>&nbsp;&nbsp;&nbsp; if 
(!filesrc-&gt;link(decodebin))<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "Failed: 
filesrc &gt; decodebin !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; appsink = 
QGst::ElementFactory::make("appsink");<BR>&nbsp;&nbsp;&nbsp; 
pipeline-&gt;add(appsink);<BR><BR>&nbsp;&nbsp;&nbsp; 
m_sink.setElement(appsink);<BR><BR>&nbsp;&nbsp;&nbsp; QGst::ElementPtr appsrc = 
QGst::ElementFactory::make("appsrc");<BR>&nbsp;&nbsp;&nbsp; 
m_src.setElement(appsrc);<BR>&nbsp;&nbsp;&nbsp; 
m_src.setFormat(QGst::FormatDefault);<BR><BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(appsrc);<BR><BR>&nbsp;&nbsp;&nbsp; QGst::ElementPtr vol = 
QGst::ElementFactory::make("volume");<BR>&nbsp;&nbsp;&nbsp; 
vol-&gt;setProperty("volume", 0.7);<BR>&nbsp;&nbsp;&nbsp; QGst::ElementPtr 
convert = QGst::ElementFactory::make("audioconvert");<BR>&nbsp;&nbsp;&nbsp; 
QGst::ElementPtr resample = 
QGst::ElementFactory::make("audioresample");<BR><BR>&nbsp;&nbsp;&nbsp; 
QGst::ElementPtr filtercaps = 
QGst::ElementFactory::make("capsfilter");<BR>&nbsp;&nbsp;&nbsp; 
filtercaps-&gt;setProperty("caps", QGst::Caps::fromString("audio/x-raw-int, 
endianness=(int)1234, channels=(int)1, width=(int)16, depth=(int)16, 
signed=(boolean)true, rate=(int)11025"));<BR><BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(vol);<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(convert);<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(resample);<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;add(filtercaps);<BR><BR>&nbsp;&nbsp;&nbsp; if 
(!appsrc-&gt;link(vol))<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "Failed: 
appsrc &gt; vol !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; if 
(!vol-&gt;link(convert))<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "Failed: 
filesrc &gt; decodebin !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; if 
(!convert-&gt;link(resample))<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "Failed: 
filesrc &gt; decodebin !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; if 
(!resample-&gt;link(filtercaps))<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "Failed: 
filesrc &gt; decodebin !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; QGst::PadPtr sinkpad = 
_ms_adder-&gt;getRequestPad("sink%d");<BR>&nbsp;&nbsp;&nbsp; if 
(!sinkpad)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
qDebug() &lt;&lt; "Failed: sinkpad 
!!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; QGst::PadPtr 
saidaConverters = filtercaps-&gt;getStaticPad("src");<BR>&nbsp;&nbsp;&nbsp; if 
(saidaConverters-&gt;link(sinkpad) != QGst::PadLinkOk)<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qDebug() &lt;&lt; "Failed: saida 
&gt; sinkpad !!!";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return;<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; 
QGlib::connect(decodebin, "pad-added", this, 
&amp;Player::onNewDecodedPad);<BR><BR>&nbsp;&nbsp;&nbsp; 
pipeline-&gt;setState(QGst::StatePlaying);<BR>&nbsp;&nbsp;&nbsp; std::cout 
&lt;&lt; "pipeline: StatePlaying\n";<BR><BR>&nbsp;&nbsp;&nbsp; QGst::State 
state;<BR>&nbsp;&nbsp;&nbsp; pipeline-&gt;getState(&amp;state, NULL, 
0);<BR>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "pipeline: state is " &lt;&lt; 
state &lt;&lt; " while playing would be: " &lt;&lt; QGst::StatePlaying &lt;&lt; 
"\n";<BR><BR><BR>&nbsp;&nbsp;&nbsp; QGst::State ms_state;<BR>&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;getState(&amp;ms_state, NULL, 0);<BR>&nbsp;&nbsp;&nbsp; if 
(ms_state != QGst::StatePlaying)<BR>&nbsp;&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; 
"_ms_pipeline: StatePlaying *AGAIN* was: " &lt;&lt; ms_state &lt;&lt; 
"\n";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;setState(QGst::StateNull);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
_ms_pipeline-&gt;setState(QGst::StatePlaying);<BR>&nbsp;&nbsp;&nbsp; 
}<BR><BR>&nbsp;&nbsp;&nbsp; _ms_pipeline-&gt;getState(&amp;ms_state, NULL, 
0);<BR>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "_ms_pipeline: state is " &lt;&lt; 
ms_state &lt;&lt; "\n";<BR>}<BR></BODY></HTML>