leaf-analysis.h
1 /*==============================================================================
2 
3  leaf-analysis.h
4  Created: 25 Oct 2019 10:30:52am
5  Author: Matthew Wang
6 
7  ==============================================================================*/
8 
9 #ifndef LEAF_ANALYSIS_H_INCLUDED
10 #define LEAF_ANALYSIS_H_INCLUDED
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16  //==============================================================================
17 
18 #include "leaf-global.h"
19 #include "leaf-mempool.h"
20 #include "leaf-distortion.h"
21 #include "leaf-math.h"
22 #include "leaf-filters.h"
23 #include "leaf-envelopes.h"
24 #include "leaf-delay.h"
25 
34  //==============================================================================
35 
78  typedef struct _tEnvelopeFollower
79  {
80 
81  tMempool mempool;
82  float y;
83  float a_thresh;
84  float d_coeff;
85 
86  } _tEnvelopeFollower;
87 
88  typedef _tEnvelopeFollower* tEnvelopeFollower;
89 
90  void tEnvelopeFollower_init (tEnvelopeFollower* const follower, float attackThreshold, float decayCoefficient, LEAF* const leaf);
91  void tEnvelopeFollower_initToPool (tEnvelopeFollower* const follower, float attackThreshold, float decayCoefficient, tMempool* const mempool);
92  void tEnvelopeFollower_free (tEnvelopeFollower* const follower);
93 
94  float tEnvelopeFollower_tick (tEnvelopeFollower* const follower, float sample);
95  void tEnvelopeFollower_setDecayCoefficient (tEnvelopeFollower* const follower, float decayCoefficient);
96  void tEnvelopeFollower_setAttackThreshold (tEnvelopeFollower* const follower, float attackThreshold);
97 
133  /* Zero Crossing Detector */
134  typedef struct _tZeroCrossingCounter
135  {
136 
137  tMempool mempool;
138  int count;
139  int maxWindowSize;
140  int currentWindowSize;
141  float invCurrentWindowSize;
142  float* inBuffer;
143  uint16_t* countBuffer;
144  int prevPosition;
145  int position;
146  } _tZeroCrossingCounter;
147 
148  typedef _tZeroCrossingCounter* tZeroCrossingCounter;
149 
150  void tZeroCrossingCounter_init (tZeroCrossingCounter* const, int maxWindowSize, LEAF* const leaf);
151  void tZeroCrossingCounter_initToPool (tZeroCrossingCounter* const, int maxWindowSize, tMempool* const mempool);
152  void tZeroCrossingCounter_free (tZeroCrossingCounter* const);
153 
154  float tZeroCrossingCounter_tick (tZeroCrossingCounter* const, float input);
155  void tZeroCrossingCounter_setWindowSize (tZeroCrossingCounter* const, float windowSize);
156 
157  // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
158 
199  /* PowerEnvelopeFollower */
200  typedef struct _tPowerFollower
201  {
202 
203  tMempool mempool;
204  float factor, oneminusfactor;
205  float curr;
206 
207  } _tPowerFollower;
208 
209  typedef _tPowerFollower* tPowerFollower;
210 
211  void tPowerFollower_init (tPowerFollower* const, float factor, LEAF* const leaf);
212  void tPowerFollower_initToPool (tPowerFollower* const, float factor, tMempool* const);
213  void tPowerFollower_free (tPowerFollower* const);
214 
215  float tPowerFollower_tick (tPowerFollower* const, float input);
216  float tPowerFollower_getPower (tPowerFollower* const);
217  void tPowerFollower_setFactor (tPowerFollower* const, float factor);
218 
219  // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
220 
258 #define MAXOVERLAP 32
259 #define INITVSTAKEN 64
260 #define ENV_WINDOW_SIZE 1024
261 #define ENV_HOP_SIZE 256
262 
263  typedef struct _tEnvPD
264  {
265 
266  tMempool mempool;
267  float buf[ENV_WINDOW_SIZE + INITVSTAKEN];
268  int x_phase; /* number of points since last output */
269  int x_period; /* requested period of output */
270  int x_realperiod; /* period rounded up to vecsize multiple */
271  int x_npoints; /* analysis window size in samples */
272  float x_result; /* result to output */
273  float x_sumbuf[MAXOVERLAP]; /* summing buffer */
274  float x_f;
275  int windowSize, hopSize, blockSize;
276  int x_allocforvs; /* extra buffer for DSP vector size */
277  } _tEnvPD;
278 
279  typedef _tEnvPD* tEnvPD;
280 
281  void tEnvPD_init (tEnvPD* const, int windowSize, int hopSize, int blockSize, LEAF* const leaf);
282  void tEnvPD_initToPool (tEnvPD* const, int windowSize, int hopSize, int blockSize, tMempool* const);
283  void tEnvPD_free (tEnvPD* const);
284 
285  float tEnvPD_tick (tEnvPD* const);
286  void tEnvPD_processBlock (tEnvPD* const, float* in);
287 
288  // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
289 
349 #define DEFBLOCKSIZE 1024
350 #define DEFTHRESHOLD 6
351 #define DEFATTACK 10
352 #define DEFRELEASE 10
353 
354  typedef struct _tAttackDetection
355  {
356  tMempool mempool;
357  float env;
358 
359  //Attack & Release times in msec
360  int atk;
361  int rel;
362 
363  //Attack & Release coefficients based on times
364  float atk_coeff;
365  float rel_coeff;
366 
367  int blocksize;
368  int samplerate;
369 
370  //RMS amplitude of previous block - used to decide if attack is present
371  float prevAmp;
372 
373  float threshold;
374  } _tAttackDetection;
375 
376  typedef _tAttackDetection* tAttackDetection;
377 
378  void tAttackDetection_init (tAttackDetection* const, int blocksize, int atk, int rel, LEAF* const leaf);
379  void tAttackDetection_initToPool (tAttackDetection* const, int blocksize, int atk, int rel, tMempool* const);
380  void tAttackDetection_free (tAttackDetection* const);
381 
382  void tAttackDetection_setBlocksize (tAttackDetection* const, int size);
383  void tAttackDetection_setSamplerate (tAttackDetection* const, int inRate);
384  void tAttackDetection_setAttack (tAttackDetection* const, int inAtk);
385  void tAttackDetection_setRelease (tAttackDetection* const, int inRel);
386  void tAttackDetection_setThreshold (tAttackDetection* const, float thres);
387  int tAttackDetection_detect (tAttackDetection* const, float *in);
388 
389  //==============================================================================
390 
447 #define SNAC_FRAME_SIZE 1024 // default analysis framesize // should be the same as (or smaller than?) PS_FRAME_SIZE
448 #define DEFOVERLAP 1 // default overlap
449 #define DEFBIAS 0.2f // default bias
450 #define DEFMINRMS 0.003f // default minimum RMS
451 #define SEEK 0.85f // seek-length as ratio of framesize
452 
453  typedef struct _tSNAC
454  {
455  tMempool mempool;
456 
457  float* inputbuf;
458  float* processbuf;
459  float* spectrumbuf;
460  float* biasbuf;
461  uint16_t timeindex;
462  uint16_t framesize;
463  uint16_t overlap;
464  uint16_t periodindex;
465 
466  float periodlength;
467  float fidelity;
468  float biasfactor;
469  float minrms;
470 
471  } _tSNAC;
472 
473  typedef _tSNAC* tSNAC;
474 
475  void tSNAC_init (tSNAC* const, int overlaparg, LEAF* const leaf);
476  void tSNAC_initToPool (tSNAC* const, int overlaparg, tMempool* const);
477  void tSNAC_free (tSNAC* const);
478 
479  void tSNAC_ioSamples (tSNAC *s, float *in, int size);
480  void tSNAC_setOverlap (tSNAC *s, int lap);
481  void tSNAC_setBias (tSNAC *s, float bias);
482  void tSNAC_setMinRMS (tSNAC *s, float rms);
483 
484  /*To get freq, perform SAMPLE_RATE/snac_getperiod() */
485  float tSNAC_getPeriod (tSNAC *s);
486  float tSNAC_getFidelity (tSNAC *s);
487 
554 #define DEFPITCHRATIO 1.0f
555 #define DEFTIMECONSTANT 100.0f
556 #define DEFHOPSIZE 64
557 #define DEFWINDOWSIZE 64
558 #define FBA 20
559 #define HPFREQ 20.0f
560 
561  typedef struct _tPeriodDetection
562  {
563  tMempool mempool;
564 
565  tEnvPD env;
566  tSNAC snac;
567  float* inBuffer;
568  float* outBuffer;
569  int frameSize;
570  int bufSize;
571  int framesPerBuffer;
572  int curBlock;
573  int lastBlock;
574  int i;
575  int indexstore;
576  int iLast;
577  int index;
578  float period;
579 
580  uint16_t hopSize;
581  uint16_t windowSize;
582  uint8_t fba;
583 
584  float timeConstant;
585  float radius;
586  float max;
587  float lastmax;
588  float deltamax;
589 
590  float fidelityThreshold;
591 
592  float history;
593  float alpha;
594  float tolerance;
595 
596  } _tPeriodDetection;
597 
598  typedef _tPeriodDetection* tPeriodDetection;
599 
600  void tPeriodDetection_init (tPeriodDetection* const, float* in, int bufSize, int frameSize, LEAF* const leaf);
601  void tPeriodDetection_initToPool (tPeriodDetection* const, float* in, int bufSize, int frameSize, tMempool* const);
602  void tPeriodDetection_free (tPeriodDetection* const);
603 
604  float tPeriodDetection_tick (tPeriodDetection* const, float sample);
605  float tPeriodDetection_getPeriod (tPeriodDetection* const);
606  float tPeriodDetection_getFidelity (tPeriodDetection* pd);
607  void tPeriodDetection_setHopSize (tPeriodDetection* const, int hs);
608  void tPeriodDetection_setWindowSize (tPeriodDetection* const, int ws);
609  void tPeriodDetection_setFidelityThreshold(tPeriodDetection* const, float threshold);
610  void tPeriodDetection_setAlpha (tPeriodDetection* const, float alpha);
611  void tPeriodDetection_setTolerance (tPeriodDetection* const, float tolerance);
612 
613  //==============================================================================
614 
615  // Maybe keep from here to tPeriodDetector internal?
616  typedef struct _tZeroCrossingInfo
617  {
618 
619  tMempool mempool;
620 
621  float _before_crossing;
622  float _after_crossing;
623 
624  float _peak;
625  int _leading_edge;// = undefined_edge; int_min
626  int _trailing_edge;// = undefined_edge;
627  float _width;// = 0.0f;
628  } _tZeroCrossingInfo;
629 
630  typedef _tZeroCrossingInfo* tZeroCrossingInfo;
631 
632  void tZeroCrossingInfo_init (tZeroCrossingInfo* const, LEAF* const leaf);
633  void tZeroCrossingInfo_initToPool (tZeroCrossingInfo* const, tMempool* const);
634  void tZeroCrossingInfo_free (tZeroCrossingInfo* const);
635 
636  int tZeroCrossingInfo_tick(tZeroCrossingInfo* const, float s);
637  int tZeroCrossingInfo_getState(tZeroCrossingInfo* const);
638  void tZeroCrossingInfo_updatePeak(tZeroCrossingInfo* const, float s, int pos);
639  int tZeroCrossingInfo_period(tZeroCrossingInfo* const, tZeroCrossingInfo* const next);
640  float tZeroCrossingInfo_fractionalPeriod(tZeroCrossingInfo* const, tZeroCrossingInfo* const next);
641  int tZeroCrossingInfo_getWidth(tZeroCrossingInfo* const);
642 
643  //==============================================================================
644 
645  typedef struct _tZeroCrossingCollector
646  {
647 
648  tMempool mempool;
649 
650  tZeroCrossingInfo* _info;
651  unsigned int _size;
652  unsigned int _pos;
653  unsigned int _mask;
654 
655  float _prev;// = 0.0f;
656  float _hysteresis;
657  int _state;// = false;
658  int _num_edges;// = 0;
659  int _window_size;
660  int _frame;// = 0;
661  int _ready;// = false;
662  float _peak_update;// = 0.0f;
663  float _peak;// = 0.0f;
664  } _tZeroCrossingCollector;
665 
666  typedef _tZeroCrossingCollector* tZeroCrossingCollector;
667 
668  void tZeroCrossingCollector_init (tZeroCrossingCollector* const, int windowSize, float hysteresis, LEAF* const leaf);
669  void tZeroCrossingCollector_initToPool (tZeroCrossingCollector* const, int windowSize, float hysteresis, tMempool* const);
670  void tZeroCrossingCollector_free (tZeroCrossingCollector* const);
671 
672  int tZeroCrossingCollector_tick(tZeroCrossingCollector* const, float s);
673  int tZeroCrossingCollector_getState(tZeroCrossingCollector* const);
674 
675  int tZeroCrossingCollector_getNumEdges(tZeroCrossingCollector* const zc);
676  int tZeroCrossingCollector_getCapacity(tZeroCrossingCollector* const zc);
677  int tZeroCrossingCollector_getFrame(tZeroCrossingCollector* const zc);
678  int tZeroCrossingCollector_getWindowSize(tZeroCrossingCollector* const zc);
679 
680  int tZeroCrossingCollector_isReady(tZeroCrossingCollector* const zc);
681  float tZeroCrossingCollector_getPeak(tZeroCrossingCollector* const zc);
682  int tZeroCrossingCollector_isReset(tZeroCrossingCollector* const zc);
683 
684  tZeroCrossingInfo const tZeroCrossingCollector_getCrossing(tZeroCrossingCollector* const zc, int index);
685 
686  void tZeroCrossingCollector_setHysteresis(tZeroCrossingCollector* const zc, float hysteresis);
687 
688  //==============================================================================
689 
690  typedef struct _tBitset
691  {
692 
693  tMempool mempool;
694 
695  unsigned int _value_size;
696  unsigned int _size;
697  unsigned int _bit_size;
698  unsigned int* _bits;
699  } _tBitset;
700 
701  typedef _tBitset* tBitset;
702 
703  void tBitset_init (tBitset* const bitset, int numBits, LEAF* const leaf);
704  void tBitset_initToPool (tBitset* const bitset, int numBits, tMempool* const mempool);
705  void tBitset_free (tBitset* const bitset);
706 
707  int tBitset_get (tBitset* const bitset, int index);
708  unsigned int* tBitset_getData (tBitset* const bitset);
709 
710  void tBitset_set (tBitset* const bitset, int index, unsigned int val);
711  void tBitset_setMultiple (tBitset* const bitset, int index, int n, unsigned int val);
712 
713  int tBitset_getSize (tBitset* const bitset);
714  void tBitset_clear (tBitset* const bitset);
715 
716 
717  //==============================================================================
718 
719  typedef struct _tBACF
720  {
721 
722  tMempool mempool;
723 
724  tBitset _bitset;
725  unsigned int _mid_array;
726  } _tBACF;
727 
728  typedef _tBACF* tBACF;
729 
730  void tBACF_init (tBACF* const bacf, tBitset* const bitset, LEAF* const leaf);
731  void tBACF_initToPool (tBACF* const bacf, tBitset* const bitset, tMempool* const mempool);
732  void tBACF_free (tBACF* const bacf);
733 
734  int tBACF_getCorrelation (tBACF* const bacf, int pos);
735  void tBACF_set (tBACF* const bacf, tBitset* const bitset);
736 
737  //==============================================================================
738 
794 #define PULSE_THRESHOLD 0.6f
795 #define HARMONIC_PERIODICITY_FACTOR 16 //16
796 #define PERIODICITY_DIFF_FACTOR 0.008f //0.008f
797 
798  typedef struct _auto_correlation_info
799  {
800  int _i1;// = -1;
801  int _i2;// = -1;
802  int _period;// = -1;
803  float _periodicity;// = 0.0f;
804  unsigned int _harmonic;
805  } _auto_correlation_info;
806 
807  typedef struct _sub_collector
808  {
809 
810  tMempool mempool;
811 
812  float _first_period;
813 
814  _auto_correlation_info _fundamental;
815 
816  // passed in, not initialized
817  tZeroCrossingCollector _zc;
818 
819  float _harmonic_threshold;
820  float _periodicity_diff_threshold;
821  int _range;
822  } _sub_collector;
823 
824  typedef struct _period_info
825  {
826  float period; // -1.0f
827  float periodicity;
828  } _period_info;
829 
830  typedef struct _tPeriodDetector
831  {
832  tMempool mempool;
833 
834  tZeroCrossingCollector _zc;
835  _period_info _fundamental;
836  unsigned int _min_period;
837  int _range;
838  tBitset _bits;
839  float _weight;
840  unsigned int _mid_point;
841  float _periodicity_diff_threshold;
842  float _predicted_period;// = -1.0f;
843  unsigned int _edge_mark;// = 0;
844  unsigned int _predict_edge;// = 0;
845  unsigned int _num_pulses; // = 0;
846  int _half_empty; // 0;
847 
848  tBACF _bacf;
849 
850  } _tPeriodDetector;
851 
852  typedef _tPeriodDetector* tPeriodDetector;
853 
854  void tPeriodDetector_init (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, LEAF* const leaf);
855  void tPeriodDetector_initToPool (tPeriodDetector* const detector, float lowestFreq, float highestFreq, float hysteresis, tMempool* const mempool);
856  void tPeriodDetector_free (tPeriodDetector* const detector);
857 
858  int tPeriodDetector_tick (tPeriodDetector* const detector, float sample);
859 
860  // get the periodicity for a given harmonic
861  float tPeriodDetector_getPeriod (tPeriodDetector* const detector);
862  float tPeriodDetector_getPeriodicity (tPeriodDetector* const detector);
863  float tPeriodDetector_harmonic (tPeriodDetector* const detector, int harmonicIndex);
864  float tPeriodDetector_predictPeriod (tPeriodDetector* const detector);
865  int tPeriodDetector_isReady (tPeriodDetector* const detector);
866  int tPeriodDetector_isReset (tPeriodDetector* const detector);
867 
868  void tPeriodDetector_setHysteresis (tPeriodDetector* const detector, float hysteresis);
869 
870  //==============================================================================
871 
926 #define ONSET_PERIODICITY 0.95f
927 #define MIN_PERIODICITY 0.9f
928 #define DEFAULT_HYSTERESIS -200.0f
929 
930  typedef struct _pitch_info
931  {
932  float frequency;
933  float periodicity;
934  } _pitch_info;
935 
936  typedef struct _tPitchDetector
937  {
938 
939  tMempool mempool;
940 
941  tPeriodDetector _pd;
942  _pitch_info _current;
943  int _frames_after_shift;// = 0;
944 
945  } _tPitchDetector;
946 
947  typedef _tPitchDetector* tPitchDetector;
948 
949  void tPitchDetector_init (tPitchDetector* const detector, float lowestFreq, float highestFreq, LEAF* const leaf);
950  void tPitchDetector_initToPool (tPitchDetector* const detector, float lowestFreq, float highestFreq, tMempool* const mempool);
951  void tPitchDetector_free (tPitchDetector* const detector);
952 
953  int tPitchDetector_tick (tPitchDetector* const detector, float sample);
954  float tPitchDetector_getFrequency (tPitchDetector* const detector);
955  float tPitchDetector_getPeriodicity (tPitchDetector* const detector);
956  float tPitchDetector_harmonic (tPitchDetector* const detector, int harmonicIndex);
957  float tPitchDetector_predictFrequency (tPitchDetector* const detector);
958  int tPitchDetector_indeterminate (tPitchDetector* const detector);
959 
960  void tPitchDetector_setHysteresis (tPitchDetector* const detector, float hysteresis);
961 
962 
963  //==============================================================================
964 
1031  typedef struct _tDualPitchDetector
1032  {
1033  tMempool mempool;
1034 
1035  tPeriodDetection _pd1;
1036  tPitchDetector _pd2;
1037  _pitch_info _current;
1038  float _mean;
1039  float _predicted_frequency;
1040  int _first;
1041 
1042  float highest, lowest;
1043  float thresh;
1044 
1045  } _tDualPitchDetector;
1046 
1047  typedef _tDualPitchDetector* tDualPitchDetector;
1048 
1049  void tDualPitchDetector_init (tDualPitchDetector* const detector, float lowestFreq, float highestFreq, float* inBuffer, int bufSize, LEAF* const leaf);
1050  void tDualPitchDetector_initToPool (tDualPitchDetector* const detector, float lowestFreq, float highestFreq, float* inBuffer, int bufSize, tMempool* const mempool);
1051  void tDualPitchDetector_free (tDualPitchDetector* const detector);
1052 
1053  int tDualPitchDetector_tick (tDualPitchDetector* const detector, float sample);
1054  float tDualPitchDetector_getFrequency (tDualPitchDetector* const detector);
1055  float tDualPitchDetector_getPeriodicity (tDualPitchDetector* const detector);
1056  float tDualPitchDetector_harmonic (tDualPitchDetector* const detector, int harmonicIndex);
1057  float tDualPitchDetector_predictFrequency (tDualPitchDetector* const detector);
1058 
1059  void tDualPitchDetector_setHysteresis (tDualPitchDetector* const detector, float hysteresis);
1060  void tDualPitchDetector_setPeriodicityThreshold (tDualPitchDetector* const detector, float thresh);
1061 
1062 
1063 
1064 
1065 #ifdef __cplusplus
1066 }
1067 #endif
1068 
1069 #endif // LEAF_ANALYSIS_H_INCLUDED
1070 
1071 //==============================================================================
1072 
1073 
1074 
1075 
tPeriodDetector_init
void tPeriodDetector_init(tPeriodDetector *const detector, float lowestFreq, float highestFreq, float hysteresis, LEAF *const leaf)
Initialize a tPeriodDetector to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:1505
tDualPitchDetector_tick
int tDualPitchDetector_tick(tDualPitchDetector *const detector, float sample)
Definition: leaf-analysis.c:2152
tAttackDetection_initToPool
void tAttackDetection_initToPool(tAttackDetection *const, int blocksize, int atk, int rel, tMempool *const)
Initialize a tAttackDetection to a specified mempool.
Definition: leaf-analysis.c:343
tAttackDetection_setRelease
void tAttackDetection_setRelease(tAttackDetection *const, int inRel)
Set release time and coeff.
Definition: leaf-analysis.c:393
tPeriodDetector_isReset
int tPeriodDetector_isReset(tPeriodDetector *const detector)
Definition: leaf-analysis.c:1652
tSNAC_setMinRMS
void tSNAC_setMinRMS(tSNAC *s, float rms)
Definition: leaf-analysis.c:566
tSNAC_setOverlap
void tSNAC_setOverlap(tSNAC *s, int lap)
Definition: leaf-analysis.c:547
tPowerFollower_tick
float tPowerFollower_tick(tPowerFollower *const, float input)
Pass a sample into the power follower and return the current power.
Definition: leaf-analysis.c:210
tPowerFollower_initToPool
void tPowerFollower_initToPool(tPowerFollower *const, float factor, tMempool *const)
Initialize a tPowerFollower to a specified mempool.
Definition: leaf-analysis.c:182
tPeriodDetection_setFidelityThreshold
void tPeriodDetection_setFidelityThreshold(tPeriodDetection *const, float threshold)
Definition: leaf-analysis.c:936
tSNAC_setBias
void tSNAC_setBias(tSNAC *s, float bias)
Definition: leaf-analysis.c:555
tAttackDetection_detect
int tAttackDetection_detect(tAttackDetection *const, float *in)
Find the largest transient in input block, return index of attack.
Definition: leaf-analysis.c:401
tAttackDetection_setSamplerate
void tAttackDetection_setSamplerate(tAttackDetection *const, int inRate)
Set attack detection sample rate.
Definition: leaf-analysis.c:369
tAttackDetection_setAttack
void tAttackDetection_setAttack(tAttackDetection *const, int inAtk)
Set attack time and coeff.
Definition: leaf-analysis.c:386
tZeroCrossingCounter_setWindowSize
void tZeroCrossingCounter_setWindowSize(tZeroCrossingCounter *const, float windowSize)
Set the size of the window. Cannot be greater than the max size given on initialization.
Definition: leaf-analysis.c:156
tPeriodDetection_free
void tPeriodDetection_free(tPeriodDetection *const)
Free a tPeriodDetection from its mempool.
Definition: leaf-analysis.c:868
tPeriodDetector_predictPeriod
float tPeriodDetector_predictPeriod(tPeriodDetector *const detector)
Definition: leaf-analysis.c:1611
tDualPitchDetector_harmonic
float tDualPitchDetector_harmonic(tDualPitchDetector *const detector, int harmonicIndex)
tEnvPD_init
void tEnvPD_init(tEnvPD *const, int windowSize, int hopSize, int blockSize, LEAF *const leaf)
Initialize a tEnvPD to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:230
tEnvPD_free
void tEnvPD_free(tEnvPD *const)
Free a tEnvPD from its mempool.
Definition: leaf-analysis.c:279
tAttackDetection_init
void tAttackDetection_init(tAttackDetection *const, int blocksize, int atk, int rel, LEAF *const leaf)
Initialize a tAttackDetection to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:338
tEnvelopeFollower_setDecayCoefficient
void tEnvelopeFollower_setDecayCoefficient(tEnvelopeFollower *const follower, float decayCoefficient)
Set the envelope decay coefficient.
Definition: leaf-analysis.c:68
tZeroCrossingCounter_tick
float tZeroCrossingCounter_tick(tZeroCrossingCounter *const, float input)
Tick the tZeroCrossingCounter.
Definition: leaf-analysis.c:117
tAttackDetection_free
void tAttackDetection_free(tAttackDetection *const)
Free a tAttackDetection from its mempool.
Definition: leaf-analysis.c:352
tSNAC_getFidelity
float tSNAC_getFidelity(tSNAC *s)
Definition: leaf-analysis.c:583
tPitchDetector_init
void tPitchDetector_init(tPitchDetector *const detector, float lowestFreq, float highestFreq, LEAF *const leaf)
Initialize a tPitchDetector to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:1887
tEnvPD_initToPool
void tEnvPD_initToPool(tEnvPD *const, int windowSize, int hopSize, int blockSize, tMempool *const)
Initialize a tEnvPD to a specified mempool.
Definition: leaf-analysis.c:235
tDualPitchDetector_predictFrequency
float tDualPitchDetector_predictFrequency(tDualPitchDetector *const detector)
Definition: leaf-analysis.c:2249
tPeriodDetection_setAlpha
void tPeriodDetection_setAlpha(tPeriodDetection *const, float alpha)
Definition: leaf-analysis.c:942
tSNAC_init
void tSNAC_init(tSNAC *const, int overlaparg, LEAF *const leaf)
Initialize a tSNAC to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:479
tDualPitchDetector_getFrequency
float tDualPitchDetector_getFrequency(tDualPitchDetector *const detector)
Definition: leaf-analysis.c:2235
tPowerFollower_init
void tPowerFollower_init(tPowerFollower *const, float factor, LEAF *const leaf)
Initialize a tPowerFollower to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:177
tPeriodDetection_tick
float tPeriodDetection_tick(tPeriodDetection *const, float sample)
Definition: leaf-analysis.c:877
tPeriodDetector_initToPool
void tPeriodDetector_initToPool(tPeriodDetector *const detector, float lowestFreq, float highestFreq, float hysteresis, tMempool *const mempool)
Initialize a tPeriodDetector to a specified mempool.
Definition: leaf-analysis.c:1510
tPeriodDetector_isReady
int tPeriodDetector_isReady(tPeriodDetector *const detector)
Definition: leaf-analysis.c:1645
tEnvelopeFollower_init
void tEnvelopeFollower_init(tEnvelopeFollower *const follower, float attackThreshold, float decayCoefficient, LEAF *const leaf)
Initialize a tEnvelopeFollower to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:25
tEnvPD_tick
float tEnvPD_tick(tEnvPD *const)
Definition: leaf-analysis.c:286
tZeroCrossingCounter_initToPool
void tZeroCrossingCounter_initToPool(tZeroCrossingCounter *const, int maxWindowSize, tMempool *const mempool)
Initialize a tZeroCrossingCounter to a specified mempool.
Definition: leaf-analysis.c:91
tPeriodDetector_setHysteresis
void tPeriodDetector_setHysteresis(tPeriodDetector *const detector, float hysteresis)
Set the hysteresis used in zero crossing detection.
Definition: leaf-analysis.c:1659
tPitchDetector_setHysteresis
void tPitchDetector_setHysteresis(tPitchDetector *const detector, float hysteresis)
Set the hysteresis used in zero crossing detection.
Definition: leaf-analysis.c:2002
tPeriodDetector_getPeriod
float tPeriodDetector_getPeriod(tPeriodDetector *const detector)
Get the periodicity for a given harmonic of the detected pitch.
Definition: leaf-analysis.c:1577
tDualPitchDetector_init
void tDualPitchDetector_init(tDualPitchDetector *const detector, float lowestFreq, float highestFreq, float *inBuffer, int bufSize, LEAF *const leaf)
Initialize a tDualPitchDetector to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:2117
tEnvelopeFollower_tick
float tEnvelopeFollower_tick(tEnvelopeFollower *const follower, float sample)
Tick the tEnvelopeFollower.
Definition: leaf-analysis.c:48
tPeriodDetection_setWindowSize
void tPeriodDetection_setWindowSize(tPeriodDetection *const, int ws)
Definition: leaf-analysis.c:930
tEnvPD_processBlock
void tEnvPD_processBlock(tEnvPD *const, float *in)
Definition: leaf-analysis.c:292
tPowerFollower_setFactor
void tPowerFollower_setFactor(tPowerFollower *const, float factor)
Set the smoothing factor for the moving average.
Definition: leaf-analysis.c:200
tDualPitchDetector_setHysteresis
void tDualPitchDetector_setHysteresis(tDualPitchDetector *const detector, float hysteresis)
Set the hysteresis used in zero crossing detection.
Definition: leaf-analysis.c:2258
tPitchDetector_predictFrequency
float tPitchDetector_predictFrequency(tPitchDetector *const detector)
Definition: leaf-analysis.c:1984
tPeriodDetector_free
void tPeriodDetector_free(tPeriodDetector *const detector)
Free a tPeriodDetector from its mempool.
Definition: leaf-analysis.c:1537
tPeriodDetection_getPeriod
float tPeriodDetection_getPeriod(tPeriodDetection *const)
Definition: leaf-analysis.c:912
tPeriodDetector_getPeriodicity
float tPeriodDetector_getPeriodicity(tPeriodDetector *const detector)
Definition: leaf-analysis.c:1584
tZeroCrossingCounter_init
void tZeroCrossingCounter_init(tZeroCrossingCounter *const, int maxWindowSize, LEAF *const leaf)
Initialize a tZeroCrossingCounter to the default mempool of a LEAF instance.
Definition: leaf-analysis.c:86
tPitchDetector_tick
int tPitchDetector_tick(tPitchDetector *const detector, float sample)
Definition: leaf-analysis.c:1912
tDualPitchDetector_initToPool
void tDualPitchDetector_initToPool(tDualPitchDetector *const detector, float lowestFreq, float highestFreq, float *inBuffer, int bufSize, tMempool *const mempool)
Initialize a tDualPitchDetector to a specified mempool.
Definition: leaf-analysis.c:2122
tAttackDetection_setBlocksize
void tAttackDetection_setBlocksize(tAttackDetection *const, int size)
Set expected input blocksize.
Definition: leaf-analysis.c:362
tPeriodDetector_harmonic
float tPeriodDetector_harmonic(tPeriodDetector *const detector, int harmonicIndex)
Definition: leaf-analysis.c:1591
tPitchDetector_getPeriodicity
float tPitchDetector_getPeriodicity(tPitchDetector *const detector)
Definition: leaf-analysis.c:1970
tZeroCrossingCounter_free
void tZeroCrossingCounter_free(tZeroCrossingCounter *const)
Free a tZeroCrossingCounter from its mempool.
Definition: leaf-analysis.c:107
tDualPitchDetector_setPeriodicityThreshold
void tDualPitchDetector_setPeriodicityThreshold(tDualPitchDetector *const detector, float thresh)
Set the threshold for periodicity of a signal to be considered as pitched.
Definition: leaf-analysis.c:2265
tPitchDetector_initToPool
void tPitchDetector_initToPool(tPitchDetector *const detector, float lowestFreq, float highestFreq, tMempool *const mempool)
Initialize a tPitchDetector to a specified mempool.
Definition: leaf-analysis.c:1892
tDualPitchDetector_getPeriodicity
float tDualPitchDetector_getPeriodicity(tDualPitchDetector *const detector)
Definition: leaf-analysis.c:2242
tPitchDetector_free
void tPitchDetector_free(tPitchDetector *const detector)
Free a tPitchDetector from its mempool.
Definition: leaf-analysis.c:1904
tEnvelopeFollower_setAttackThreshold
void tEnvelopeFollower_setAttackThreshold(tEnvelopeFollower *const follower, float attackThreshold)
Set the envelope attack threshold.
Definition: leaf-analysis.c:74
tSNAC_free
void tSNAC_free(tSNAC *const)
Free a tSNAC from its mempool.
Definition: leaf-analysis.c:507
tPowerFollower_free
void tPowerFollower_free(tPowerFollower *const)
Free a tPowerFollower from its mempool.
Definition: leaf-analysis.c:193
tAttackDetection_setThreshold
void tAttackDetection_setThreshold(tAttackDetection *const, float thres)
Set level above which values are identified as attacks.
Definition: leaf-analysis.c:380
tPeriodDetection_setHopSize
void tPeriodDetection_setHopSize(tPeriodDetection *const, int hs)
Definition: leaf-analysis.c:924
tEnvelopeFollower_free
void tEnvelopeFollower_free(tEnvelopeFollower *const follower)
Free a tEnvelopeFollower from its mempool.
Definition: leaf-analysis.c:41
tPeriodDetector_tick
int tPeriodDetector_tick(tPeriodDetector *const detector, float sample)
Definition: leaf-analysis.c:1548
tPitchDetector_getFrequency
float tPitchDetector_getFrequency(tPitchDetector *const detector)
Definition: leaf-analysis.c:1963
LEAF
Struct for an instance of LEAF.
Definition: leaf-global.h:31
tSNAC_initToPool
void tSNAC_initToPool(tSNAC *const, int overlaparg, tMempool *const)
Initialize a tSNAC to a specified mempool.
Definition: leaf-analysis.c:484
tEnvelopeFollower_initToPool
void tEnvelopeFollower_initToPool(tEnvelopeFollower *const follower, float attackThreshold, float decayCoefficient, tMempool *const mempool)
Initialize a tEnvelopeFollower to a specified mempool.
Definition: leaf-analysis.c:30
tPeriodDetection_setTolerance
void tPeriodDetection_setTolerance(tPeriodDetection *const, float tolerance)
Definition: leaf-analysis.c:948
tDualPitchDetector_free
void tDualPitchDetector_free(tDualPitchDetector *const detector)
Free a tDualPitchDetector from its mempool.
Definition: leaf-analysis.c:2142
tSNAC_getPeriod
float tSNAC_getPeriod(tSNAC *s)
Definition: leaf-analysis.c:576
tPowerFollower_getPower
float tPowerFollower_getPower(tPowerFollower *const)
Get the current power.
Definition: leaf-analysis.c:217
tPitchDetector_harmonic
float tPitchDetector_harmonic(tPitchDetector *const detector, int harmonicIndex)
Definition: leaf-analysis.c:1977