Mixing Using au format...

Login to reply to this topic.
Thu, 2005-08-25 14:30
Joined: 2005-01-24
Forum posts: 57
Hi,
how can i do sound mixing with au files?...
thanking in adv
sajuat

"I dont know with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."
.... Albert Einstein


Fri, 2005-08-26 08:38
Joined: 2005-07-25
Forum posts: 31
Re: Mixing Using au format...
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 the
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 of
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 the
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.
Fri, 2005-08-26 18:34
Joined: 2005-01-24
Forum posts: 76
Re: Mixing Using au format...
Hi.

There's a sound mixer example application at Forum Nokia here:
http://www.forum.nokia.com/info/sw.nokia.com/id/70a2bde5-9b14-41b3-89ae-198b0d8d380d/SoundMixer_Example_v1_0.zip.html

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.  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.

If you want to mix multiple AU files using this code, you'll have to convert the AU files to PCM.  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.  Use the MMF to decode the AU file into a descriptor, then pass this PCM descriptor buffer into the sound mixing code.

Symbian, as standard, doesn't provide a standard API for sound mixing.  Indeed, most phones will not have sound mixing hardware available.

Hope this helps.

Regards.

Andy.
Mon, 2005-08-29 14:06
Joined: 2005-01-24
Forum posts: 57
Re: Mixing Using au format...
Hi friends ,
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...
hoping a help
sajuat

"I dont know with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."
.... Albert Einstein

Tue, 2005-08-30 14:03
Joined: 2005-07-25
Forum posts: 31
Re: Mixing Using au format...
Sujat

First let me know that how much file you have to mix ?
means what is the max number of stream which you are looking to mix as a single stream,

Regards
Ranjeet Gupta

Tue, 2005-08-30 15:00
Joined: 2005-07-25
Forum posts: 31
Re: Mixing Using au format...
Yes I was wondering on the number of files, Well what i can say that if you have to only mix arround the
Max three files (Simultaneously at some senario) then i will suggest implement the equation which I have
given to you, Yes the above algo is not going to give the best output for more then 5 files,

second if you implemnet the above equation then let me tell you, that there is over head as we are
operating on the each sample values,  If the overhead is not the constraint then try it and let us know
what the diffculties you are facing while implementing.

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.

Regards
Ranjeet Gupta

Fri, 2005-10-07 12:19
Joined: 2005-10-07
Forum posts: 1
Re: Mixing Using au format...
Hi all,

i'm trying to do something similar, and i almost did it.
Starting from 2 mp3, i decompress them to 2 raw PCM wav files with no header with lame :
> lame --decode -t file1.mp3
> lame --decode -t file2.mp3
NB : my mp3s are 16bit 44.1


which generates file1.mp3.wav and file2.mp3.wav

then i use the following program (i'm a newbie) :

Code:
#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;
}

which generates file1.mp3.wav_temp.wav


and i use lame back again to generate an mp3 :

> lame -s 44.1 s file1.mp3.wav_temp.wav


Problem : This works like a dream excpet that the sound has a tendency to become saturated

How to solve this saturation problem?



NB : i don't have any error checking for the moment and this program implies that file1 is shorter than file2 but it's just a beginning
  • Login to reply to this topic.