Browse Source

Use dsp:: namespace. Automatically include dsp headers in rack.hpp.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
cb0f3e5100
18 changed files with 93 additions and 43 deletions
  1. +9
    -3
      include/dsp/common.hpp
  2. +0
    -2
      include/dsp/decimator.hpp
  3. +3
    -1
      include/dsp/digital.hpp
  4. +4
    -1
      include/dsp/filter.hpp
  5. +4
    -1
      include/dsp/fir.hpp
  6. +5
    -1
      include/dsp/frame.hpp
  7. +5
    -1
      include/dsp/minblep.hpp
  8. +5
    -2
      include/dsp/ode.hpp
  9. +7
    -3
      include/dsp/resampler.hpp
  10. +5
    -1
      include/dsp/ringbuffer.hpp
  11. +0
    -2
      include/dsp/samplerate.hpp
  12. +3
    -1
      include/dsp/vumeter.hpp
  13. +10
    -0
      include/rack.hpp
  14. +15
    -0
      include/rack0.hpp
  15. +10
    -12
      src/Core/AudioInterface.cpp
  16. +1
    -2
      src/Core/MIDICCToCVInterface.cpp
  17. +7
    -9
      src/Core/MIDIToCVInterface.cpp
  18. +0
    -1
      src/Core/QuadMIDIToCVInterface.cpp

include/dsp/functions.hpp → include/dsp/common.hpp View File

@@ -3,6 +3,11 @@


