summaryrefslogblamecommitdiffstats
path: root/src/synth_engine.h
blob: 38ff740ef4d16527ff9d5f5accb8e131839a86e4 (plain) (tree)
1
2
3
4
5
6
7
8
9







                      
                         

                   
                 
                    
 
 



                          


                      
                             
        
 





                               

                  
                             
                                   




                      
                          
                      
         


                
                   







                    
                  
  



                    

                                    

              

            

             
           

             

            


                    
                                                                                           

           
               
 
                 
                   
 

             


            
                                 
                                 

                           
#ifndef SYNTH_ENGINE_H
#define SYNTH_ENGINE_H

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <portaudio.h>

#include "synth_common.h"
#include "notes.h"
#include "filter.h"
#include "adsr.h"
#include "control.h"


#ifndef M_PI
#define M_PI  (3.14159265)
#endif

typedef struct lfo_t {
  float freq;
  float amp;
  unsigned long long elapsed;
} lfo_t;

typedef struct midi_note_t {
  float freq;
  int channel;
  PaTime noteOn;
  PaTime noteOff;
  float velocity; // normalized
  float wvt_index;
  float lfo_index;
  unsigned long long elapsed;
  unsigned long long noteOffSample;
  adsr_t * adsr;
  int active;
} midi_note_t;

typedef struct viz_t {
  int sample_rate_divider;
  float wave[VIZ_BUF];
  int wi;
} viz_t;

typedef struct {
  PaStream *stream;

  cc_t * ccs[128];
  int cci;
  
  cc_t cc_pitch;
  cc_t cc_cutoff;
  cc_t cc_resonance;
  cc_t cc_lfo_freq;
  cc_t cc_lfo_amp;
  
  float freq_offset;
  float gain;
  float x;

  midi_note_t midi_note[MIDI_NOTES];

  adsr_t adsr;

  lfo_t lfo;

  int octave;

  int poly;
  int multi;
  int filter;
  int clamp;

  int modifiers[16];
  int modi;

  float (*gen[7]) (float freq, midi_note_t * midi_note, float x, unsigned int sample_rate);
  int geni;

  float cutoff;

  BWLowPass* fff;
  BWBandStop* fff2;

  int active;
  
  viz_t viz;
} synth_t;

void init_synth(synth_t * synth);
void free_synth(synth_t * synth);

#endif /* SYNTH_ENGINE_H */