2

Say we got 2 different music chunks in SDL. Currently we are not sure on how to mix them into one single audio with noise and distortion is filtered. Currently try to mix in this format which is wrong.

  if( Mix_PlayChannel( 1, test1, 0 ) == -1 )
                        {
                            return 1;
                        }

                        if( Mix_PlayChannel( 2, test2, 0 ) == -1 )
                        {
                            return 1;
                        } 
1
  if( Mix_PlayChannel( 1, test1, 0 ) == -1 ) // Tests for error return value -1
  {
      return 1; // Returns 1 to something?
  }

  if( Mix_PlayChannel( 2, test2, 0 ) == -1 ) // Tests for error return value -1
  {
      return 1; // Returns 1 to something?
  } 

Without seeing what your function is the above code seems like it would not be playing sound at all, because it only tests for error return values of Mix_PlayChannel and in the case of an error (i.e. Mix_PlayChannel returns -1), the function returns 1/True (and exits already in the first if-block).

See: http://sdl.beuc.net/sdl.wiki/Mix_PlayChannel

You don't need to even grab (or assign) the return value to play the sound. The return value, if the Mix_PlayChannel function doesn't fail, is the channel number (in your case 1 or 2).

What you could write is just:

Mix_PlayChannel(1, test1, 0);
Mix_PlayChannel(2, test2, 0);

Or if you want to test for errors:

int channel;

channel = Mix_PlayChannel(1, test1, 0);
if(channel == -1) {
    fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
}

channel = Mix_PlayChannel(2, test2, 0);
if(channel == -1) {
    fprintf(stderr, "Unable to play WAV file: %s\n", Mix_GetError());
}

There are some more examples here (note the special functions for playing music, instead of just sound files / SFX):
http://people.cs.clemson.edu/~malloy/courses/3dgames-2007/tutor/web/audio/audio.html

0

My guess is that this is a programming question. I'm not sure you'll find an answer here, because most(?) of us are sound designers or composers. This is a technical question you might want to ask in the forum of SDL, whatever that may be.

But overall, mixing signals that are of maximum loudness (0dBFS) will result in distortion. So my guess is that you need to somehow lower the input of the mixer resulting in more headroom and no clipping or distortion.

Good luck! Arnoud

  • Why is maximum loudness term as 0db isnt that is silent? – biz14 Oct 10 '13 at 15:08
  • 2
    It refers to 0dBFS - ie the dB scale used for DSP. 0dBFS is the maximum. Any yes, I don't use SDL, but generally you need to multiply each signal by 0.5 to mix the 2 together. – Mark Durham Oct 10 '13 at 20:45
  • Or apply some sort of rolloff or other limiting mechanism, rather than allowing the signal to clip or overflow. – fluffy Dec 7 '14 at 0:38
  • With FS, I like to think of it as "room left." At 0dBFS, there is no more room for dynamic range, and there will be clipping. -8dBFS means you have 8dB left before clipping. – user22688 Aug 24 '17 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.