fifo


    Feb 19 2009 | 10:43 am
    Hello
    I install codeblocs on MaxMsp 4.56 on pc but how to compile this on pc: this code is for macintosh in first, and how do you compile same object for mac and pc.
    /* --------fifo.c----------- */ // created 17/3/95 // modified 12/4/96
    /* a fifo buffer filled with longs and empties itself on every bang (in order of coming in) */
    // copyright St. Rainstick, Amsterdam 1995 // any changes to the source must be sent to: // St. Rainstick // Herenmarkt 12 // 1012 ED Amsterdam // rainstick@xs4all.nl
    // *********************************************************************************
    #include "ext.h" #include #include "typedefs.h"
    fptr *FNS;
    typedef struct fifo { struct object d_ob; long *getal; long count, end, size; void *out;
    }Fifo;
    void *fifo_new(); void *fifo_int(); void *fifo_bang(); void *fifo_free(); void *class;
    main(f) fptr *f; {
    RememberA0(); SetUpA4(); FNS = f;
    setup(&class, fifo_new, fifo_free, (short)sizeof(Fifo), 0L, A_DEFLONG,0); addbang(fifo_bang); addint(fifo_int); RestoreA4(); }
    void *fifo_int(x,n) struct fifo *x; long n; { register i;
    SetUpA4(); x->getal[x->count] = n; x->count = (x->count + 1) % x->size; RestoreA4(); }
    void *fifo_bang(x) struct fifo *x; { register i;
    SetUpA4(); if (x->end != x->count){ outlet_int(x->out,x->getal[x->end]); x->end = (x->end + 1) % x->size; } RestoreA4(); }
    void *fifo_free(x) struct fifo *x; { SetUpA4(); DisposPtr((Ptr)(x->getal)); RestoreA4(); }
    void *fifo_new(n) long n; {
    struct fifo *x;
    SetUpA4(); x = (struct fifo *)newobject(class); if (n x->size = n; x->end = 0; x->count = 0; x->getal = (long *)NewPtr(n * 4); x->out = intout(x);
    RestoreA4(); return (x); }

    • Feb 19 2009 | 6:26 pm
      This code is ancient. Get an up to date copy of the SDK.
      The references to fptr, and all the A4-world stuff -- SetupA4(), RestoreA4(), etc -- have not been used since about 1995. This is seriously dead code you're working with.
    • Feb 23 2009 | 1:21 pm
      OK, here's a more concrete answer:
      Delete the line:
      #include 
      Delete the line:
      fptr *FNS;
      Delete all occurrences of any of the following statements:
      • RememberA0();
      • SetUpA4();
      • RestoreA4();
      While you're at it, edit all function definitions to use ANSI C syntax. So, for instance, replace:
      void *fifo_int(x,n)
      struct fifo *x;
      long n;
      {
      
      with:
      void *fifo_int(Fifo* x, long n)
      {
      
      Rewrite main as follows
      void main(void)
        {
        setup((t_messlist*) &class,
              (method) fifo_new,
              (method) fifo_free,
              sizeof(Fifo), 0L, A_DEFLONG, 0);
        addbang(fifo_bang);
        addint(fifo_int);
        }
      
      Note the explicit typecasts, which will be necessary with a modern compiler. OTOH, since functions are now prototyped, you don't need to typecast sizeof(Fifo).
      Some compilers will complain about main() not returning int. This is a harmless warning, although you can apparently safely define main to return int and end the function with a return 0; statement if that makes you happier.
      That should be about everything.
      Don't forget to read the SDK documentation to understand what you're doing.
      Hope this helps ---- P.