namespace rack {
namespace dsp {


static const float FREQ_C4 = 261.6256f;
static const float FREQ_A4 = 440.0000f;


/** The normalized sinc function. https://en.wikipedia.org/wiki/Sinc_function */
@@ -42,13 +47,14 @@ inline float exponentialBipolar(float b, float x) {
return (std::pow(b, x) - std::pow(b, -x)) / a;
}

inline float gainToDb(float gain) {
return std::log10(gain) * 20.f;
inline float amplitudeToDb(float amp) {
return std::log10(amp) * 20.f;
}

inline float dbToGain(float db) {
inline float dbToAmplitude(float db) {
return std::pow(10.f, db / 20.f);
}


} // namespace dsp
} // namespace rack

+ 0
- 2
include/dsp/decimator.hpp View File

@@ -1,2 +0,0 @@
#pragma once
#include "resampler.hpp"

+ 3
- 1
include/dsp/digital.hpp View File

@@ -1,8 +1,9 @@
#pragma once
#include "math.hpp"
#include "dsp/common.hpp"


namespace rack {
namespace dsp {


/** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */
@@ -102,4 +103,5 @@ struct PulseGenerator {
};


} // namespace dsp
} // namespace rack

+ 4
- 1
include/dsp/filter.hpp View File

@@ -1,8 +1,10 @@
#pragma once
#include "math.hpp"
#include "dsp/common.hpp"


namespace rack {
namespace dsp {


struct RCFilter {
float c = 0.f;
@@ -81,4 +83,5 @@ struct ExponentialFilter {
};


} // namespace dsp
} // namespace rack

+ 4
- 1
include/dsp/fir.hpp View File

@@ -1,9 +1,11 @@
#pragma once
#include "dsp/functions.hpp"
#include "dsp/common.hpp"
#include <pffft.h>


namespace rack {
namespace dsp {


/** Performs a direct sum convolution */
inline float convolveNaive(const float *in, const float *kernel, int len) {
@@ -145,4 +147,5 @@ struct RealTimeConvolver {
};


} // namespace dsp
} // namespace rack

+ 5
- 1
include/dsp/frame.hpp View File

@@ -1,8 +1,10 @@
#pragma once
#include <stdlib.h>
#include "dsp/common.hpp"


namespace rack {
namespace dsp {


/** Useful for storing arrays of samples in ring buffers and casting them to `float*` to be used by interleaved processors, like SampleRateConverter */
template <size_t CHANNELS>
@@ -10,4 +12,6 @@ struct Frame {
float samples[CHANNELS];
};


} // namespace dsp
} // namespace rack

+ 5
- 1
include/dsp/minblep.hpp View File

@@ -1,8 +1,10 @@
#pragma once
#include "math.hpp"
#include "dsp/common.hpp"


namespace rack {
namespace dsp {


// Pre-made minBLEP samples in minBLEP.cpp
extern const float minblep_16_32[];
@@ -33,4 +35,6 @@ struct MinBLEP {
}
};


} // namespace dsp
} // namespace rack

+ 5
- 2
include/dsp/ode.hpp View File

@@ -1,8 +1,10 @@
#pragma once
#include "dsp/common.hpp"


namespace rack {
namespace ode {
namespace dsp {


/** The callback function `f` in each of these stepping functions must have the signature

@@ -84,5 +86,6 @@ void stepRK4(float t, float dt, float x[], int len, F f) {
}
}

} // namespace ode

} // namespace dsp
} // namespace rack

+ 7
- 3
include/dsp/resampler.hpp View File

@@ -1,13 +1,16 @@
#pragma once
#include "frame.hpp"
#include "ringbuffer.hpp"
#include "fir.hpp"
#include "dsp/common.hpp"
#include "dsp/frame.hpp"
#include "dsp/ringbuffer.hpp"
#include "dsp/fir.hpp"
#include <assert.h>
#include <string.h>
#include <speex/speex_resampler.h>


namespace rack {
namespace dsp {


template<int CHANNELS>
struct SampleRateConverter {
@@ -170,4 +173,5 @@ struct Upsampler {
};


} // namespace dsp
} // namespace rack

+ 5
- 1
include/dsp/ringbuffer.hpp View File

@@ -1,9 +1,11 @@
#pragma once
#include "common.hpp"
#include "dsp/common.hpp"
#include <string.h>


namespace rack {
namespace dsp {


/** A simple cyclic buffer.
S must be a power of 2.
@@ -196,4 +198,6 @@ struct AppleRingBuffer {
}
};


} // namespace dsp
} // namespace rack

+ 0
- 2
include/dsp/samplerate.hpp View File

@@ -1,2 +0,0 @@
#pragma once
#include "resampler.hpp"

+ 3
- 1
include/dsp/vumeter.hpp View File

@@ -1,8 +1,9 @@
#pragma once
#include "math.hpp"
#include "dsp/common.hpp"


namespace rack {
namespace dsp {


struct VUMeter {
@@ -28,4 +29,5 @@ struct VUMeter {
};


} // namespace dsp
} // namespace rack

+ 10
- 0
include/rack.hpp View File

@@ -80,6 +80,16 @@
#include "plugin/Model.hpp"
#include "plugin/callbacks.hpp"

#include "dsp/common.hpp"
#include "dsp/digital.hpp"
#include "dsp/filter.hpp"
#include "dsp/fir.hpp"
#include "dsp/frame.hpp"
#include "dsp/minblep.hpp"
#include "dsp/ode.hpp"
#include "dsp/resampler.hpp"
#include "dsp/ringbuffer.hpp"
#include "dsp/vumeter.hpp"

namespace rack {



+ 15
- 0
include/rack0.hpp View File

@@ -147,4 +147,19 @@ DEPRECATED inline float engineGetSampleTime() {
return context()->engine->getSampleTime();
}

////////////////////
// dsp
////////////////////

using namespace dsp;

inline float gainToDb(float gain) {
return dsp::amplitudeToDb(gain);
}

inline float dbToGain(float db) {
return dsp::dbToAmplitude(db);
}


} // namespace rack

+ 10
- 12
src/Core/AudioInterface.cpp View File

@@ -1,7 +1,5 @@
#include "Core.hpp"
#include "audio.hpp"
#include "dsp/resampler.hpp"
#include "dsp/ringbuffer.hpp"
#include <mutex>
#include <chrono>
#include <thread>
@@ -23,9 +21,9 @@ struct AudioInterfaceIO : audio::IO {
std::mutex audioMutex;
std::condition_variable audioCv;
// Audio thread produces, engine thread consumes
DoubleRingBuffer<Frame<AUDIO_INPUTS>, (1<<15)> inputBuffer;
dsp::DoubleRingBuffer<dsp::Frame<AUDIO_INPUTS>, (1<<15)> inputBuffer;
// Audio thread consumes, engine thread produces
DoubleRingBuffer<Frame<AUDIO_OUTPUTS>, (1<<15)> outputBuffer;
dsp::DoubleRingBuffer<dsp::Frame<AUDIO_OUTPUTS>, (1<<15)> outputBuffer;
bool active = false;

~AudioInterfaceIO() {
@@ -46,7 +44,7 @@ struct AudioInterfaceIO : audio::IO {
for (int i = 0; i < frames; i++) {
if (inputBuffer.full())
break;
Frame<AUDIO_INPUTS> inputFrame;
dsp::Frame<AUDIO_INPUTS> inputFrame;
memset(&inputFrame, 0, sizeof(inputFrame));
memcpy(&inputFrame, &input[numInputs * i], numInputs * sizeof(float));
inputBuffer.push(inputFrame);
@@ -62,7 +60,7 @@ struct AudioInterfaceIO : audio::IO {
if (audioCv.wait_for(lock, timeout, cond)) {
// Consume audio block
for (int i = 0; i < frames; i++) {
Frame<AUDIO_OUTPUTS> f = outputBuffer.shift();
dsp::Frame<AUDIO_OUTPUTS> f = outputBuffer.shift();
for (int j = 0; j < numOutputs; j++) {
output[numOutputs*i + j] = clamp(f.samples[j], -1.f, 1.f);
}
@@ -112,12 +110,12 @@ struct AudioInterface : Module {
int lastNumOutputs = -1;
int lastNumInputs = -1;

SampleRateConverter<AUDIO_INPUTS> inputSrc;
SampleRateConverter<AUDIO_OUTPUTS> outputSrc;
dsp::SampleRateConverter<AUDIO_INPUTS> inputSrc;
dsp::SampleRateConverter<AUDIO_OUTPUTS> outputSrc;

// in rack's sample rate
DoubleRingBuffer<Frame<AUDIO_INPUTS>, 16> inputBuffer;
DoubleRingBuffer<Frame<AUDIO_OUTPUTS>, 16> outputBuffer;
dsp::DoubleRingBuffer<dsp::Frame<AUDIO_INPUTS>, 16> inputBuffer;
dsp::DoubleRingBuffer<dsp::Frame<AUDIO_OUTPUTS>, 16> outputBuffer;

AudioInterface() {
setup(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
@@ -177,7 +175,7 @@ void AudioInterface::step() {
}

// Take input from buffer
Frame<AUDIO_INPUTS> inputFrame;
dsp::Frame<AUDIO_INPUTS> inputFrame;
if (!inputBuffer.empty()) {
inputFrame = inputBuffer.shift();
}
@@ -195,7 +193,7 @@ void AudioInterface::step() {
if (audioIO.active && audioIO.numOutputs > 0) {
// Get and push output SRC frame
if (!outputBuffer.full()) {
Frame<AUDIO_OUTPUTS> outputFrame;
dsp::Frame<AUDIO_OUTPUTS> outputFrame;
for (int i = 0; i < AUDIO_OUTPUTS; i++) {
outputFrame.samples[i] = inputs[AUDIO_INPUT + i].getVoltage() / 10.f;
}


+ 1
- 2
src/Core/MIDICCToCVInterface.cpp View File

@@ -1,6 +1,5 @@
#include "Core.hpp"
#include "midi.hpp"
#include "dsp/filter.hpp"


struct MIDICCToCVInterface : Module {
@@ -20,7 +19,7 @@ struct MIDICCToCVInterface : Module {

midi::InputQueue midiInput;
int8_t ccs[128];
ExponentialFilter ccFilters[16];
dsp::ExponentialFilter ccFilters[16];

int learningId = -1;
int learnedCcs[16] = {};


+ 7
- 9
src/Core/MIDIToCVInterface.cpp View File

@@ -1,7 +1,5 @@
#include "Core.hpp"
#include "midi.hpp"
#include "dsp/digital.hpp"
#include "dsp/filter.hpp"

#include <algorithm>

@@ -35,14 +33,14 @@ struct MIDIToCVInterface : Module {
midi::InputQueue midiInput;

uint8_t mod = 0;
ExponentialFilter modFilter;
dsp::ExponentialFilter modFilter;
uint16_t pitch = 8192;
ExponentialFilter pitchFilter;
PulseGenerator retriggerPulse;
PulseGenerator clockPulses[2];
PulseGenerator startPulse;
PulseGenerator stopPulse;
PulseGenerator continuePulse;
dsp::ExponentialFilter pitchFilter;
dsp::PulseGenerator retriggerPulse;
dsp::PulseGenerator clockPulses[2];
dsp::PulseGenerator startPulse;
dsp::PulseGenerator stopPulse;
dsp::PulseGenerator continuePulse;
int clock = 0;
int divisions[2];



+ 0
- 1
src/Core/QuadMIDIToCVInterface.cpp View File

@@ -1,6 +1,5 @@
#include "Core.hpp"
#include "midi.hpp"
#include "dsp/digital.hpp"

#include <algorithm>



Loading…
Cancel
Save