Skip to content

Commit

Permalink
added vocal object and a function to set SVF type
Browse files Browse the repository at this point in the history
  • Loading branch information
spiricom committed Oct 21, 2023
1 parent 97b859e commit 768a294
Show file tree
Hide file tree
Showing 8 changed files with 1,117 additions and 10 deletions.
1 change: 1 addition & 0 deletions leaf/Inc/leaf-filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ extern "C" {
void tSVF_setFreqFast (tSVF* const vf, Lfloat cutoff);
void tSVF_setQ (tSVF* const, Lfloat Q);
void tSVF_setFreqAndQ (tSVF* const svff, Lfloat freq, Lfloat Q);
void tSVF_setFilterType (tSVF* const svff, SVFType type);
void tSVF_setSampleRate (tSVF* const svff, Lfloat sr);

//==============================================================================
Expand Down
16 changes: 8 additions & 8 deletions leaf/Inc/leaf-oscillators.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extern "C" {
tMempool mempool;
// Underlying phasor
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
int oct;
Lfloat w;
Expand Down Expand Up @@ -181,7 +181,7 @@ extern "C" {
tMempool mempool;
// Underlying phasor
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
int oct;
Lfloat w;
Expand Down Expand Up @@ -243,7 +243,7 @@ extern "C" {
tMempool mempool;
// Underlying phasor
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
int oct;
Lfloat w;
Expand Down Expand Up @@ -404,7 +404,7 @@ extern "C" {
{
tMempool mempool;
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
uint32_t width;
uint32_t oneMinusWidth;
Expand Down Expand Up @@ -467,7 +467,7 @@ extern "C" {
{
tMempool mempool;
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
Lfloat invSampleRate;
Lfloat invSampleRateTimesTwoTo32;
Expand Down Expand Up @@ -499,7 +499,7 @@ typedef struct _tPBSawSquare
{
tMempool mempool;
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
Lfloat invSampleRate;
Lfloat invSampleRateTimesTwoTo32;
Expand Down Expand Up @@ -534,7 +534,7 @@ void tPBSawSquare_setSampleRate (tPBSawSquare* const osc, Lfloat sr);
{
tMempool mempool;
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
int32_t mask;
uint8_t phaseDidReset;
Expand Down Expand Up @@ -593,7 +593,7 @@ void tPBSawSquare_setSampleRate (tPBSawSquare* const osc, Lfloat sr);

tMempool mempool;
uint32_t phase;
uint32_t inc;
int32_t inc;
Lfloat freq;
Lfloat invSampleRate;
Lfloat invSampleRateTimesTwoTo32;
Expand Down
201 changes: 201 additions & 0 deletions leaf/Inc/leaf-vocal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* leaf-vocal.h
*
* Created on: Oct 17, 2023
* Author: jeffsnyder
*/

#ifndef LEAF_VOCAL_H_INCLUDED
#define LEAF_VOCAL_H_INCLUDED

#include "leaf-math.h"
#include "leaf-mempool.h"
#include "leaf-filters.h"
#include "leaf-oscillators.h"

#define EPSILON 1.0e-38

#define MAX_TRANSIENTS 4



typedef struct _glottis
{
tMempool mempool;
Lfloat freq;
Lfloat tenseness;
Lfloat Rd;
Lfloat waveform_length;
Lfloat time_in_waveform;

Lfloat alpha;
Lfloat E0;
Lfloat epsilon;
Lfloat shift;
Lfloat delta;
Lfloat Te;
Lfloat omega;

Lfloat T;
} _glottis;

typedef _glottis* glottis;
void glottis_init(glottis *glo, LEAF* const leaf);
void glottis_initToPool(glottis *glo, tMempool* const mp);
Lfloat glottis_compute(glottis *glo);
void glottis_setup_waveform(glottis *glo);



typedef struct _transient
{
int position;
Lfloat time_alive;
Lfloat lifetime;
Lfloat strength;
Lfloat exponent;
char is_free;
unsigned int id;
struct _transient *next;
} _transient;

typedef _transient* transient;

typedef struct _transient_pool
{
transient pool[MAX_TRANSIENTS];
_transient *root;
int size;
int next_free;
} _transient_pool;

typedef _transient_pool* transient_pool;



typedef struct _tract
{
tMempool mempool;
int n;

Lfloat* diameter;
Lfloat* rest_diameter;
Lfloat* target_diameter;
Lfloat* new_diameter;
Lfloat* R;
Lfloat* L;
Lfloat* reflection;
Lfloat* new_reflection;
Lfloat* junction_outL;
Lfloat* junction_outR;
Lfloat* A;

int nose_length;


int nose_start;

int tip_start;
int blade_start;
int lip_start;

Lfloat tongueUpperBound;
Lfloat tongueLowerBound;

Lfloat* noseL;
Lfloat* noseR;
Lfloat* nose_junc_outL;
Lfloat* nose_junc_outR;
Lfloat* nose_reflection;
Lfloat* nose_diameter;
Lfloat* noseA;

Lfloat reflection_left;
Lfloat reflection_right;
Lfloat reflection_nose;

Lfloat new_reflection_left;
Lfloat new_reflection_right;
Lfloat new_reflection_nose;

Lfloat velum_target;

Lfloat glottal_reflection;
Lfloat lip_reflection;
int last_obstruction;
Lfloat fade;
Lfloat movement_speed;
Lfloat lip_output;
Lfloat nose_output;
Lfloat block_time;

tSVF fricativeNoiseFilt[2];
tSVF aspirationNoiseFilt;
tNoise whiteNoise;

Lfloat turbuluencePointPosition[2];
Lfloat turbuluencePointDiameter[2];
transient_pool tpool;
Lfloat T;
} _tract;

typedef _tract* tract;
void tract_init(tract *t, LEAF* const leaf);
void tract_initToPool(tract *t, tMempool* const mp);
void tract_calculate_reflections(tract *t);
void tract_reshape(tract *t);
void tract_compute(tract *t, Lfloat in, Lfloat lambda);
void tract_calculate_nose_reflections(tract *t);
int append_transient(transient_pool *pool, int position);
void remove_transient(transient_pool *pool, unsigned int id);
Lfloat move_towards(Lfloat current, Lfloat target,
Lfloat amt_up, Lfloat amt_down);
void tract_addTurbulenceNoise(tract* const t);
void tract_addTurbulenceNoiseAtPosition(tract* const t, Lfloat turbulenceNoise, Lfloat position, Lfloat diameter);



typedef struct _tVoc
{
tMempool mempool;
glottis glot; /*The Glottis*/
tract tr; /*The Vocal Tract */

//Lfloat* buf;
int counter;
int sampleRate;
} _tVoc;

typedef _tVoc* tVoc;

void tVoc_init (tVoc* const voc, LEAF* const leaf);
void tVoc_initToPool (tVoc* const voc, tMempool* const mempool);
void tVoc_free (tVoc* const voc);

Lfloat tVoc_tick (tVoc* const voc);

void tVoc_tractCompute (tVoc* const voc, Lfloat *in, Lfloat *out);
void tVoc_setSampleRate(tVoc* const voc, Lfloat sr);


void tVoc_setFreq (tVoc* const voc, Lfloat freq);



Lfloat* tVoc_get_tract_diameters(tVoc* const voc);
Lfloat* tVoc_get_current_tract_diameters(tVoc* const voc);
Lfloat* tVoc_get_tract_rest_diameters(tVoc* const voc);
int tVoc_get_tract_size(tVoc* const voc);
Lfloat* tVoc_get_nose_diameters(tVoc* const voc);
int tVoc_get_nose_size(tVoc* const voc);
void tVoc_set_tongue_shape_and_touch(tVoc* const voc, Lfloat tongue_index, Lfloat tongue_diameter, Lfloat touch_index, Lfloat touch_diameter);
void tVoc_set_tongue_and_touch_diameters(tVoc* const voc, Lfloat tongue_index, Lfloat tongue_diameter, Lfloat touch_index, Lfloat touch_diameter, Lfloat *theDiameters);
void tVoc_set_tenseness(tVoc* const voc, Lfloat breathiness);
Lfloat * tVoc_get_tenseness_ptr(tVoc* const voc);
void tVoc_set_velum(tVoc* const voc, Lfloat velum);
Lfloat * tVoc_get_velum_ptr(tVoc* const voc);

int tVoc_get_counter(tVoc* const voc);


#endif /* INC_LEAF_VOCAL_H_ */
5 changes: 3 additions & 2 deletions leaf/Src/leaf-effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1531,9 +1531,10 @@ void tSimpleRetune_free (tSimpleRetune* const rt)
tPitchShift_free(&r->ps[i]);
}
mpool_free((char*)r->shiftValues, r->mempool);
mpool_free((char*)r->ps, r->mempool);
mpool_free((char*)r->inBuffer, r->mempool);
//mpool_free((char*)r->ps, r->mempool);
mpool_free((char*)r->outBuffer, r->mempool);
mpool_free((char*)r->inBuffer, r->mempool);
mpool_free((char*)r->pdBuffer, r->mempool);
mpool_free((char*)r, r->mempool);
}

Expand Down
44 changes: 44 additions & 0 deletions leaf/Src/leaf-filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,50 @@ void tSVF_setFreqAndQ(tSVF* const svff, Lfloat freq, Lfloat Q)
svf->a3 = svf->g * svf->a2;
}

void tSVF_setFilterType(tSVF* const svff, SVFType type)
{
_tSVF* svf = *svff;

if (type == SVFTypeLowpass)
{
svf->cH = 0.0f;
svf->cB = 0.0f;
svf->cBK = 0.0f;
svf->cL = 1.0f;
}
else if (type == SVFTypeBandpass)
{
svf->cH = 0.0f;
svf->cB = 1.0f;
svf->cBK = 0.0f;
svf->cL = 0.0f;
}

else if (type == SVFTypeHighpass)
{
svf->cH = 1.0f;
svf->cB = 0.0f;
svf->cBK = -1.0f;
svf->cL = -1.0f;
}

else if (type == SVFTypeNotch)
{
svf->cH = 1.0f;
svf->cB = 0.0f;
svf->cBK = -1.0f;
svf->cL = 0.0f;
}

else if (type == SVFTypePeak)
{
svf->cH = 1.0f;
svf->cB = 0.0f;
svf->cBK = -1.0f;
svf->cL = -2.0f;
}
}

void tSVF_setSampleRate (tSVF* const svff, Lfloat sr)
{
_tSVF* svf = *svff;
Expand Down
Loading

0 comments on commit 768a294

Please sign in to comment.