<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.newlc.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>NewLC - Mixing Using au format... - Comments</title>
 <link>http://www.newlc.com/en/topic-10064</link>
 <description>Comments for &quot;Mixing Using au format...&quot;</description>
 <language>en</language>
<item>
 <title>Re: Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064#comment-24235</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hi all,&lt;br /&gt;&lt;br /&gt;i&amp;#039;m trying to do something similar, and i almost did it.&lt;br /&gt;Starting from 2 mp3, i decompress them to 2 raw PCM wav files with no header with lame :&lt;br /&gt;&amp;gt; lame --decode -t file1.mp3&lt;br /&gt;&amp;gt; lame --decode -t file2.mp3&lt;br /&gt;NB : my mp3s are 16bit 44.1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;which generates file1.mp3.wav and file2.mp3.wav&lt;br /&gt;&lt;br /&gt;then i use the following program (i&amp;#039;m a newbie) : &lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;codeheader&quot;&gt;Code:&lt;/div&gt;&lt;div class=&quot;code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;#include &amp;lt;string.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include &amp;lt;math.h&amp;gt;&lt;br /&gt;&lt;br /&gt;int main(int argc,char *argv[]) {&lt;br /&gt;&amp;nbsp; char mixname[255];&lt;br /&gt;&amp;nbsp; FILE *pcm1, *pcm2, *mix;&lt;br /&gt;&amp;nbsp; char sample1, sample2;&lt;br /&gt;&amp;nbsp; int value;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; pcm1 = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;&amp;nbsp; pcm2 = fopen(argv[2],&amp;quot;r&amp;quot;);&lt;br /&gt;&amp;nbsp; &lt;br /&gt;&amp;nbsp; strcpy (mixname, argv[1]);&lt;br /&gt;&amp;nbsp; strcat (mixname, &amp;quot;_temp.wav&amp;quot;);&lt;br /&gt;&amp;nbsp; mix = fopen(mixname, &amp;quot;w&amp;quot;);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; while(!feof(pcm1)) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; sample1 = fgetc(pcm1);&lt;br /&gt;&amp;nbsp; &amp;nbsp; sample2 = fgetc(pcm2);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; if ((sample1 &amp;lt; 0) &amp;amp;&amp;amp; (sample2 &amp;lt; 0)) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; value = sample1 + sample2 - (sample1 * sample2 / -(pow(2,16-1)-1));&lt;br /&gt;&amp;nbsp; &amp;nbsp; }else{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; value = sample1 + sample2 - (sample1 * sample2 / (pow(2,16-1)-1));&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; fputc(value, mix);&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; fclose(pcm1);&lt;br /&gt;&amp;nbsp; fclose(pcm2);&lt;br /&gt;&amp;nbsp; fclose(mix);&lt;br /&gt;&lt;br /&gt;&amp;nbsp; return 0;&lt;br /&gt;}&lt;/div&gt;&lt;br /&gt;which generates file1.mp3.wav_temp.wav&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;and i use lame back again to generate an mp3 :&lt;br /&gt;&lt;br /&gt;&amp;gt; lame -s 44.1 s file1.mp3.wav_temp.wav&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: Red;&quot;&gt;Problem&lt;/span&gt; : This works like a dream excpet that the sound has a tendency to become saturated&lt;br /&gt;&lt;br /&gt;How to solve this saturation problem?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NB : i don&amp;#039;t have any error checking for the moment and this program implies that file1 is shorter than file2 but it&amp;#039;s just a beginning&lt;/div&gt;</description>
 <pubDate>Fri, 07 Oct 2005 13:19:10 +0200</pubDate>
 <dc:creator>duch</dc:creator>
 <guid isPermaLink="false">comment 24235 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064#comment-24234</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Yes I was wondering on the number of files, Well what i can say that if you have to only mix arround the&lt;br /&gt;Max three files (Simultaneously at some senario) then i will suggest implement the equation which I have&lt;br /&gt;given to you, Yes the above algo is not going to give the best output for more then 5 files, &lt;br /&gt;&lt;br /&gt;second if you implemnet the above equation then let me tell you, that there is over head as we are &lt;br /&gt;operating on the each sample values,&amp;nbsp; If the overhead is not the constraint then try it and let us know&lt;br /&gt;what the diffculties you are facing while implementing.&lt;br /&gt;&lt;br /&gt;The most advantage of the above algorthim, is that there is _NO_ over flow or under flow of the data while mixing, which makes this algorthim to produce the best of qualities for less then 5 files.&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Ranjeet Gupta&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Tue, 30 Aug 2005 16:00:21 +0200</pubDate>
 <dc:creator>ranjeet</dc:creator>
 <guid isPermaLink="false">comment 24234 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064#comment-24233</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Sujat &lt;br /&gt;&lt;br /&gt;First let me know that how much file you have to mix ? &lt;br /&gt;means what is the max number of stream which you are looking to mix as a single stream,&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Ranjeet Gupta&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Tue, 30 Aug 2005 15:03:45 +0200</pubDate>
 <dc:creator>ranjeet</dc:creator>
 <guid isPermaLink="false">comment 24233 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064#comment-24232</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hi friends ,&lt;br /&gt; at first i would like to thank both of u.... I saw the sound mixer exampleÂ  given by nokia...but they havnt done any calculation specified by ranjeet( at my first glance)...Ranjeet if u hav some spare time pls hav a look at the example... as iÂ  am having doubts withÂ  the way they are doing it...&lt;br /&gt; hoping a help &lt;br /&gt;sajuat&lt;/div&gt;</description>
 <pubDate>Mon, 29 Aug 2005 15:06:21 +0200</pubDate>
 <dc:creator>sajuat</dc:creator>
 <guid isPermaLink="false">comment 24232 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064#comment-24231</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hi.&lt;br /&gt;&lt;br /&gt;There&amp;#039;s a sound mixer example application at Forum Nokia here:&lt;br /&gt;&lt;a href=&quot;http&amp;#58;//www.forum.nokia.com/info/sw.nokia.com/id/70a2bde5-9b14-41b3-89ae-198b0d8d380d/SoundMixer_Example_v1_0.zip.html&quot; target=&quot;_blank&quot;&gt;http://www.forum.nokia.com/info/sw.nokia.com/id/70a2bde5-9b14-41b3-89ae-198b0d8d380d/SoundMixer_Example_v1_0.zip.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;That uses CMdaAudioOutputStream to stream out audio data, but does some real-time sample mixing on raw PCM audio samples beforehand in order to combined them into one audio stream.&amp;nbsp; The application is quite nifty, it allows you the alter per-channel volume or master volume over all 16 channels and allows sound-clips to be loaded and played dynamically.&lt;br /&gt;&lt;br /&gt;If you want to mix multiple AU files using this code, you&amp;#039;ll have to convert the AU files to PCM.&amp;nbsp; Either do this before running the application (using Goldwave or some other audio conversion tool) to convert your audio files to PCM files, or alternatively, you could convert the AU files to PCM within your application.&amp;nbsp; Use the MMF to decode the AU file into a descriptor, then pass this PCM descriptor buffer into the sound mixing code.&lt;br /&gt;&lt;br /&gt;Symbian, as standard, doesn&amp;#039;t provide a standard API for sound mixing.&amp;nbsp; Indeed, most phones will not have sound mixing hardware available.&lt;br /&gt;&lt;br /&gt;Hope this helps.&lt;br /&gt;&lt;br /&gt;Regards.&lt;br /&gt;&lt;br /&gt;Andy.&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Fri, 26 Aug 2005 19:34:24 +0200</pubDate>
 <dc:creator>andrew.hayes</dc:creator>
 <guid isPermaLink="false">comment 24231 at http://www.newlc.com</guid>
