Home | ER-101 | ER-102 | ER-301 | Wiki | Contact

301 + Max/MSP (Gen~)

So I’ve talked a little about this with Brian on the back channel but wanting to put it out here. Some of you may or may not know that inside Max/MSP is a low level dsp framework called Gen

Gen~ has code export to a .cpp file which includes dsp code in c++ format.

Brian has taken a look at it and says that this shouldn’t be much hassle at all to take Gen~ and make it into units. The beauty of this is that there are ALOT of Gen fully functional examples already and a neat internal object in Gen~ called codebox that you can simply drop DSP code into (which you can find all over the internet) give it some I/O and you’re away.

Essentially this just gives another possibility for users to code there own units for out too much heavy lifting. Right now I’m sending Gen code to the Mod Devices MOD Duo (similar power to the 301) and the Rebel Technology Owl (about the same power of just one or two units) examples here

I’d like to open the floor for further discussion. Perhaps Brian could chime in here with discussion about support beyond the SDK, perhaps a Tool Chain of sorts for some of the more popular languages?

15 Likes

Yes. :clap:

For example here is a simple 2sec delay in Gen~ (see the code generation on the right hand side, happens in real-time)

2 Likes

and here is the exported C++

include “gen_exported.h”

namespace gen_exported {

/*******************************************************************************************************************
Cycling '74 License for Max-Generated Code for Export
Copyright © 2016 Cycling '74
The code that Max generates automatically and that end users are capable of exporting and using, and any
associated documentation files (the “Software”) is a work of authorship for which Cycling '74 is the author
and owner for copyright purposes. A license is hereby granted, free of charge, to any person obtaining a
copy of the Software (“Licensee”) to use, copy, modify, merge, publish, and distribute copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The Software is licensed to Licensee only for non-commercial use. Users who wish to make commercial use of the
Software must contact the copyright owner to determine if a license for commercial use is available, and the
terms and conditions for same, which may include fees or royalties. For commercial use, please send inquiries
to licensing (at) cycling74.com. The determination of whether a use is commercial use or non-commercial use is based
upon the use, not the user. The Software may be used by individuals, institutions, governments, corporations, or
other business whether for-profit or non-profit so long as the use itself is not a commercialization of the
materials or a use that generates or is intended to generate income, revenue, sales or profit.
The above copyright notice and this license shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*******************************************************************************************************************/

// global noise generator
Noise noise;
static const int GENLIB_LOOPCOUNT_BAIL = 100000;

// The State struct contains all the state and procedures for the gendsp kernel
typedef struct State {
CommonState __commonstate;
Delay m_delay_3;
Delay m_delay_4;
int __exception;
int vectorsize;
t_sample m_delaytime_5;
t_sample m_history_2;
t_sample m_history_1;
t_sample m_feedback_6;
t_sample samplerate;
t_sample m_dryWet_7;
// re-initialize all member variables;
inline void reset(t_param __sr, int __vs) {
__exception = 0;
vectorsize = __vs;
samplerate = __sr;
m_history_1 = 0;
m_history_2 = 0;
m_delay_3.reset(“m_delay_3”, 96000);
m_delay_4.reset(“m_delay_4”, 96000);
m_delaytime_5 = 250;
m_feedback_6 = 0.5;
m_dryWet_7 = 0.5;
genlib_reset_complete(this);

};
// the signal processing routine;
inline int perform(t_sample ** __ins, t_sample ** __outs, int __n) {
vectorsize = __n;
const t_sample * __in1 = __ins[0];
const t_sample * __in2 = __ins[1];
t_sample * __out1 = __outs[0];
t_sample * __out2 = __outs[1];
if (__exception) {
return __exception;

  } else if (( (__in1 == 0) || (__in2 == 0) || (__out1 == 0) || (__out2 == 0) )) {
  	__exception = GENLIB_ERR_NULL_BUFFER;
  	return __exception;
  	
  };
  t_sample mstosamps_118 = (m_delaytime_5 * (samplerate * 0.001));
  // the main sample loop;
  while ((__n--)) {
  	const t_sample in1 = (*(__in1++));
  	const t_sample in2 = (*(__in2++));
  	t_sample mix_147 = (in2 + (m_dryWet_7 * (m_history_2 - in2)));
  	t_sample out2 = mix_147;
  	t_sample mul_95 = (m_history_2 * m_feedback_6);
  	t_sample tap_7 = m_delay_4.read_spline(mstosamps_118);
  	t_sample tap_20 = m_delay_3.read_spline(mstosamps_118);
  	t_sample mix_148 = (in1 + (m_dryWet_7 * (m_history_1 - in1)));
  	t_sample out1 = mix_148;
  	t_sample mul_103 = (m_history_1 * m_feedback_6);
  	t_sample history_10_next_142 = fixdenorm(tap_7);
  	t_sample history_18_next_143 = fixdenorm(tap_20);
  	m_delay_4.write((mul_95 + in2));
  	m_delay_3.write((mul_103 + in1));
  	m_history_2 = history_10_next_142;
  	m_history_1 = history_18_next_143;
  	m_delay_3.step();
  	m_delay_4.step();
  	// assign results to output buffer;
  	(*(__out1++)) = out1;
  	(*(__out2++)) = out2;
  	
  };
  return __exception;

};
inline void set_delaytime(t_param _value) {
m_delaytime_5 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
};
inline void set_feedback(t_param _value) {
m_feedback_6 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
};
inline void set_dryWet(t_param _value) {
m_dryWet_7 = (_value < 0 ? 0 : (_value > 1 ? 1 : _value));
};

} State;

///
/// Configuration for the genlib API
///

/// Number of signal inputs and outputs

int gen_kernel_numins = 2;
int gen_kernel_numouts = 2;

int num_inputs() { return gen_kernel_numins; }
int num_outputs() { return gen_kernel_numouts; }
int num_params() { return 3; }

/// Assistive lables for the signal inputs and outputs

const char *gen_kernel_innames[] = { “in1”, “in2” };
const char *gen_kernel_outnames[] = { “out1”, “out2” };

/// Invoke the signal process of a State object

int perform(CommonState *cself, t_sample **ins, long numins, t_sample *outs, long numouts, long n) {
State
self = (State *)cself;
return self->perform(ins, outs, n);
}

/// Reset all parameters and stateful operators of a State object

void reset(CommonState cself) {
State
self = (State *)cself;
self->reset(cself->sr, cself->vs);
}

/// Set a parameter of a State object

void setparameter(CommonState *cself, long index, t_param value, void *ref) {
State *self = (State *)cself;
switch (index) {
case 0: self->set_delaytime(value); break;
case 1: self->set_dryWet(value); break;
case 2: self->set_feedback(value); break;

  default: break;

}
}

/// Get the value of a parameter of a State object

void getparameter(CommonState *cself, long index, t_param *value) {
State *self = (State *)cself;
switch (index) {
case 0: *value = self->m_delaytime_5; break;
case 1: *value = self->m_dryWet_7; break;
case 2: *value = self->m_feedback_6; break;

  default: break;

}
}

/// Get the name of a parameter of a State object

const char *getparametername(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].name;
}
return 0;
}

