Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

67 lines (54 sloc) 1.386 kB
/*
* 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;
}
Jump to Line
Something went wrong with that request. Please try again.