At the end of the day, you are only getting clipping when you pass the audio back to libsndfile.  Go to the part of the code right before you call the libsndfile function to write the audio to the file.  If at that point, you loop through all the samples, and find the one with the biggest absolute value, and then loop through again and divide every sample by that value, you will remove any clipping.   Or you could hard clip it and instead just set any value &gt;1 to 1.  The fact that you wrote this program in the first place clearly shows that you have enough understanding to do either one of these things.<br>

<br>You don&#39;t need to know any more about DSP than what I&#39;m telling you now (and you don&#39;t need to know anything about jack): <br>1. All the samples passed to libsndfile should be between -1&lt;x&lt;+1.  <br>
2. If you divide all the samples by the same value, this will make all the samples lie within a smaller range, and will lower the volume of the audio. <br>
<br>If you&#39;re interested in playing around with your computer some more, you could add code to write out the sound from the intermediate steps, so that you could see precisely where it is inserted. But this is not necessary at all, as clipping can be removed easily at any point up until it is written to file.  All you need it two &quot;for&quot; loops.<br>

<br>Jeremy<br><br><div class="gmail_quote">On Sat, Oct 29, 2011 at 1:11 AM, Stephen Cameron <span dir="ltr">&lt;<a href="mailto:smcameron@yahoo.com">smcameron@yahoo.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div style="color:#000;background-color:#fff;font-family:times new roman, new york, times, serif;font-size:12pt"><div><br>
<span></span></div>
<div><span>Yeah, I know there&#39;s a bit of clipping.</span></div>
<div><br>
  <span></span></div>
<div><span>I
 think it&#39;s because I&#39;m summing what amount to a bunch of normalized 
random data -- so some of those sums end up outside -1 &lt; x &lt; +1, 
though I do normalizing steps between sums, so... I don&#39;t know exactly 
where the clipping is coming from -- I think it&#39;s coming from my &quot;poor 
man&#39;s reverb&quot; effect, which, that thing should probably be replaced with
 something better and faster, but... like I said, I don&#39;t know JACK 
about DSP, I&#39;m just playing around with my computer and my compiler and 
my soundcard.</span></div>
<div><br>
</div>
<div>Best thing ever would be to send me a patch!</div>
<div><br>
  <span></span></div>
<div><span>-- steve<br><div class="hm">
  </div></span></div><div class="hm">
<div><br></div><div><br></div></div><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div class="hm"><font size="2" face="Arial"><hr size="1">

<b><span style="font-weight:bold">From:</span></b> Jeremy Salwen &lt;<a href="mailto:jeremysalwen@gmail.com" target="_blank">jeremysalwen@gmail.com</a>&gt;<br><b><span style="font-weight:bold">To:</span></b> Stephen Cameron &lt;<a href="mailto:smcameron@yahoo.com" target="_blank">smcameron@yahoo.com</a>&gt;<br>

<b><span style="font-weight:bold">Cc:</span></b> &quot;<a href="mailto:linux-audio-user@lists.linuxaudio.org" target="_blank">linux-audio-user@lists.linuxaudio.org</a>&quot; &lt;<a href="mailto:linux-audio-user@lists.linuxaudio.org" target="_blank">linux-audio-user@lists.linuxaudio.org</a>&gt;<br>

<b><span style="font-weight:bold">Sent:</span></b> Friday, October 28, 2011 9:09 PM<br><b><span style="font-weight:bold">Subject:</span></b> Re: [LAU] Explodomatica - explosion sound effect generator<br></font></div><div>

<div></div><div class="h5"><br>
<div>Very cool.  I was playing around with it.  I do have one suggestion though: It seems you are introducing unwanted artifacts due to clipping.<br><br>First, you probably don&#39;t want clipping.  However, it is showing up, even in your demo samples.<br>



<br>Second, you might want clipping (Probably we&#39;ve ingrained digital clipping in our perception of explosion sounds), but if you do, you&#39;re not clipping in the right way.  I haven&#39;t looked at your code, but because I had the exact same symptoms while using libsndfile, I&#39;m guessing that what you are doing is feeding libsndfile floats with values &gt;1 or &lt;-1.  If you want proper clipping, these samples would be pulled to the closest value within the range [-1,1].  However, due to performance reasons (I&#39;m guessing), this is not what libsndfile does, but instead it wraps around.  So 1.1 will be interpreted as the amplitude of -0.9.  <br>



<br>Here&#39;s what it looks like:  <a href="http://i.imgur.com/sselM.png" target="_blank">http://i.imgur.com/sselM.png</a>  <br><br>That image is from demo0.wav.  This causes the &quot;clicking&quot; artifacts you hear in the file.  In order to fix this, just go through and find any samples &gt; 1 and replace them with 1, and similarly with -1, right before you write the data out with libsndfile.  This should give you proper &quot;chopped peaks&quot; clipping.  Or, if you don&#39;t want clipping at all, just calculate the max amplitude and divide every sample by it before outputting.<br>



<br>Good luck and thanks,<br>Jeremy<br><br><br><br><div>On Fri, Oct 28, 2011 at 2:05 PM, Stephen Cameron <span dir="ltr">&lt;<a rel="nofollow" href="mailto:smcameron@yahoo.com" target="_blank">smcameron@yahoo.com</a>&gt;</span> wrote:<br>



<blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div><div style="color:rgb(0, 0, 0);background-color:rgb(255, 255, 255);font-family:times new roman,new york,times,serif;font-size:12pt">



<div><br></div><div>I made a little explosion sound effect generator, the idea being to help out people looking for such things for making video games, and so on.  It  relies on portaudio, libsndfile, and gtk2.</div><div>



<br></div><div>I don&#39;t really know what I&#39;m doing when it comes to DSP, so probably some of you will laugh when you see my algorithms.  But it does more or less make explosion sounds.</div><div><br></div><div>It&#39;s here:<br>



</div><div><a href="http://smcameron.github.com/explodomatica" target="_blank">http://smcameron.github.com/explodomatica</a></div><div><br></div><div>Enjoy<br></div><div><br></div><div>-- steve</div><div></div></div></div>



<br>_______________________________________________<br>
Linux-audio-user mailing list<br>
<a rel="nofollow" href="mailto:Linux-audio-user@lists.linuxaudio.org" target="_blank">Linux-audio-user@lists.linuxaudio.org</a><br>
<a href="http://lists.linuxaudio.org/listinfo/linux-audio-user" target="_blank">http://lists.linuxaudio.org/listinfo/linux-audio-user</a><br>
<br></blockquote></div><br>
</div><br><br></div></div></div></div></div></div></blockquote></div><br>