Float based voice summing

pull/1/head
asb2m10 11 years ago
parent f83a12b08a
commit 6637400d47
  1. BIN
      Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate
  2. 36
      Source/PluginProcessor.cpp
  3. 6
      Source/PluginProcessor.h

@ -85,7 +85,7 @@ void DexedAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
extra_buf_size = 0; extra_buf_size = 0;
workBlockSize = samplesPerBlock; workBlockSize = samplesPerBlock;
workBlock = new SInt16[samplesPerBlock]; workBlock = new float[samplesPerBlock];
keyboardState.reset(); keyboardState.reset();
@ -129,7 +129,7 @@ void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& mi
if ( numSamples > workBlockSize ) { if ( numSamples > workBlockSize ) {
delete workBlock; delete workBlock;
workBlockSize = numSamples; workBlockSize = numSamples;
workBlock = new SInt16[workBlockSize]; workBlock = new float[workBlockSize];
} }
// Now pass any incoming midi messages to our keyboard state object, and let it // Now pass any incoming midi messages to our keyboard state object, and let it
@ -169,10 +169,7 @@ void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& mi
processSamples(block, workBlock); processSamples(block, workBlock);
for(int i = 0; i < block; i++ ) { for(int i = 0; i < block; i++ ) {
float f = ((float) workBlock[i+samplePos]) / (float) 32768; channelData[i+samplePos] = workBlock[i];
if( f > 1 ) f = 1;
if( f < -1 ) f = -1;
channelData[i+samplePos] = (double) f;
} }
samplePos += block; samplePos += block;
@ -347,7 +344,7 @@ void DexedAudioProcessor::keyup(uint8_t pitch) {
} }
void DexedAudioProcessor::processSamples(int n_samples, int16_t *buffer) { void DexedAudioProcessor::processSamples(int n_samples, float *buffer) {
int i; int i;
for (i = 0; i < n_samples && i < extra_buf_size; i++) { for (i = 0; i < n_samples && i < extra_buf_size; i++) {
buffer[i] = extra_buf[i]; buffer[i] = extra_buf[i];
@ -359,11 +356,14 @@ void DexedAudioProcessor::processSamples(int n_samples, int16_t *buffer) {
extra_buf_size -= n_samples; extra_buf_size -= n_samples;
return; return;
} }
for (; i < n_samples; i += N) { for (; i < n_samples; i += N) {
AlignedBuf<int32_t, N> audiobuf; AlignedBuf<int32_t, N> audiobuf;
float sumbuf[N];
for (int j = 0; j < N; ++j) { for (int j = 0; j < N; ++j) {
audiobuf.get()[j] = 0; audiobuf.get()[j] = 0;
sumbuf[j] = 0;
} }
int32_t lfovalue = lfo.getsample(); int32_t lfovalue = lfo.getsample();
int32_t lfodelay = lfo.getdelay(); int32_t lfodelay = lfo.getdelay();
@ -371,18 +371,24 @@ void DexedAudioProcessor::processSamples(int n_samples, int16_t *buffer) {
if (voices[note].live) { if (voices[note].live) {
voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers); voices[note].dx7_note->compute(audiobuf.get(), lfovalue, lfodelay, &controllers);
} }
for (int j=0; j < N; ++j) {
int32_t val = audiobuf.get()[j] >> 4;
int clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff : val >> 9;
float f = ((float) clip_val) / (float) 32768;
if( f > 1 ) f = 1;
if( f < -1 ) f = -1;
sumbuf[j] += f;
audiobuf.get()[j] = 0;
}
} }
int jmax = n_samples - i; int jmax = n_samples - i;
for (int j = 0; j < N; ++j) { for (int j = 0; j < N; ++j) {
int32_t val = audiobuf.get()[j] >> 4;
int clip_val = val < -(1 << 24) ? 0x8000 : val >= (1 << 24) ? 0x7fff :
val >> 9;
// val = val & 0x0FFF7000;
// TODO: maybe some dithering?
if (j < jmax) { if (j < jmax) {
buffer[i + j] = clip_val; buffer[i + j] = sumbuf[j];
} else { } else {
extra_buf[j - jmax] = clip_val; extra_buf[j - jmax] = sumbuf[j];
} }
} }
} }

@ -56,10 +56,10 @@ class DexedAudioProcessor : public AudioProcessor, public AsyncUpdater
bool sustain; bool sustain;
// Extra buffering for when GetSamples wants a buffer not a multiple of N // Extra buffering for when GetSamples wants a buffer not a multiple of N
int16_t extra_buf[N]; float extra_buf[N];
int extra_buf_size; int extra_buf_size;
SInt16 *workBlock; float *workBlock;
int workBlockSize; int workBlockSize;
int currentProgram; int currentProgram;
@ -87,7 +87,7 @@ class DexedAudioProcessor : public AudioProcessor, public AsyncUpdater
void processMidiMessage(MidiMessage *msg); void processMidiMessage(MidiMessage *msg);
void keydown(uint8_t pitch, uint8_t velo); void keydown(uint8_t pitch, uint8_t velo);
void keyup(uint8_t pitch); void keyup(uint8_t pitch);
void processSamples(int n_samples, int16_t *buffer); void processSamples(int n_samples, float *buffer);
/** /**
* this is called from the Audio thread to tell * this is called from the Audio thread to tell

Loading…
Cancel
Save