void node_noise::update_noise (sample* buf) { const sample_buffer* ampl_buf = get_input <sample_buffer>(LINK_CONTROL, IN_C_AMPLITUDE); const sample_buffer* trig_buf = get_input <sample_buffer>(LINK_CONTROL, IN_C_TRIGGER); link_envelope mod_env = get_in_envelope (LINK_CONTROL, IN_C_AMPLITUDE); link_envelope trig_env = get_in_envelope (LINK_CONTROL, IN_C_TRIGGER); const sample* ampl = ampl_buf ? (const sample*) &const_range (*ampl_buf)[0] : NULL; int n_samp = get_info().block_size; sample* out = buf; if (m_param_type == NOISE_PINK) if (ampl) while (n_samp--) *out++ = update_pink () * (m_param_ampl + m_param_ampl * *ampl++); else while (n_samp--) *out++ = update_pink () * m_param_ampl; else if (ampl) while (n_samp--) *out++ = update_white () * (m_param_ampl + m_param_ampl * *ampl++); else while (n_samp--) *out++ = update_white () * m_param_ampl; /* Modulate amplitude with trigger envelope. */ if (trig_buf) { n_samp = get_info().block_size; out = buf; const sample* trig = (const sample*) &const_range (*trig_buf)[0]; trig_env = get_in_envelope (LINK_CONTROL, IN_C_TRIGGER); while (n_samp--) { float env_val = (float) (audio_sample) trig_env.update(); *out = *out * ((1.0f - env_val) + (env_val * *trig)); ++out; ++trig; } } }
void node_sampler::do_update (const node0* caller, int caller_port_type, int caller_port) { audio_buffer* out = get_output<audio_buffer> (node0::LINK_AUDIO, OUT_A_OUTPUT); const sample_buffer* trig = get_input<sample_buffer> (node0::LINK_CONTROL, IN_C_TRIGGER); const sample* trig_buf = trig ? (const sample*) &const_range(*trig)[0] : 0; link_envelope trig_env = get_in_envelope (LINK_CONTROL, IN_C_TRIGGER); /* Read the data. */ size_t start = 0; size_t end = get_info ().block_size; if (m_reader) { while (start < get_info ().block_size) { if (m_restart) { if (trig_buf && trig_buf[start] != 0.0f) { restart(); m_restart = false; } } if (trig) end = synth::find_hill (const_range (*trig), start); read(*out, start, end); float env_val = (float) (audio_sample) trig_env.update (end - start); if (env_val == 1.0f && trig_buf && trig_buf[end - 1] == 0.0f) m_restart = true; start = end; } } else fill_frames (range (*out), audio_frame (0)); /* Set amplitude. */ transform_frames ( range (*out), range (*out), [&] (audio_frame in) -> audio_frame { static_transform (in, in, [&] (audio_sample in) -> audio_sample { return in * this->m_param_ampl; }); return in; }); /* Apply trigger envelope. */ if (trig_buf) { for (size_t i = 0; i < get_info ().num_channels; ++i) { sample* buf = (sample*) &range (*out)[0][i]; int n_samp = get_info ().block_size; trig_buf = (const sample*) &const_range (*trig)[0]; trig_env = get_in_envelope (LINK_CONTROL, IN_C_TRIGGER); while (n_samp--) { float env_val = (float) (audio_sample) trig_env.update(); *buf = *buf * ((1.0f - env_val) + (env_val * *trig_buf)); ++buf; ++trig_buf; } } } }