</item>
<item>
 <title>Re: Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064#comment-24230</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;Hi !!!!&lt;br /&gt;&lt;br /&gt;I am not sure weather I have fully understood your question or not, I persume that you are asking &lt;br /&gt;&amp;quot;How can we mix two or more audio stream&amp;quot;, If this is the question then I am explaning below the &lt;br /&gt;mixing of the two audio stream (You Can Mix More Audio Stream),&lt;br /&gt;&lt;br /&gt;Step 1, &lt;br /&gt;&lt;br /&gt;Get the Raw data of the two files, (Example, of the sample 8bit and 8Kh, means one sample is of&lt;br /&gt;8bit)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 2 &lt;br /&gt;&lt;br /&gt;Let the two audio signal be A and B respectively, the range is between 0 and 255.Â  Where A and B are the&lt;br /&gt; Sample Values (Each raw data) And store the resultant into the Y&lt;br /&gt;&lt;br /&gt; If Both the samples Values are possitve&lt;br /&gt;&lt;br /&gt; Y = AÂ  +Â  B - A * B / 255 &lt;br /&gt;&lt;br /&gt;Where Y is the resultant signal which contains both signal A and B, merging two audio streams into single &lt;br /&gt;stream by this method solves theÂ  problem of overflow and information loss to an extent. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Â  Â If the range of 8-bit sampling is between -127 to 128 &lt;br /&gt;&lt;br /&gt;Â  Â If both A and B are negativeÂ  Â  Â  Â Y = A +B - (A * B / (-127)) &lt;br /&gt;Â  Â ElseÂ  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Y = A + B - A * B / 128 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Similarly for the nbit (ex 16bit data)&lt;br /&gt;&lt;br /&gt;Â  Â ForÂ  n-bit sampling audio signal &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Â  Â If both A and B are negativeÂ  Â  Â  Â Y = A + B - (A * BÂ  /Â  (-(2 pow(n-1) -1))) &lt;br /&gt;Â  Â ElseÂ  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â Y = A + B - (A * B /Â  (2 pow(n-1)) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 3.&lt;br /&gt;&lt;br /&gt;Add the Header to the Resultant (mixed) data and play back.&lt;br /&gt;&lt;br /&gt;If some thing is unclear and ambigious let me know.&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Ranjeet Gupta.&lt;br /&gt;&lt;/div&gt;</description>
 <pubDate>Fri, 26 Aug 2005 09:38:47 +0200</pubDate>
 <dc:creator>ranjeet</dc:creator>
 <guid isPermaLink="false">comment 24230 at http://www.newlc.com</guid>
</item>
<item>
 <title>Mixing Using au format...</title>
 <link>http://www.newlc.com/en/topic-10064</link>
 <description>&lt;div class=&quot;smf-content&quot;&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;http://www.newlc.com/en/topic-10064&quot;&gt;read more&lt;/a&gt;&lt;/p&gt;</description>
 <comments>http://www.newlc.com/en/topic-10064#comments</comments>
 <category domain="http://www.newlc.com/en/forums/audio">Audio</category>
 <pubDate>Thu, 25 Aug 2005 15:30:41 +0200</pubDate>
 <dc:creator>sajuat</dc:creator>
 <guid isPermaLink="false">10482 at http://www.newlc.com</guid>
</item>
</channel>
</rss>
