Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 67 lines (54 sloc) 1.386 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/*
* SampleMixer.cpp
* Sin
*
* Created by blucia0a on 8/6/11.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/

#include "SampleMixer.h"
#include <stdlib.h>
#include <string.h>
SampleMixer::SampleMixer(){

  numSources = 0;
  srcs = (SampleSource **)malloc(sizeof(SampleSource *) * MIXER_MAX_SRCS);
  memset(srcs,0,sizeof(SampleSource *) * MIXER_MAX_SRCS);
  this->amp = 1.0;
   
}

void SampleMixer::Mix(int numSources, SampleSource **srcs, float *out){

out[0] = 0.0; //left
out[1] = 0.0; //right
for(int i = 0; i < numSources; i++){
float o[2];
srcs[i]->getNextSample(o);
out[0] = out[0] + o[0];// > 1.0 ? 0.9 : out[0] + o[0];
out[1] = out[1] + o[1];// > 1.0 ? 0.9 : out[1] + o[1];
}
out[0] /= (float)numSources;
out[1] /= (float)numSources;

        out[0] *= this->amp;
        out[1] *= this->amp;

}

void SampleMixer::getNextSample(float *out){
  this->Mix(this->numSources,this->srcs,out);
}

void SampleMixer::setAmpVal(float newamp){
  this->amp = newamp;
}

bool SampleMixer::Add(SampleSource *s){
  for(int i = 0; i < MIXER_MAX_SRCS; i++){
    if(this->srcs[i] == NULL){
      this->srcs[this->numSources++] = s;
      return true;
    }
  }
  return false;
}


SampleSource *SampleMixer::Remove(unsigned i){
  SampleSource *r = NULL;
  if(this->srcs[i] == NULL){
    r = this->srcs[i];
    this->srcs[i] = NULL;
  }
  return r;
}
Something went wrong with that request. Please try again.