| 31 | {} |
| 32 | |
| 33 | void process(out_channels const& out) |
| 34 | { |
| 35 | auto left = out[0]; |
| 36 | auto right = out[1]; |
| 37 | for (auto frame : out.frames) |
| 38 | { |
| 39 | // Generate the ADSR envelope |
| 40 | auto env_ = env() * velocity; |
| 41 | |
| 42 | // Set the filter frequency |
| 43 | filter.cutoff(env_); |
| 44 | |
| 45 | // Synthesize the square wave |
| 46 | auto val = q::square(phase++); |
| 47 | |
| 48 | // Apply the envelope (amplifier and filter) with soft clip |
| 49 | val = clip(filter(val) * env_); |
| 50 | |
| 51 | // Output |
| 52 | right[frame] = left[frame] = val; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | q::phase_iterator phase; // The phase iterator |
| 57 | q::adsr_envelope_gen env; // The envelope generator |