Changeset c7860af


Ignore:
Timestamp:
Dec 4, 2009, 1:32:43 AM (14 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
66fb3ea
Parents:
c6d0169
Message:

modified fvec and lvec to be mono, added fmat

Location:
src
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/fvec.c

    rc6d0169 rc7860af  
    2222#include "fvec.h"
    2323
    24 fvec_t * new_fvec( uint_t length, uint_t channels) {
     24fvec_t * new_fvec( uint_t length) {
    2525  fvec_t * s = AUBIO_NEW(fvec_t);
    26   uint_t i,j;
    27   s->channels = channels;
     26  uint_t j;
    2827  s->length = length;
    29   s->data = AUBIO_ARRAY(smpl_t*,s->channels);
    30   for (i=0; i< s->channels; i++) {
    31     s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
    32     for (j=0; j< s->length; j++) {
    33       s->data[i][j]=0.;
    34     }
     28  s->data = AUBIO_ARRAY(smpl_t, s->length);
     29  for (j=0; j< s->length; j++) {
     30    s->data[j]=0.;
    3531  }
    3632  return s;
     
    3834
    3935void del_fvec(fvec_t *s) {
    40   uint_t i;
    41   for (i=0; i<s->channels; i++) {
    42     AUBIO_FREE(s->data[i]);
    43   }
    4436  AUBIO_FREE(s->data);
    4537  AUBIO_FREE(s);
    4638}
    4739
    48 void fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position) {
    49   s->data[channel][position] = data;
    50 }
    51 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position) {
    52   return s->data[channel][position];
    53 }
    54 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel) {
    55   s->data[channel] = data;
    56 }
    57 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel) {
    58   return s->data[channel];
     40void fvec_write_sample(fvec_t *s, smpl_t data, uint_t position) {
     41  s->data[position] = data;
    5942}
    6043
    61 smpl_t ** fvec_get_data(fvec_t *s) {
     44smpl_t fvec_read_sample(fvec_t *s, uint_t position) {
     45  return s->data[position];
     46}
     47
     48smpl_t * fvec_get_data(fvec_t *s) {
    6249  return s->data;
    6350}
     
    6653
    6754void fvec_print(fvec_t *s) {
    68   uint_t i,j;
    69   for (i=0; i< s->channels; i++) {
    70     for (j=0; j< s->length; j++) {
    71       AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
    72     }
    73     AUBIO_MSG("\n");
     55  uint_t j;
     56  for (j=0; j< s->length; j++) {
     57    AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[j]);
    7458  }
     59  AUBIO_MSG("\n");
    7560}
    7661
    7762void fvec_set(fvec_t *s, smpl_t val) {
    78   uint_t i,j;
    79   for (i=0; i< s->channels; i++) {
    80     for (j=0; j< s->length; j++) {
    81       s->data[i][j] = val;
    82     }
     63  uint_t j;
     64  for (j=0; j< s->length; j++) {
     65    s->data[j] = val;
    8366  }
    8467}
     
    9376
    9477void fvec_rev(fvec_t *s) {
    95   uint_t i,j;
    96   for (i=0; i< s->channels; i++) {
    97     for (j=0; j< FLOOR(s->length/2); j++) {
    98       ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
    99     }
     78  uint_t j;
     79  for (j=0; j< FLOOR(s->length/2); j++) {
     80    ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
    10081  }
    10182}
    10283
    10384void fvec_weight(fvec_t *s, fvec_t *weight) {
    104   uint_t i,j;
     85  uint_t j;
    10586  uint_t length = MIN(s->length, weight->length);
    106   for (i=0; i< s->channels; i++) {
    107     for (j=0; j< length; j++) {
    108       s->data[i][j] *= weight->data[0][j];
    109     }
     87  for (j=0; j< length; j++) {
     88    s->data[j] *= weight->data[j];
    11089  }
    11190}
    11291
    11392void fvec_copy(fvec_t *s, fvec_t *t) {
    114   uint_t i,j;
    115   uint_t channels = MIN(s->channels, t->channels);
     93  uint_t j;
    11694  uint_t length = MIN(s->length, t->length);
    117   if (s->channels != t->channels) {
    118     AUBIO_ERR("warning, trying to copy %d channels to %d channels\n",
    119             s->channels, t->channels);
    120   }
    12195  if (s->length != t->length) {
    122     AUBIO_ERR("warning, trying to copy %d elements to %d elements \n",
     96    AUBIO_WRN("trying to copy %d elements to %d elements \n",
    12397            s->length, t->length);
    12498  }
    125   for (i=0; i< channels; i++) {
    126     for (j=0; j< length; j++) {
    127       t->data[i][j] = s->data[i][j];
    128     }
     99  for (j=0; j< length; j++) {
     100    t->data[j] = s->data[j];
    129101  }
    130102}
  • src/fvec.h

    rc6d0169 rc7860af  
    3838typedef struct {
    3939  uint_t length;   /**< length of buffer */
    40   uint_t channels; /**< number of channels */
    41   smpl_t **data;   /**< data array of size [length] * [channels] */
     40  smpl_t *data;   /**< data array of size [length] */
    4241} fvec_t;
    4342
     
    4544
    4645  \param length the length of the buffer to create
    47   \param channels the number of channels in the buffer
    4846
    4947*/
    50 fvec_t * new_fvec(uint_t length, uint_t channels);
     48fvec_t * new_fvec(uint_t length);
    5149/** fvec_t buffer deletion function
    5250
     
    5856
    5957  Note that this function is not used in the aubio library, since the same
    60   result can be obtained using vec->data[channel][position]. Its purpose is to
     58  result can be obtained using vec->data[position]. Its purpose is to
    6159  access these values from wrappers, as created by swig.
    6260
    6361  \param s vector to read from
    64   \param channel channel to read from
    6562  \param position sample position to read from
    6663
    6764*/
    68 smpl_t fvec_read_sample(fvec_t *s, uint_t channel, uint_t position);
     65smpl_t fvec_read_sample(fvec_t *s, uint_t position);
    6966/** write sample value in a buffer
    7067
    7168  Note that this function is not used in the aubio library, since the same
    72   result can be obtained by assigning vec->data[channel][position]. Its purpose
     69  result can be obtained by assigning vec->data[position]. Its purpose
    7370  is to access these values from wrappers, as created by swig.
    7471
    7572  \param s vector to write to
    76   \param data value to write in s->data[channel][position]
    77   \param channel channel to write to
     73  \param data value to write in s->data[position]
    7874  \param position sample position to write to
    7975
    8076*/
    81 void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t channel, uint_t position);
    82 /** read channel vector from a buffer
     77void  fvec_write_sample(fvec_t *s, smpl_t data, uint_t position);
    8378
    84   Note that this function is not used in the aubio library, since the same
    85   result can be obtained with vec->data[channel]. Its purpose is to access
    86   these values from wrappers, as created by swig.
    87 
    88   \param s vector to read from
    89   \param channel channel to read from
    90 
    91 */
    92 smpl_t * fvec_get_channel(fvec_t *s, uint_t channel);
    93 /** write channel vector into a buffer
    94 
    95   Note that this function is not used in the aubio library, since the same
    96   result can be obtained by assigning vec->data[channel]. Its purpose is to
    97   access these values from wrappers, as created by swig.
    98 
    99   \param s vector to write to
    100   \param data vector of [length] values to write
    101   \param channel channel to write to
    102 
    103 */
    104 void fvec_put_channel(fvec_t *s, smpl_t * data, uint_t channel);
    10579/** read data from a buffer
    10680
     
    11286
    11387*/
    114 smpl_t ** fvec_get_data(fvec_t *s);
     88smpl_t * fvec_get_data(fvec_t *s);
    11589
    11690/** print out fvec data
  • src/lvec.c

    rc6d0169 rc7860af  
    2222#include "lvec.h"
    2323
    24 lvec_t * new_lvec( uint_t length, uint_t channels) {
     24lvec_t * new_lvec( uint_t length) {
    2525  lvec_t * s = AUBIO_NEW(lvec_t);
    26   uint_t i,j;
    27   s->channels = channels;
     26  uint_t j;
    2827  s->length = length;
    29   s->data = AUBIO_ARRAY(lsmp_t*,s->channels);
    30   for (i=0; i< s->channels; i++) {
    31     s->data[i] = AUBIO_ARRAY(lsmp_t, s->length);
    32     for (j=0; j< s->length; j++) {
    33       s->data[i][j]=0.;
    34     }
     28  s->data = AUBIO_ARRAY(lsmp_t, s->length);
     29  for (j=0; j< s->length; j++) {
     30    s->data[j]=0.;
    3531  }
    3632  return s;
     
    3834
    3935void del_lvec(lvec_t *s) {
    40   uint_t i;
    41   for (i=0; i<s->channels; i++) {
    42     AUBIO_FREE(s->data[i]);
    43   }
    4436  AUBIO_FREE(s->data);
    4537  AUBIO_FREE(s);
    4638}
    4739
    48 void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position) {
    49   s->data[channel][position] = data;
     40void lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position) {
     41  s->data[position] = data;
    5042}
    51 lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position) {
    52   return s->data[channel][position];
    53 }
    54 void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel) {
    55   s->data[channel] = data;
    56 }
    57 lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel) {
    58   return s->data[channel];
     43lsmp_t lvec_read_sample(lvec_t *s, uint_t position) {
     44  return s->data[position];
    5945}
    6046
    61 lsmp_t ** lvec_get_data(lvec_t *s) {
     47lsmp_t * lvec_get_data(lvec_t *s) {
    6248  return s->data;
    6349}
     
    6652
    6753void lvec_print(lvec_t *s) {
    68   uint_t i,j;
    69   for (i=0; i< s->channels; i++) {
    70     for (j=0; j< s->length; j++) {
    71       AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[i][j]);
    72     }
    73     AUBIO_MSG("\n");
     54  uint_t j;
     55  for (j=0; j< s->length; j++) {
     56    AUBIO_MSG(AUBIO_LSMP_FMT " ", s->data[j]);
    7457  }
     58  AUBIO_MSG("\n");
    7559}
    7660
    7761void lvec_set(lvec_t *s, smpl_t val) {
    78   uint_t i,j;
    79   for (i=0; i< s->channels; i++) {
    80     for (j=0; j< s->length; j++) {
    81       s->data[i][j] = val;
    82     }
     62  uint_t j;
     63  for (j=0; j< s->length; j++) {
     64    s->data[j] = val;
    8365  }
    8466}
  • src/lvec.h

    rc6d0169 rc7860af  
    3939typedef struct {
    4040  uint_t length;   /**< length of buffer */
    41   uint_t channels; /**< number of channels */
    42   lsmp_t **data;   /**< data array of size [length] * [channels] */
     41  lsmp_t *data;   /**< data array of size [length] */
    4342} lvec_t;
    4443
     
    4645
    4746  \param length the length of the buffer to create
    48   \param channels the number of channels in the buffer
    4947
    5048*/
    51 lvec_t * new_lvec(uint_t length, uint_t channels);
     49lvec_t * new_lvec(uint_t length);
    5250/** lvec_t buffer deletion function
    5351
     
    5957
    6058  Note that this function is not used in the aubio library, since the same
    61   result can be obtained using vec->data[channel][position]. Its purpose is to
     59  result can be obtained using vec->data[position]. Its purpose is to
    6260  access these values from wrappers, as created by swig.
    6361
    6462  \param s vector to read from
    65   \param channel channel to read from
    6663  \param position sample position to read from
    6764
    6865*/
    69 lsmp_t lvec_read_sample(lvec_t *s, uint_t channel, uint_t position);
     66lsmp_t lvec_read_sample(lvec_t *s, uint_t position);
    7067/** write sample value in a buffer
    7168
    7269  Note that this function is not used in the aubio library, since the same
    73   result can be obtained by assigning vec->data[channel][position]. Its purpose
     70  result can be obtained by assigning vec->data[position]. Its purpose
    7471  is to access these values from wrappers, as created by swig.
    7572
    7673  \param s vector to write to
    77   \param data value to write in s->data[channel][position]
    78   \param channel channel to write to
     74  \param data value to write in s->data[position]
    7975  \param position sample position to write to
    8076
    8177*/
    82 void  lvec_write_sample(lvec_t *s, lsmp_t data, uint_t channel, uint_t position);
    83 /** read channel vector from a buffer
     78void  lvec_write_sample(lvec_t *s, lsmp_t data, uint_t position);
    8479
    85   Note that this function is not used in the aubio library, since the same
    86   result can be obtained with vec->data[channel]. Its purpose is to access
    87   these values from wrappers, as created by swig.
    88 
    89   \param s vector to read from
    90   \param channel channel to read from
    91 
    92 */
    93 lsmp_t * lvec_get_channel(lvec_t *s, uint_t channel);
    94 /** write channel vector into a buffer
    95 
    96   Note that this function is not used in the aubio library, since the same
    97   result can be obtained by assigning vec->data[channel]. Its purpose is to
    98   access these values from wrappers, as created by swig.
    99 
    100   \param s vector to write to
    101   \param data vector of [length] values to write
    102   \param channel channel to write to
    103 
    104 */
    105 void lvec_put_channel(lvec_t *s, lsmp_t * data, uint_t channel);
    10680/** read data from a buffer
    10781
     
    11387
    11488*/
    115 lsmp_t ** lvec_get_data(lvec_t *s);
     89lsmp_t * lvec_get_data(lvec_t *s);
    11690
    11791/** print out lvec data
Note: See TracChangeset for help on using the changeset viewer.