Mixing implemented on Symbian 6.1 is a very troublesome issue, because the program can only play one piece of music at the same time, and the program needs to implement the mixing by itself. Below is a sound mixing Implementation of PCM pulse-coded audio signals I found on newlc, which contains a key audio mixing algorithm!
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 negativeY = a + B-(A * B/(-127 ))
ElseY = a + B-a * B/128
Similarly for the nbit (ex 16bit data)
For N-bit sampling Audio Signal
If both A and B are negativeY = a + B-(A * B/(-(2 POW (n-1)-1 )))
ElseY = 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 indicating the code, but it contains 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