/// Get the minimum value of a parameter of a State object

t_param getparametermin(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].outputmin;
}
return 0;
}

/// Get the maximum value of a parameter of a State object

t_param getparametermax(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].outputmax;
}
return 0;
}

/// Get parameter of a State object has a minimum and maximum value

char getparameterhasminmax(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].hasminmax;
}
return 0;
}

/// Get the units of a parameter of a State object

const char *getparameterunits(CommonState *cself, long index) {
if (index >= 0 && index < cself->numparams) {
return cself->params[index].units;
}
return 0;
}

/// Get the size of the state of all parameters of a State object

size_t getstatesize(CommonState *cself) {
return genlib_getstatesize(cself, &getparameter);
}

/// Get the state of all parameters of a State object

short getstate(CommonState *cself, char *state) {
return genlib_getstate(cself, state, &getparameter);
}

/// set the state of all parameters of a State object

short setstate(CommonState *cself, const char *state) {
return genlib_setstate(cself, state, &setparameter);
}

/// Allocate and configure a new State object and it’s internal CommonState:

void *create(t_param sr, long vs) {
State *self = new State;
self->reset(sr, vs);
ParamInfo *pi;
self->__commonstate.inputnames = gen_kernel_innames;
self->__commonstate.outputnames = gen_kernel_outnames;
self->__commonstate.numins = gen_kernel_numins;
self->__commonstate.numouts = gen_kernel_numouts;
self->__commonstate.sr = sr;
self->__commonstate.vs = vs;
self->__commonstate.params = (ParamInfo *)genlib_sysmem_newptr(3 * sizeof(ParamInfo));
self->__commonstate.numparams = 3;
// initialize parameter 0 (“m_delaytime_5”)
pi = self->__commonstate.params + 0;
pi->name = “delaytime”;
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_delaytime_5;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0;
pi->outputmax = 1;
pi->exp = 0;
pi->units = “”; // no units defined
// initialize parameter 1 (“m_dryWet_7”)
pi = self->__commonstate.params + 1;
pi->name = “dryWet”;
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_dryWet_7;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0;
pi->outputmax = 1;
pi->exp = 0;
pi->units = “”; // no units defined
// initialize parameter 2 (“m_feedback_6”)
pi = self->__commonstate.params + 2;
pi->name = “feedback”;
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_feedback_6;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0;
pi->outputmax = 1;
pi->exp = 0;
pi->units = “”; // no units defined

return self;
}

