Roughometer  0.2
Data Structures | Macros | Typedefs | Functions | Variables
roughometer.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "m_pd.h"
Include dependency graph for roughometer.c:

Data Structures

struct  _roughometer
 
struct  proxy
 

Macros

#define MAX_INSTRUMENTS   20
 Max. number of streams. More...
 
#define MAX_PARTIALS   20
 Max. number of spectra components. More...
 
#define SCALE_CONSTANT   100
 A scale constant to express the roughness in manageable values. More...
 
#define DEFAULT_THRESHOLD   0.001
 Default amplitude threshold for incoming streams. More...
 
#define min(a, b)
 Returns the minimum of the two arguments. More...
 
#define max(a, b)
 Returns the maximum of the two arguments. More...
 

Typedefs

typedef struct _roughometer t_roughometer
 
typedef struct proxy t_proxy
 Auxiliary structure to allow dynamic number of inlets. More...
 

Functions

t_float S (t_float f)
 Calculate S. More...
 
t_float dissonance (t_roughometer *x, t_float a1, t_float a2, t_float f1, t_float f2)
 Calculates auditory roughness of a dyad using the model proposed by Vassilakis. More...
 
t_float d_Calculation (t_roughometer *x)
 Calculates the complex roughness of the ensemble. More...
 
void roughometer_initMatrix (t_roughometer *x)
 Initializes the frequency and amplitude matrices as well as the solution, partial solution, and last pitch vector. More...
 
void setCounters (t_roughometer *x, t_int value)
 Sets the counters of processed income to the value indicated by the parameter 'value. More...
 
void roughometer_bang (t_roughometer *x)
 Process a request for roughness calculation. More...
 
void roughometer_setOffset (t_roughometer *x, t_floatarg f)
 Sets the minimum amplitude value to be considered for the Roughness calculation. More...
 
t_int areAllComponentsIn (t_roughometer *x)
 Counts how many streams have been completed (in terms of the number of partials analyzed). More...
 
static void roughometer_value (t_proxy *p, t_symbol *s, int argc, t_atom *argv)
 Update the frequency and amplitude values for each instrument. More...
 
void * roughometer_new (t_floatarg n)
 Instantiate the object. More...
 
void roughometer_setup (void)
 setup the object More...
 

Variables

static t_class * roughometer_class
 
static t_class * proxy_class
 

Macro Definition Documentation

#define DEFAULT_THRESHOLD   0.001

Default amplitude threshold for incoming streams.

#define max (   a,
  b 
)
Value:
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; })

Returns the maximum of the two arguments.

#define MAX_INSTRUMENTS   20

Max. number of streams.

#define MAX_PARTIALS   20

Max. number of spectra components.

#define min (   a,
  b 
)
Value:
({ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a < _b ? _a : _b; })

Returns the minimum of the two arguments.

#define SCALE_CONSTANT   100

A scale constant to express the roughness in manageable values.

Typedef Documentation

typedef struct proxy t_proxy

Auxiliary structure to allow dynamic number of inlets.

typedef struct _roughometer t_roughometer

Function Documentation

t_int areAllComponentsIn ( t_roughometer *  x)

Counts how many streams have been completed (in terms of the number of partials analyzed).

and returns 0 or 1 if there are some incomplete or not respectevly.

Parameters
xa pointer to the inner structure of the object

not all the components have been written

they're all in.

t_float d_Calculation ( t_roughometer *  x)

Calculates the complex roughness of the ensemble.

One difference between the model proposed by Vassilakis is that only the dissonance produced by components belonging to different signals count. In other words, the intrinsic dissonance is not considered because it is wanted to preserve the timbre of the signal. Also, by doing it the number of iterations is reduced. This function is the kernel of the minimization, since it takes the current values of the vicinity in cents for the stream where an onset was detected and calculates

\[ d= \sum_{h=0}^{n-1} \sum_{i=h}^{n} \sum_{j=0}^{p} \sum_{k=0}^{p} dissonance( a_1,a_2,F_1,F_2) \]

where $n,p,F_1,F_2$ are the number of streams, number of partials, $f_{(1,2)}\, \times vicinity$ if $f_{(1,2)} \in $ onsetting stream, or $f_{(1,2)}$ otherwise

Parameters
xA pointer to the inner structure of the object.
Returns
the roughness for a complex tone ensamble
t_float dissonance ( t_roughometer *  x,
t_float  a1,
t_float  a2,
t_float  f1,
t_float  f2 
)

Calculates auditory roughness of a dyad using the model proposed by Vassilakis.

Vassilakis models assumes that for a dyad $(f_1,a_1)$ and $f_2,a_2)$, $(a_1 \geq a_2)$. There's an error in his thesis about this (p. 197). The SRA model is better.

See also Sethares' "Adaptive tunings for musical scales."

This method calculates

\[ d=\frac{1}{2} {(a_1 a_2)^{0.1}} {\left( \frac{2\,min(a_1 , a_2)}{a_1 + a_2} \right) ^{3.11}} (e^{-3.5 F} - e^{-7.5 F}) \]

where

\[ F= S(min(a_1,a_2)) \left| f_1 - f_2 \right| \]

Components with frequencies beyond the default boundaries (amp <=threshold, 20Hz < f < 20kHz) don't contribute in the result.

Parameters
*xA pointer to the data structure of the class
a1The amplitude of the first spectral component
a2The amplitude of the second spectral component
f1The frequency of the first spectral component
f2The frequency of the second spectral component
Returns
the sensory roughness of the dyad
See also
d_Calculation(), S()
void roughometer_bang ( t_roughometer *  x)

Process a request for roughness calculation.

Parameters
xA pointer to the inner structure of the object

< set the flag to read the components

< reset the counters

void roughometer_initMatrix ( t_roughometer *  x)

Initializes the frequency and amplitude matrices as well as the solution, partial solution, and last pitch vector.

Parameters
xA pointer to the inner structure of the object
void* roughometer_new ( t_floatarg  n)

Instantiate the object.

Parameters
nnumber of spectra
cvicinity in cents
void roughometer_setOffset ( t_roughometer *  x,
t_floatarg  f 
)

Sets the minimum amplitude value to be considered for the Roughness calculation.

When working with soundfiles or captured audio, there is a noise that can distort the roughness calculation. This can be compensated by adjusting the threshold.

Parameters
xa pointer to the inner structure of the object
fthe new threshold in part per thousand
void roughometer_setup ( void  )

setup the object

static void roughometer_value ( t_proxy *  p,
t_symbol *  s,
int  argc,
t_atom *  argv 
)
static

Update the frequency and amplitude values for each instrument.

The list of arguments consists of the following elements: inlet_id, partial_id, frequency, amplitude, cos, sin or inlet_id, partial_id, frequency, amplitude, flag depending on the argument of sigmund~ (peaks or tracks, peaks are preferred). inlet_id corresponds to the number of the instrument.

Parameters
pthe inlet that is calling the method
argcthe number of elements in the list of arguments
argvthe list of arguments

the frequency component

the frequency value

the amplitude value

clear the flag

do the minimization

t_float S ( t_float  f)

Calculate S.

\[ S=\frac{0.24}{0.0207 f + 18.96} \]

Parameters
fthe minimum frequency of a dyad.
Returns
S
See also
dissonance()
void setCounters ( t_roughometer *  x,
t_int  value 
)

Sets the counters of processed income to the value indicated by the parameter 'value.

'

Parameters
xa pointer to the inner structure of the object
valuethe new value for the counters

Variable Documentation

t_class* proxy_class
static
t_class* roughometer_class
static