Rev 2267 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1528 | jag | 1 | /* |
2 | * play.h |
||
2302 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2025 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1528 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
6 | */ |
||
7 | |||
8 | |||
9 | #ifndef PLAY |
||
10 | #define PLAY |
||
11 | |||
12 | #include "note.h" |
||
13 | #include "curve_mixer.h" |
||
14 | |||
15 | // |
||
16 | // renders a tone |
||
17 | // |
||
18 | |||
19 | struct solver; |
||
20 | |||
21 | struct play : set_mixer { |
||
22 | |||
23 | // pitch |
||
24 | // |
||
25 | solver* sol; // solver linked to waveform |
||
26 | float x; // current x on the waveform; x usually goes from 0 to 1. 0 = waveform start, 1 = waveform end ie 1 cycle. |
||
27 | float dx; // change of x every sample; determines how fast the waveform is sampled and hence frequency of the tone (equivalent to variable step in note.h) |
||
28 | float* pdx; // array of dx [interpolated from last to present for smooth frequency change] |
||
29 | |||
30 | // volume |
||
31 | // |
||
32 | float vol; // current volume |
||
33 | float* pvol; // array of volumes [interpolated from last to present for smooth volume change] |
||
34 | |||
35 | // for calculation of pdx and pvol |
||
36 | // |
||
37 | float da; // delta alpha |
||
38 | int n; // buffer size |
||
39 | int n_1; // n-1 |
||
40 | |||
41 | // for mixing waveforms |
||
42 | curve_mixer mixer; |
||
1799 | jag | 43 | void set_mix (multi_curve& crv, const std::string& nam); |
1528 | jag | 44 | |
45 | play (solver* s); |
||
46 | play (); |
||
47 | play (const play&); |
||
48 | ~play (); |
||
49 | void alloc (); |
||
50 | void realloc (); |
||
51 | |||
52 | void init (); |
||
53 | |||
54 | inline void set_wave (solver* s) { sol = s;} |
||
55 | inline void set_step (float xd) {dx = xd;} |
||
56 | inline void set_volume (float v) {vol = v;} |
||
57 | inline void set (float xd, float l, float r) {dx = xd; vol = l;} |
||
58 | |||
59 | void interpolate_buffer (float* buf, float s, float e); |
||
60 | void fill_pitch (float xd); |
||
61 | void fill_volume (float v); |
||
62 | void set_interpolated_pitch (float xd); |
||
63 | void set_interpolated_pitch (float xd, int check); |
||
64 | void set_interpolated_volume (float v); |
||
65 | void set_interpolated_volume (float v, int check); |
||
66 | |||
67 | void set_interpolated_pitch_volume (float xd, float v) { |
||
68 | set_interpolated_pitch (xd); |
||
69 | set_interpolated_volume (v); |
||
70 | } |
||
71 | |||
72 | void set_interpolated_pitch_volume (float xd, float v, int check) { |
||
73 | set_interpolated_pitch (xd, check); |
||
74 | set_interpolated_volume (v, check); |
||
75 | } |
||
76 | |||
77 | inline void operator() (float* out, int n, float* wav, float vol) { |
||
78 | // no modulation audio output |
||
79 | for (int i = 0; i < n; ++i) out[i] += (vol * wav[i]); |
||
80 | } |
||
81 | |||
82 | inline void operator() (float* out, int n, float* wav, float* vola) { |
||
83 | // no modulation audio output with volume array |
||
84 | for (int i = 0; i < n; ++i) out[i] += (vola[i] * wav[i]); |
||
85 | } |
||
86 | |||
87 | void operator() (float* out, int n, float* wav, float* am, float vol) { |
||
88 | // AM modulation in audio output |
||
89 | for (int i = 0; i < n; ++i) out[i] += ((vol + am[i]) * wav[i]); |
||
90 | } |
||
91 | |||
92 | void gen_wav_and_mix (float* wav, int n); |
||
93 | void gen_wav_fm (solver& s, float& xx, float* wav, float* fm, int n); |
||
94 | void gen_wav_am (float* out, float* wav, float* am, int n); |
||
95 | void gen_wav_fm_am_mix (float* out, int n); |
||
96 | void gen_wav_mix (float* out, float vol, int n); |
||
97 | void gen_wav_mix (float* out, float* vol, int n); |
||
98 | void master (float* left, float* right, float* wav, int n, float* vol); |
||
99 | void master (float* left, float* right, float* wav, int n, float vol); |
||
2267 | jag | 100 | void master (float* L, float* wav, int n, float* vol); |
2266 | jag | 101 | void master (float* L, float* wav, int n, float vol); |
1528 | jag | 102 | |
103 | }; |
||
104 | |||
105 | #endif |