示例#1
0
void soft_buffer_in_port<B>::rt_process (rt_process_context& ctx)
{
    typedef typename B::value_type frame_type;

    if (_requested)
        _envelope.release ();
    _envelope.update (); // Hack, skips one frame
    
    if (_requested && (!this->rt_connected () ||
                       _envelope.finished ()))
    {
        this->_rt_connect (_request_source);
        if (_request_source) 
            _envelope.press ();
        _requested = false;
    }

    base_type::rt_process (ctx);    
    if (this->rt_in_available ())
    {
        _envelope.update (range (_local_buffer));
        
        synth::blend (const_range (base_type::rt_get_in ()),
                      range (_local_buffer),
                      _stable_value,
                      range (_local_buffer));
        
    }
    else
    {
        _envelope.update (ctx.block_size ());
        sound::fill_frames (range (_local_buffer),
                            frame_type (_stable_value));
    }
}
示例#2
0
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;
	}
    }
}
示例#3
0
    void deps_object::test<2>()
    {
        typedef LLDependencies<std::string, int> NameIndexDeps;
        NameIndexDeps nideps;
        const NameIndexDeps& const_nideps(nideps);
        nideps.add("def", 2, list_of("ghi"));
        nideps.add("ghi", 3);
        nideps.add("abc", 1, list_of("def"));
        NameIndexDeps::range range(nideps.get_range());
        ensure_equals(range.begin()->first, "abc");
        ensure_equals(range.begin()->second, 1);
        range.begin()->second = 0;
        range.begin()->second = 1;
        NameIndexDeps::const_range const_range(const_nideps.get_range());
        NameIndexDeps::const_iterator const_iterator(const_range.begin());
        ++const_iterator;
        ensure_equals(const_iterator->first, "def");
        ensure_equals(const_iterator->second, 2);
//        NameIndexDeps::node_range node_range(nideps.get_node_range());
//        ensure_equals(instance_from_range<std::vector<int> >(node_range), make< std::vector<int> >(list_of(1)(2)(3)));
//        *node_range.begin() = 0;
//        *node_range.begin() = 1;
        NameIndexDeps::const_node_range const_node_range(const_nideps.get_node_range());
        ensure_equals(instance_from_range<std::vector<int> >(const_node_range), make< std::vector<int> >(list_of(1)(2)(3)));
        NameIndexDeps::const_key_range const_key_range(const_nideps.get_key_range());
        ensure_equals(instance_from_range<StringList>(const_key_range), make<StringList>(list_of("abc")("def")("ghi")));
        NameIndexDeps::sorted_range sorted(const_nideps.sort());
        NameIndexDeps::sorted_iterator sortiter(sorted.begin());
        ensure_equals(sortiter->first, "ghi");
        ensure_equals(sortiter->second, 3);

        // test all iterator-flavored versions of get_after_range()
        StringList def(make<StringList>(list_of("def")));
        ensure("empty abc before list", is_empty(nideps.get_before_range(nideps.get_range().begin())));
        ensure_equals(instance_from_range<StringList>(nideps.get_after_range(nideps.get_range().begin())),
                      def);
        ensure_equals(instance_from_range<StringList>(const_nideps.get_after_range(const_nideps.get_range().begin())),
                      def);
//        ensure_equals(instance_from_range<StringList>(nideps.get_after_range(nideps.get_node_range().begin())),
//                      def);
        ensure_equals(instance_from_range<StringList>(const_nideps.get_after_range(const_nideps.get_node_range().begin())),
                      def);
        ensure_equals(instance_from_range<StringList>(nideps.get_after_range(nideps.get_key_range().begin())),
                      def);
        // advance from "ghi" to "def", which must come after "ghi"
        ++sortiter;
        ensure_equals(instance_from_range<StringList>(const_nideps.get_after_range(sortiter)),
                      make<StringList>(list_of("ghi")));
    }
示例#4
0
void node_sampler::read (audio_buffer& buf, int start, int end)
{
    const sample_buffer* rate = get_input<sample_buffer> (
        node0::LINK_CONTROL, IN_C_RATE);
    const sample* rate_buf = rate ? (const sample*) &const_range (*rate) [0] : 0;

    float base_factor =
	(float) m_reader->frame_rate () / get_info ().sample_rate * m_param_rate;

    int must_read;
    int nread;
    float factor;

    bool backwards = false;;
    bool high_latency = false;

    if (m_update_mutex.try_lock ())
    {
        m_scaler.set_tempo (m_param_tempo);
        m_scaler.set_pitch (m_param_pitch);
        m_update_mutex.unlock ();
    }

    if (m_param_tempo != 1.0f ||
	m_param_pitch != 1.0f)
	high_latency = true;

    if (base_factor < 0) {
	backwards = true;
	base_factor = -base_factor;
    }
    factor = base_factor;

    assert(end >= start);
    while(m_scaler.available() < static_cast<std::size_t>(
            (high_latency ?
             TIME_STRETCH_MIN_SAMPLES :
             end - start))) {
        if (rate)
	    factor = base_factor + base_factor * rate_buf[(int) m_ctrl_pos];

	if (backwards != m_fetcher.is_backwards ())
	    m_fetcher.set_backwards (backwards);

	if (factor < 0.2)
	    factor = 0.2;

	must_read = high_latency ? get_info ().block_size : SMALL_BLOCK_SIZE;
	if (factor * m_param_tempo < 1.0)
	    must_read = (float)must_read * factor * m_param_tempo;
	else
	    must_read = must_read;

	m_update_mutex.lock();
	nread = m_fetcher.take (sub_range (range (m_inbuf), 0, must_read));

	if (nread)
        {
	    m_ctrl_pos += (float) nread / (factor * m_param_tempo);
	    if (m_ctrl_pos >= get_info ().block_size)
		m_ctrl_pos = base::phase(m_ctrl_pos) +
                    ((int) m_ctrl_pos % get_info ().block_size);

            m_scaler.set_rate (factor);
	    m_scaler.update (sub_range (range (m_inbuf), 0, nread));
	}

	m_update_mutex.unlock();
    }

    m_update_mutex.lock();
    m_scaler.receive (sub_range (range (m_inbuf), 0, end - start));
    m_update_mutex.unlock();

    copy_and_convert_frames (sub_range (range (m_inbuf), 0, end - start),
                             sub_range (range (buf), start, end - start));
}
示例#5
0
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;
	    }
	}
    }

}
示例#6
0
    result_type operator () (const Buffer& img) const
    {
	return result_type (const_range (img));
    }