summaryrefslogtreecommitdiffstats
path: root/src/generator.h
blob: df90578a0c40fb3fa2375566cd6d8d4094f690a2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef GENERATOR_H
#define GENERATOR_H

#include "adsr.h"
#include "osc.h"
#include "synth_engine.h"

#define MAX_CMP 64

enum osc_enum {
  SIN,
  SAW,
  DIGISAW,
  TRI,
  SQR
};

enum adsr_type {
  LINEAR,
  CUBIC
};

enum target_enum {
  OSC_FREQ,
  OSC_AMP,
  ADSR_AMP,
  OUTPUT
};

// ints are:
// negative if false
// the id of the component if true
typedef struct sound_node {
  int osc;
  enum osc_enum osc_type;
  int lfo;
  enum adsr_enum adsr_type;
  int adsr;
  float target_amp;
  enum target_enum target;

  struct sound_node ** children;
  int n;
} sound_node;

struct generator {
  // list of indexes for oscilators, lfos and adsrs
  float osc[MAX_CMP];
  float lfo[MAX_CMP];
  float adsr[MAX_CMP];

  // need to include some info about the wiring of the oscs lfos and adsrs
  // e.g. :
  //   adsr 0 -> osc 0 frequency
  //   lfo 0  -> osc 0 frequency
  //   lfo 1  -> lfo 0 frequency
  //   osc 0  -> output

  //o0-saw:l0-sin:l1-sin:a0-linear
  //a0-o0/frequency:l0-o0/frequency:l1-l0/frequency:o0-1
};

int sound_tree_add_node(sound_node * root, const char * cmp);

// needs to "play" the wiring defined in the struct
// using sounds from `s` and the midi note `i`
float generate(generator * g, synth_t * s, int i);

#endif /* GENERATOR_H */