Convert external to gen codebox?

Jun 15, 2013 at 5:45am

Convert external to gen codebox?

So I have this external (by Alex Harker) that I’ve been using for mp3-ification of sound in my patch. It sounds and works awesome. But it’s just an .mxo, and a 32bit one. I’ve been trying to convert my patch to a project to share more easily, but once it’s flattened into a project, it’s much harder for end users to replace individual files depending on the operating system they use. Up to now I just had windows users replace the poly~ file with a version that doesn’t use the external, and they were good to go. With a maxproject, that’s not an option anymore.

I’m wondering if the external can just work inside a codebox.

I pasted the .c inside codebox and it’s not working, and throws up errors I don’t understand:

gen_domain: dsp.gen: [string "gen2.Operators"]:711: expr/codebox object missing expression
gen~: failed to compile patcher

So I’m wondering if it’s a syntax thing that needs to change, or if it is more complex than that, and will require refactoring the code altogether.

Here is the gen object with the code pasted in:

– Pasted Max Patch, click to expand. –

This is how the actual external is being used.

– Pasted Max Patch, click to expand. –

And here is the unedited .c file, as codebox changes it a bit:

#include "ext.h"
#include "z_dsp.h"
#include <float.h>

/*
framerank~ is an object to average the values of a specific number of fft frames.
*/

void *this_class;

typedef struct _framerank
{
t_pxobject x_obj;

long *indices;

} t_framerank;

void *framerank_new (long windowsize, long size);
t_int *framerank_perform(t_int *w);
void framerank_dsp(t_framerank *x, t_signal **sp, short *count);
void framerank_free(t_framerank *x);
void framerank_assist (t_framerank *x, void *b, long m, long a, char *s);

int main(void)
{
setup((t_messlist **) &this_class, (method) framerank_new, (method)framerank_free, (short)sizeof(t_framerank), 0L, A_DEFLONG, A_DEFLONG, 0);
addmess((method)framerank_dsp, "dsp", A_CANT, 0);
addmess ((method)framerank_assist, "assist", A_CANT, 0);
dsp_initclass();

return 0;
}

void *framerank_new(long windowsize, long size)
{
t_framerank *x = (t_framerank *)newobject(this_class);

dsp_setup((t_pxobject *)x, 1);
outlet_new(x, "signal");

x->indices = 0;

return (x);
}

void framerank_free(t_framerank *x)
{
dsp_free(&x->x_obj);
if (x->indices)
free (x->indices);
}

void combsort_indices_float (long *indices, float *data, long num_points)
{
long gap = num_points;
long swaps = 1;
long index;
long gap_index;
long i;

while (gap > 1 || swaps)
{
if (gap > 1)
{
gap = (gap * 10) / 13;
if (gap == 9 || gap == 10)
gap = 11;
if (gap < 1) gap = 1;
}

for (i = 0, swaps = 0; i + gap < num_points; i++)
{
index = indices[i];
gap_index = indices[i + gap];
if (data[index] < data[gap_index])
{
indices[i] = gap_index;
indices[i + gap] = index;
swaps = 1;
}
}
}
}

t_int *framerank_perform(t_int *w) // Here we just store the incoming vals if we are taking a sample and then decide when to output
{
float *in = (float *)(w[1]);
float *out = (float *)(w[2]);
int vectsize = w[3];
t_framerank *x = (t_framerank *)(w[4]);

long *indices = x->indices;
long i;

if (x->x_obj.z_disabled)
goto out;

for (i = 0; i < vectsize; i++)
indices[i] = i;

combsort_indices_float(indices, in, vectsize);

for (i = 0; i < vectsize; i++)
out[indices[i]] = i + 1;

out:
return w + 5;
}

void framerank_dsp(t_framerank *x, t_signal **sp, short *count)
{
free (x->indices);
x->indices = malloc (sizeof(long) * sp[0]->s_n);

dsp_add(framerank_perform, 4, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n, x);
}

void framerank_assist(t_framerank *x, void *b, long m, long a, char *s)
{
if (m == ASSIST_OUTLET)
sprintf(s,"(signal) Ranking");
else
sprintf(s,"(signal) FFT Data In");
}

#252837

You must be logged in to reply to this topic.