-2

I'm trying to mix six sound clips together.

Imagine each clip is a single guitar string pluck sound and I want to mix them to produce a guitar chord.

Here, a clip is an array of real numbers in the range [-1,1], where each number is a mono sample.

double mixed_sample = mix(double sample1, ..., double sample6);

Please, implement mix!

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Nicolas Repiquet
  • 9,097
  • 2
  • 31
  • 53

1 Answers1

1

You have got to be kidding.

Mixing is simple addition of signals.

double mix(double s1, double s2, double s3, double s4, double s5, double s6)
{
  return (s1 + s2 + s3 + s4 + s5 + s6);
}

Next step is to provide individual channel gains.

double variable_mix(double s1, double s2, double s3, double s4, double s5, double s6,
                      double g1, double g2, double g3, double g4, double g5, double g6)
{
  return (s1*g1 + s2*g2 + s3*g3 + s4*g4 + s5*g5 + s6*g6);
}

Of course, this is kind of a pain in the ass to code, and the parameter-passing overhead will eat you alive, but this is basically what you have to do.

John R. Strohm
  • 7,547
  • 2
  • 28
  • 33
  • So, if only one string produce sound and the five other are silent, the amplitude of the mixed clip will be 1/6 the amplitude of the original clip? – Nicolas Repiquet Nov 16 '10 at 19:59
  • 1
    @Nicolas: that's correct - it's no different than a real guitar in the real world - a chord is louder than a single string. – Paul R Nov 16 '10 at 20:03
  • 1
    Don't forget the time offsets. Guitar strings are not strummed or picked at the same time. – Gilbert Le Blanc Nov 16 '10 at 20:10
  • @Gilbert, managing the playback of the individual string sample sequences that feed the mixer is a completely different issue. You are correct that it is important: if they are all started at exactly the same time, you will hear a single complex sound, not a chord. (This experiment is easy to do on an electronic keyboard, and VERY instructive. I think I first heard about it from something Wendy Carlos wrote.) – John R. Strohm Nov 16 '10 at 21:33
  • Thanks for the additional information. It's been years since I've done signal processing. – Gilbert Le Blanc Nov 17 '10 at 15:44