Exemple #1
0
/*******************************************************************************
 Functionname:  UpdateFreqScale
 *******************************************************************************
 Description:

 Arguments:

 Return:
 *******************************************************************************/
int
UpdateFreqScale(unsigned char  *v_k_master, int *h_num_bands,
                const int k0, const int k2,
                const int freqScale,
                const int alterScale)

{

  int     b_p_o = 0;
  float   warp = 0;
  int     dk = 0;

  /* Internal variables */
  int     two_regions = 0;
  int     k1 = 0, i;
  int     num_bands0;
  int     num_bands1;
  int     diff_tot[MAX_OCTAVE + MAX_SECOND_REGION];
  int     *diff0 = diff_tot;
  int     *diff1 = diff_tot+MAX_OCTAVE;
  int     k2_achived;
  int     k2_diff;
  int     incr = 0;

  

    /* counting previous operations */


   
  if(freqScale==1)
  {
    
    b_p_o=12;
  }

   
  if(freqScale==2)
  {
    
    b_p_o=10;
  }

   
  if(freqScale==3)
  {
    
    b_p_o=8;
  }


  
  if(freqScale > 0)
    {
      
      if(alterScale==0)
      {
        
        warp=1.0;
      }
      else
      {
        
        warp=1.3f;
      }


        
      if(4*k2 >= 9*k0)
        {
          
          two_regions=1;

          
          k1=2*k0;

          
          num_bands0=numberOfBands(b_p_o, k0, k1, 1.0);

          
          num_bands1=numberOfBands(b_p_o, k1, k2, warp);

          
          CalcBands(diff0, k0, k1, num_bands0);

          
          Shellsort_int( diff0, num_bands0);

          
          if (diff0[0] == 0)
          {
            

            return (1);

          }

          
          cumSum(k0, diff0, num_bands0, v_k_master);

          
          CalcBands(diff1, k1, k2, num_bands1);

          
          Shellsort_int( diff1, num_bands1);

            
          if(diff0[num_bands0-1] > diff1[0])
            {
                
              if(modifyBands(diff0[num_bands0-1],diff1, num_bands1))
              {
                
                return(1);
              }

            }


            
          cumSum(k1, diff1, num_bands1, &v_k_master[num_bands0]);
           
          *h_num_bands=num_bands0+num_bands1;

        }
      else
        {
          
          two_regions=0;
          k1=k2;

          
          num_bands0=numberOfBands(b_p_o, k0, k1, 1.0);

          
          CalcBands(diff0, k0, k1, num_bands0);

          
          Shellsort_int( diff0, num_bands0);

          
          if (diff0[0] == 0)
          {
            
            return (1);

          }

          
          cumSum(k0, diff0, num_bands0, v_k_master);

          
          *h_num_bands=num_bands0;

        }
    }
  else
    {
      
      if (alterScale==0) {

        
        dk = 1;

          
        num_bands0 = 2 * ((k2 - k0)/2);
      } else {

        
        dk = 2;

          
        num_bands0 = 2 * (((k2 - k0)/dk +1)/2);
      }

       
      k2_achived = k0 + num_bands0*dk;

      
      k2_diff = k2 - k2_achived;

      
      
      for(i=0;i<num_bands0;i++)
      {
        
        diff_tot[i] = dk;
      }



      
      if (k2_diff < 0) {

          
          incr = 1;
          i = 0;
      }



      
      if (k2_diff > 0) {

          
          incr = -1;

          
          i = num_bands0-1;
      }


       /* diff_tot[] */
      
      while (k2_diff != 0) {

         
        diff_tot[i] = diff_tot[i] - incr;

        /* ADD(1): pointer increment */
        i = i + incr;

        
        k2_diff = k2_diff + incr;
      }

      
      cumSum(k0, diff_tot, num_bands0, v_k_master);

      
      *h_num_bands=num_bands0;

    }

   
  if (*h_num_bands < 1)
  {
    
    return(1);
  }

  

  return (0);
}/* End UpdateFreqScale */
static void mTXCumsumMatrix (MTXCumsum *mtx_cumsum_obj, t_symbol *s,
                             int argc, t_atom *argv)
{
  int rows, columns, size;
  t_atom *list_ptr = argv+2;
  t_atom *list_out = mtx_cumsum_obj->list_out;
  t_float *x = mtx_cumsum_obj->x;
  t_float *y = mtx_cumsum_obj->y;
  int count;

  /* size check */
  if(iemmatrix_check(mtx_cumsum_obj, argc, argv, 0))return;
  rows = atom_getint (argv+0);
  columns = atom_getint (argv+1);
  size = rows * columns;

  if ((!x)||(!list_out)||(!y)) {
    if (!x) {
      x = (t_float *) getbytes (sizeof (t_float) * (size));
    }
    if (!y) {
      y = (t_float *) getbytes (sizeof (t_float) * (size));
    }
    if (!list_out) {
      list_out = (t_atom *) getbytes (sizeof (t_atom) * (size+2));
    }
  } else if (size != mtx_cumsum_obj->size) {
    x = (t_float *) resizebytes (x,
                                 sizeof (t_float) * (mtx_cumsum_obj->size),
                                 sizeof (t_float) * (size));
    y = (t_float *) resizebytes (y,
                                 sizeof (t_float) * (mtx_cumsum_obj->size),
                                 sizeof (t_float) * (size));
    list_out = (t_atom *) resizebytes (list_out,
                                       sizeof (t_atom) * (mtx_cumsum_obj->size+2),
                                       sizeof (t_atom) * (size + 2));
  }
  mtx_cumsum_obj->size = size;
  mtx_cumsum_obj->rows = rows;
  mtx_cumsum_obj->columns = columns;
  mtx_cumsum_obj->list_out = list_out;
  mtx_cumsum_obj->x = x;
  mtx_cumsum_obj->y = y;

  /* main part */
  /* reading matrix from inlet */
  if ((mtx_cumsum_obj->cumsum_mode == col_sym) ||
      (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
    readFloatFromListModulo (size, columns, list_ptr, x);
    columns = mtx_cumsum_obj->rows;
    rows = mtx_cumsum_obj->columns;
  } else {
    readFloatFromList (size, list_ptr, x);
  }

  /* calculating cumsum */
  if (mtx_cumsum_obj->cumsum_direction == -1) {
    if ((mtx_cumsum_obj->cumsum_mode == row_sym) ||
        (mtx_cumsum_obj->cumsum_mode == col_sym) ||
        (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
      x += columns-1;
      y += columns-1;

      for (count = rows; count--; x += columns, y += columns) {
        cumSumReverse (columns,x,y);
      }
    } else {
      x += size-1;
      y += size-1;
      cumSumReverse (size, x, y);
    }
  } else if ((mtx_cumsum_obj->cumsum_mode == row_sym) ||
             (mtx_cumsum_obj->cumsum_mode == col_sym) ||
             (mtx_cumsum_obj->cumsum_mode == col_sym2))
    for (count = rows; count--; x += columns, y += columns) {
      cumSum (columns,x,y);
    }
  else {
    cumSum (size, x, y);
  }

  x = mtx_cumsum_obj->x;
  y = mtx_cumsum_obj->y;

  /* writing matrix to outlet */
  if ((mtx_cumsum_obj->cumsum_mode == col_sym) ||
      (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
    columns = mtx_cumsum_obj->columns;
    rows = mtx_cumsum_obj->rows;
    writeFloatIntoListModulo (size, columns, list_out+2, y);
  } else {
    writeFloatIntoList (size, list_out+2, y);
  }

  SETSYMBOL(list_out, gensym("matrix"));
  SETFLOAT(list_out, rows);
  SETFLOAT(&list_out[1], columns);
  outlet_anything(mtx_cumsum_obj->list_outlet, gensym("matrix"),
                  mtx_cumsum_obj->size+2, list_out);
}
Exemple #3
0
static void mTXCumsumMatrix (MTXCumsum *mtx_cumsum_obj, t_symbol *s, 
      int argc, t_atom *argv)
{
   int rows = atom_getint (argv++);
   int columns = atom_getint (argv++);
   int size = rows * columns;
   int list_size = argc - 2;
   t_atom *list_ptr = argv;
   t_atom *list_out = mtx_cumsum_obj->list_out;
   t_float *x = mtx_cumsum_obj->x;
   t_float *y = mtx_cumsum_obj->y;
   int count;

   /* size check */
   if (!size) {
      post("mtx_cumsum: invalid dimensions");
      return;
   }
   else if (list_size<size) {
      post("mtx_cumsum: sparse matrix not yet supported: use \"mtx_check\"");
      return;
   }
   else if ((!x)||(!list_out)||(!y)) {
      if (!x)
	 x = (t_float *) getbytes (sizeof (t_float) * (size));
      if (!y)
	 y = (t_float *) getbytes (sizeof (t_float) * (size));
      if (!list_out)
	 list_out = (t_atom *) getbytes (sizeof (t_atom) * (size+2));
   }
   else if (size != mtx_cumsum_obj->size) {
      x = (t_float *) resizebytes (x,
	    sizeof (t_float) * (mtx_cumsum_obj->size),
	    sizeof (t_float) * (size));
      y = (t_float *) resizebytes (y,
	    sizeof (t_float) * (mtx_cumsum_obj->size),
	    sizeof (t_float) * (size));
      list_out = (t_atom *) resizebytes (list_out,
	    sizeof (t_atom) * (mtx_cumsum_obj->size+2),
	    sizeof (t_atom) * (size + 2));
   }
   mtx_cumsum_obj->size = size;
   mtx_cumsum_obj->rows = rows;
   mtx_cumsum_obj->columns = columns;
   mtx_cumsum_obj->list_out = list_out;
   mtx_cumsum_obj->x = x;
   mtx_cumsum_obj->y = y;

   /* main part */
   /* reading matrix from inlet */
   if ((mtx_cumsum_obj->cumsum_mode == col_sym) ||
	(mtx_cumsum_obj->cumsum_mode == col_sym2)) {
      readFloatFromListModulo (size, columns, list_ptr, x);
      columns = mtx_cumsum_obj->rows;
      rows = mtx_cumsum_obj->columns;
   }
   else
      readFloatFromList (size, list_ptr, x);
   
   /* calculating cumsum */
   if (mtx_cumsum_obj->cumsum_direction == -1) {
      if ((mtx_cumsum_obj->cumsum_mode == row_sym) ||
	    (mtx_cumsum_obj->cumsum_mode == col_sym) ||
	    (mtx_cumsum_obj->cumsum_mode == col_sym2)) {
	 x += columns-1;
	 y += columns-1;

	 for (count = rows; count--; x += columns, y += columns)
	    cumSumReverse (columns,x,y);
      }
      else {
	 x += size-1;
	 y += size-1;
	 cumSumReverse (size, x, y);
      }
   }
   else if ((mtx_cumsum_obj->cumsum_mode == row_sym) ||
	 (mtx_cumsum_obj->cumsum_mode == col_sym) ||
	 (mtx_cumsum_obj->cumsum_mode == col_sym2))
      for (count = rows; count--; x += columns, y += columns)
	 cumSum (columns,x,y);
   else
      cumSum (size, x, y);

   x = mtx_cumsum_obj->x;
   y = mtx_cumsum_obj->y;

   /* writing matrix to outlet */
   if ((mtx_cumsum_obj->cumsum_mode == col_sym) ||
	(mtx_cumsum_obj->cumsum_mode == col_sym2)) {
      columns = mtx_cumsum_obj->columns;
      rows = mtx_cumsum_obj->rows;
      writeFloatIntoListModulo (size, columns, list_out+2, y);
   }
   else
      writeFloatIntoList (size, list_out+2, y);

   SETSYMBOL(list_out, gensym("matrix"));
   SETFLOAT(list_out, rows);
   SETFLOAT(&list_out[1], columns);
   outlet_anything(mtx_cumsum_obj->list_outlet, gensym("matrix"), 
	 mtx_cumsum_obj->size+2, list_out);
}