• kroklop92217

    @robertesler hi again, i tried implementing simple mutex locking, so in theory only one thread can now read/write to the matrix state array. but surprisingly the issue remains. is my implementation faulty? i thought about adding this access protection to the whole class dataspace, maaaybe it could help, but im not sure really.

    thanks !!

    code added/changed:

    ...
    
    t_float matrix_rw(t_simple_matrix_tilde *x, int op, int c, ...) //x, 0/1, c, x, y, val
    {
      int m = pthread_mutex_lock(&x->mutex);
      
      va_list args;
      va_start(args, c);
    
      int xpos;
      int ypos;
      int sval;
    
      if(!m)
      {
        switch(op)
        {
          case 0: //read from timrax
            xpos = va_arg(args, int);
            ypos = va_arg(args, int);
            va_end(args);
            pthread_mutex_unlock(&x->mutex);
    
            return x->m_state[xpos][ypos];
      
          case 1: //write to axtirm
            xpos = va_arg(args, int);
            ypos = va_arg(args, int);
            sval = va_arg(args, int);
    
            x->m_state[xpos][ypos] = (t_float)sval;
            va_end(args);
            pthread_mutex_unlock(&x->mutex);
    
            return 0;
          
          default:
            //hm
            pthread_mutex_unlock(&x->mutex);
            return 0;
        }
      } else
      {
        //pthread error
        return 0;
      }
    }
    
    ...
    
    void simple_matrix_tilde_oscin(t_simple_matrix_tilde *x, t_symbol *s)
    {
      if(strlen(s->s_name) >= TRANSM_SIZE)
      {
        //sometimes the size is for some reason larger, maybe UDP? crazy guy
        //char recv[TRANSM_SIZE]; //snad to nevybouchne
        memcpy(x->recv, s->s_name, TRANSM_SIZE);
      
        x->val = x->recv[0] - '0';
        x->posx = x->recv[1] - '0';
        x->posy = x->recv[2] - '0';
      
        //post("val %d posx %d posy %d", x->val, x->posx, x->posy);
    
        matrix_rw(x, 1, 3, x->posx, x->posy, x->val); //write
      } else 
      {
        //?
      }
    }
    
    ...
    
    t_int *simple_matrix_tilde_perform(t_int *w)
    {
      t_simple_matrix_tilde *x =  (t_simple_matrix_tilde*)(w[1]);
      t_sample *sig_in =          (t_sample *)(w[2]);
      t_sample *sig_out =         (t_sample *)(w[3]);
      int len =                   (int)(w[4]); //lenght of sample
    
      t_float stat = matrix_rw(x, 0, 2, 0, 0); //read
      for(int u = 0; u < len; u++)
      {
        *sig_out++ = *(sig_in++) * stat;
      }
    
      return (w+5);
    }
    
    ...
    

    posted in extra~ read more
  • kroklop92217

    @robertesler thanks! i tried connecting just symbol object to the inlet instead of the OSC data stream and it works just fine...! so now i need to figure out whats up with the data its receiving. anyways thanks much again

    posted in extra~ read more
  • kroklop92217

    @whale-av thanks much! went through the code and its waayyyy too complex for my current understandig to be helpful. im definitely going to read throug it later when i have time, buut im now im looking for some simple fix to my problem (even something bit dirty).

    posted in extra~ read more
  • kroklop92217

    Hi,
    im trying to implement this simple object/class, that takes symbol in the first inlet and based on its value gates signal from nd inlet to outlet. The symbol comes from udp data stream, that is being parsed as OSC. Internally the incoming signal is multiplied by the symbol value (0 or 1). So in my understanding output should be silent or come through.
    Buuut its not working as excpected... signal output is terribly noisy and "laggy" sounding. Sometimes the puredata even shows and "Audio error". Interestingly, when i stop the OSC transmission it goes to normal and sounds as expected.

    Is my understanding of signal manipulation wrong? Or is the datastream lagging Pd?

    Thanks much for advice!

    simple_matrix~.c

    //sudo ln /Applications/Pd-0.55-0.app/Contents/Resources/src/m_pd.h m_pd.h
    //snad je to ok udelat takhle no
    
    #include <m_pd.h>
    #include <string.h>
    
    
    #define MATRIX_SIZE 7
    #define TRANSM_SIZE 3
    
    
    static t_class *simple_matrix_tilde_class;
    
    typedef struct _simple_matrix_tilde
    {
      t_object x_obj;
    
      t_float m_state[MATRIX_SIZE][MATRIX_SIZE]; //stav peč desky
    
      t_symbol transm_in;
    
      t_inlet *sig_one_in, *sig_two_in, *sig_tri_in, *sig_qud_in, *sig_fiv_in, *sig_six_in, *sig_sev_in; 
      t_outlet *sig_one_out, *sig_two_out, *sig_tri_out, *sig_qud_out, *sig_fiv_out, *sig_six_out, *sig_sev_out;
    
    } t_simple_matrix_tilde;
    
    void simple_matrix_tilde_osc_recv(t_simple_matrix_tilde *x, t_symbol *s)
    {
      if(strlen(s->s_name) > TRANSM_SIZE)
      {
        //pd_error(&x->x_obj, ":(");
        //sometimes the size is for some reason larger, maybe UDP? crazy guy
      }
    
      //post("lenght %d", strlen(s->s_name));
      //post("value %s", s->s_name);
    
      char recv[TRANSM_SIZE]; //snad to nevybouchne
      memcpy(recv, s->s_name, TRANSM_SIZE);
    
      int val = recv[0] - '0';
      int posx = recv[1] - '0';
      int posy = recv[2] - '0';
    
      //post("val %d posx %d posy %d", val, posx, posy);
    
      x->m_state[posx][posy] = (t_float)val;
    }
    
    t_int *simple_matrix_tilde_perform(t_int *w)
    {
      t_simple_matrix_tilde *x =  (t_simple_matrix_tilde*)(w[1]);
      t_sample *sig_in =          (t_sample *)(w[2]);
      t_sample *sig_out =         (t_sample *)(w[3]);
      int len =                   (int)(w[4]); //lenght of sample
    
      for(int u = 0; u < len; u++)
      {
        t_sample timesby = x->m_state[0][0];
        *sig_out++ = *(sig_in++) * timesby;
      }
    
      return (w+5);
    }
    
    void simple_matrix_tilde_dsp(t_simple_matrix_tilde *x, t_signal **sp)
    {
      dsp_add(simple_matrix_tilde_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
      return;
    }
    
    void *simple_matrix_tilde_new(void)
    {
      t_simple_matrix_tilde *x = (t_simple_matrix_tilde *)pd_new(simple_matrix_tilde_class);
    
      //wall,
      //wall,
      x->sig_one_in = inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
    
      x->sig_one_out = outlet_new(&x->x_obj, &s_signal);
    
      return (void *) x;
    }
    
    void simple_matrix_tilde_freedom(t_simple_matrix_tilde *x)
    {
      inlet_free(x->sig_one_in);
      outlet_free(x->sig_one_out);
    }
    
    void simple_matrix_tilde_setup(void)
    {
      simple_matrix_tilde_class = class_new(
        gensym("simple_matrix~"),
        (t_newmethod)simple_matrix_tilde_new,
        (t_method)simple_matrix_tilde_freedom,
        sizeof(t_simple_matrix_tilde),
        CLASS_DEFAULT,
        0
      );
    
      class_addsymbol(simple_matrix_tilde_class, simple_matrix_tilde_osc_recv);
    
      class_addmethod(simple_matrix_tilde_class, (t_method)simple_matrix_tilde_dsp, gensym("dsp"), A_CANT, 0);
    
    }
    
    

    The function simple_matrix_tilde_osc_recv just takes the input symbol and updates state of matrix connections, from which the gate of signal is later determined in perform function. The object should have 7 signal inlets and outlets in the future.

    Also i understand, that this could be implemented as a subpatch, but it seemed like good first external, to learn the basics.

    aand my Pd patch for testing:
    obrazek.png

    (i just got into writing externls, so maybe my undertanding of basic Pd internal concepts is little off)

    posted in extra~ read more
Internal error.

Oops! Looks like something went wrong!