/// Release all resources and memory used by a State object:

void destroy(CommonState *cself) {
State *self = (State *)cself;
genlib_sysmem_freeptr(cself->params);

delete self;
}

} // gen_exported::

Woua, wait, are you saying it would be possible to use gen~ to make er301 units ? It would be amazing ! I’m not into pure coding, i don’t want to take time to learn it actualy. but with max/msp, it would be totaly different !

that’s what Im saying, and Brian has confirmed with me direct.

I did a quick read of the generated code that you sent me. It does look pretty straightforward to wrap into a Unit, almost one-to-one with perhaps some complexity in mapping parameter units and types between the two worlds.

1 Like

Straightforward but not trivial! :grimacing:

There is a DSP library that the generated gen~ code uses which needs to be ported and adapters need to be written to interface a gen~ parameter to an ER-301 parameter. Also, we have to pray that the gen~ framework doesn’t rely on any OS-level niceties like virtual memory or file-mapping. The ER-301 is bare-metal after all.

Let’s not forget that there is a contingent of users picketing for faust as well.

So, the best thing I can do for everyone (I think) is to quickly get everything to the point where I can release a solid SDK that allows a motivated individual(*) to wrap the output from [put your favorite DSP-description language here] into a unit.

(*) Yes, if necessary I would hire someone to do this.

My personal goal with the ER-301 (the one that motivates me personally, because, surprise! it is not the money :smirk:) is to enhance the immersion/deep-dive aspect of the modular synthesizer. Supporting other DSP-description frameworks is not exactly in line with that. HOWEVER, I do want to support it and see it happen, simply because it is a good idea.

Does that make sense?

16 Likes

Wow, this all sounds amazing!

If this can be made reality then we really are talking about something quite extraordinary!

Itching to have a go at wrapping something… for some reason I think a wave folder might be a nice little unit to start with :slight_smile:

As a side note I am quite intrigued about the development environment, depending on preferred platform it might be nice to wrap up a clean install with everything needed and nicely configured as a Vagrant box or something like that.

I will end up with 4 x er301 if this will happen!

4 Likes

Yes it does. It’s epic that you can appreciate and are open to the many sides of this DSP and modular quest we (especially you) are navigating.

2 Likes

Wow! My excitement for the ER301 is growing by the day it seems. I’ve been wanting something like it in Eurorack for years, building a few DIY kits like the Terminal Tedium to get me close with Pd on a Rasberry Pi-- all just to build and play the perfect sampler in order to make and perform the music I’m trying to create. I really appreciate the open-endedness of your development. June 9th can’t come soon enough!

Greetings from Make Noise, btw!

3 Likes

Hi, probably a bit late on this…
Any updates about connecting dsp code (from gen~ c++ exports or anything pure dsp language codes FAUST or whatever) to ER301 ??

While I personally would prefer low level and native programming access, I am of the opinion that more is more in this case. I’m all for it, although I can’t say I’ll be using it much. :grin:

Faust-support would be amazing. But I suspect this is a feature that’s pretty far off.

Nothing to report yet. :bowing_man:

+1 for gen~ support :star_struck: that’d be amazing.
Nebulae with pd is not really an optimal option as it lacks the gui :frowning:
Is this feature still anywhere near your future plans?

1 Like

So is gen~ available in max for live? I tried to duplicate the patch above, but there were a lot of missing objects.

I’m dreaming of being able to build units with Gen. Would be incredible!

2 Likes

+100 this would extend the life of the 301 by a decade for me (along with the cpu expansion ofc)

4 Likes

Have we confirmed this is a thing? Seems we could do with a few options like this that cover stuff that Brian doesn’t plan on doing and I’m talking beyond the gen stuff

Be nice for a general update Brian on how things are progressing - middle layer and sdk and all that good stuff:)