Soft sound mixing implementation

Source: Internet
Author: User
Hi !!!!
I am not sure weather I have fully understood your question or not, I persume that you are asking
"How can we mix two or more audio stream", if this is the question then I am explaning below
Mixing of the two audio stream (you can mix more audio stream ),
Step 1,
Get the raw data of the two files, (example, of the sample 8bit and 8kh, means one sample is
8bit)
Step 2
Let the two audio signal be A and B respectively, the range is between 0 and 255. where A and B are
Sample values (each raw data) and store the resultant into the y
If both the Samples values are possitve
Y = a + B-a * B/255

Where Y is the resultant signal which contains both signal a and B, merging two audio streams into single
Stream by this method solves the problem of overflow and information loss to an extent.
If the range of 8-bit sampling is between-127 to 128
If both A and B are negative
Y = a + B-(A * B/(-127 ))
Else
Y = a + B-a * B/128
Similarly for the nbit (ex 16bit data)
For N-bit sampling Audio Signal
If both A and B are negative
Y = a + B-(A * B/(-(2 POW (n-1)-1 )))
Else
Y = a + B-(A * B/(2 POW (n-1 ))
Step 3.
Add the header to the resultant (mixed) data and play back.
If some thing is unclear and ambigious let me know.
Regards
Ranjeet Gupta.
There is also a simple C Program Schematic Code But it includes the core Algorithm :
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Include <math. h>
Int main (INT argc, char * argv []) {
Char mixname [255];
File * pcm1, * pcm2, * mix;
Char sample1, sample2;
Int value;
Pcm1 = fopen (argv [1], "R ");
Pcm2 = fopen (argv [2], "R ");

Strcpy (mixname, argv [1]);
Strcat (mixname, "_temp.wav ");
Mix = fopen (mixname, "W ");
While (! Feof (pcm1 )){
Sample1 = fgetc (pcm1 );
Sample2 = fgetc (pcm2 );

If (sample1 <0) & (sample2 <0 )){
Value = sample1 + sample2-(sample1 * sample2/-(POW (2,16-1)-1 ));
} Else {
Value = sample1 + sample2-(sample1 * sample2/(POW (2,16-1)-1 ));
}
Fputc (value, mix );
}
Fclose (pcm1 );
Fclose (pcm2 );
Fclose (MIX );
Return 0;
}

In addition, if you only use Symbian for sound mixing, there is also a soundmixer examples on the official website of Nokia.

Http://www.forum.nokia.com/info/sw.nokia.com/id/70a2bde5-9b14-41b3-89ae-198b0d8d380d/SoundMixer_Example_v1_0.zip.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.