I am trying to make a sequence synthesizer and feel like I am so close to the finish line but I am having a weird issue. When there are no oscillators feeding the buffer its silent, like it should be. But once even one oscillator starts feeding the buffer
there is a lot of noise that is also played out. I am testing this in exclusive event driven rendering so I believe I am filling up the buffer properly but perhaps it takes too long to fill the buffer and that is creating underrun?
hr = _RenderClient->GetBuffer(_BufferSizePerPeriod, &data);
if (SUCCEEDED(hr))
{
soundOutputPtr->audioOut((float *) data, _BufferSizePerPeriod, channels, 0, 0);
hr = _RenderClient->ReleaseBuffer(_BufferSizePerPeriod, 0);
}
Here is the code that passes the buffer to get filled
for (int i = 0; i < bufferSize/nChannels; i++){
double sample = 0;
int it = waves.size();
for (int j = 0; j < it; j++){
float val = waves[j].getSample();
soundBuffers[j][i] = val;
sample += val;
}
output[i*nChannels ] = sample;
output[i*nChannels + 1] = sample;
soundBuffer[i] = sample;
}
and this fills the buffer.
waves is a vector filled with oscillators of various types, sine, sawtooth etc...
float oscillator::getSample(){
phase += phaseAdder;
while (phase > TWO_PI) phase -= TWO_PI;
if (type == sineWave){
return sin(phase) * volume;
} else if (type == squareWave){
return (sin(phase) > 0 ? 1 : -1) * volume;
} else if (type == triangleWave){
float pct = phase / TWO_PI;
return ( pct < 0.5 ? ofMap(pct, 0, 0.5, -1, 1) : ofMap(pct, 0.5, 1.0, 1, -1)) * volume;
} else if (type == sawWave){
float pct = phase / TWO_PI;
return ofMap(pct, 0, 1, -1, 1) * volume;
} else if (type == sawWaveReverse){
float pct = phase / TWO_PI;
return ofMap(pct, 0, 1, 1, -1) * volume;
}
}
I can't really find anything as to why there would be a lot of white noise that is being played out so underrun is my only guess. has anyone else experienced this?