Browse Source

Clean up types in dsp/window.hpp. Fix createModel() in helpers.hpp if a member field exists called `model`. Fix `make install` path for plugins. Fail silently if a MIDI message >3 bytes is received.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
d6c8d84ede
4 changed files with 25 additions and 22 deletions
  1. +16
    -16
      include/dsp/window.hpp
  2. +4
    -4
      include/helpers.hpp
  3. +1
    -1
      plugin.mk
  4. +4
    -1
      src/rtmidi.cpp

+ 16
- 16
include/dsp/window.hpp View File

@@ -12,13 +12,13 @@ https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
*/ */
template <typename T> template <typename T>
inline T hann(T p) { inline T hann(T p) {
return 0.5f * (1.f - simd::cos(2*M_PI * p));
return T(0.5) * (1 - simd::cos(2 * T(M_PI) * p));
} }


/** Multiplies the Hann window by a signal `x` of length `len` in-place. */ /** Multiplies the Hann window by a signal `x` of length `len` in-place. */
inline void hannWindow(float *x, int len) { inline void hannWindow(float *x, int len) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
x[i] *= hann((float) i / (len - 1));
x[i] *= hann(float(i) / (len - 1));
} }
} }


@@ -29,14 +29,14 @@ A typical alpha value is 0.16.
template <typename T> template <typename T>
inline T blackman(T alpha, T p) { inline T blackman(T alpha, T p) {
return return
+ (1 - alpha) / 2.f
- 1 / 2.f * simd::cos(2*M_PI * p)
+ alpha / 2.f * simd::cos(4*M_PI * p);
+ (1 - alpha) / 2
- T(1) / 2 * simd::cos(2 * T(M_PI) * p)
+ alpha / 2 * simd::cos(4 * T(M_PI) * p);
} }


inline void blackmanWindow(float alpha, float *x, int len) { inline void blackmanWindow(float alpha, float *x, int len) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
x[i] *= blackman(alpha, (float) i / (len - 1));
x[i] *= blackman(alpha, float(i) / (len - 1));
} }
} }


@@ -47,15 +47,15 @@ https://en.wikipedia.org/wiki/Window_function#Blackman%E2%80%93Nuttall_window
template <typename T> template <typename T>
inline T blackmanNuttall(T p) { inline T blackmanNuttall(T p) {
return return
+ 0.3635819f
- 0.4891775f * simd::cos(2*M_PI * p)
+ 0.1365995f * simd::cos(4*M_PI * p)
- 0.0106411f * simd::cos(6*M_PI * p);
+ T(0.3635819)
- T(0.4891775) * simd::cos(2 * T(M_PI) * p)
+ T(0.1365995) * simd::cos(4 * T(M_PI) * p)
- T(0.0106411) * simd::cos(6 * T(M_PI) * p);
} }


inline void blackmanNuttallWindow(float *x, int len) { inline void blackmanNuttallWindow(float *x, int len) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
x[i] *= blackmanNuttall((float) i / (len - 1));
x[i] *= blackmanNuttall(float(i) / (len - 1));
} }
} }


@@ -65,15 +65,15 @@ https://en.wikipedia.org/wiki/Window_function#Blackman%E2%80%93Harris_window
template <typename T> template <typename T>
inline T blackmanHarris(T p) { inline T blackmanHarris(T p) {
return return
+ 0.35875f
- 0.48829f * simd::cos(2*M_PI * p)
+ 0.14128f * simd::cos(4*M_PI * p)
- 0.01168f * simd::cos(6*M_PI * p);
+ T(0.35875)
- T(0.48829) * simd::cos(2 * T(M_PI) * p)
+ T(0.14128) * simd::cos(4 * T(M_PI) * p)
- T(0.01168) * simd::cos(6 * T(M_PI) * p);
} }


inline void blackmanHarrisWindow(float *x, int len) { inline void blackmanHarrisWindow(float *x, int len) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
x[i] *= blackmanHarris((float) i / (len - 1));
x[i] *= blackmanHarris(float(i) / (len - 1));
} }
} }




+ 4
- 4
include/helpers.hpp View File

@@ -20,19 +20,19 @@ template <class TModule, class TModuleWidget, typename... Tags>
plugin::Model *createModel(const std::string &slug) { plugin::Model *createModel(const std::string &slug) {
struct TModel : plugin::Model { struct TModel : plugin::Model {
engine::Module *createModule() override { engine::Module *createModule() override {
TModule *m = new TModule;
engine::Module *m = new TModule;
m->model = this; m->model = this;
return m; return m;
} }
app::ModuleWidget *createModuleWidget() override { app::ModuleWidget *createModuleWidget() override {
TModule *m = new TModule; TModule *m = new TModule;
m->model = this;
TModuleWidget *mw = new TModuleWidget(m);
m->engine::Module::model = this;
app::ModuleWidget *mw = new TModuleWidget(m);
mw->model = this; mw->model = this;
return mw; return mw;
} }
app::ModuleWidget *createModuleWidgetNull() override { app::ModuleWidget *createModuleWidgetNull() override {
TModuleWidget *mw = new TModuleWidget(NULL);
app::ModuleWidget *mw = new TModuleWidget(NULL);
mw->model = this; mw->model = this;
return mw; return mw;
} }


+ 1
- 1
plugin.mk View File

@@ -71,7 +71,7 @@ endif
cd dist && zip -q -9 -r $(SLUG)-$(VERSION)-$(ARCH).zip $(SLUG) cd dist && zip -q -9 -r $(SLUG)-$(VERSION)-$(ARCH).zip $(SLUG)


install: dist install: dist
cp dist/$(SLUG)-$(VERSION)-$(ARCH).zip $(RACK_USER_DIR)/plugins/
cp dist/$(SLUG)-$(VERSION)-$(ARCH).zip $(RACK_USER_DIR)/plugins-v1/


.PHONY: clean dist .PHONY: clean dist
.DEFAULT_GOAL := all .DEFAULT_GOAL := all

+ 4
- 1
src/rtmidi.cpp View File

@@ -39,7 +39,10 @@ struct RtMidiInputDevice : midi::InputDevice {
if (!midiInputDevice) if (!midiInputDevice)
return; return;


assert(message->size() <= 3);
// Users have reported that some MIDI devices can send messages >3 bytes. I don't know how this is possible, so just reject the message.
if (message->size() > 3)
return;

midi::Message msg; midi::Message msg;
msg.size = message->size(); msg.size = message->size();
for (int i = 0; i < msg.size; i++) { for (int i = 0; i < msg.size; i++) {


Loading…
Cancel
Save