if (inputs_are_all_sample_data) { // For sample data CTKSample sample; (*input_sockets)[0]->get_sample(sample); if (sample<param_1) sample=param_1; (*output_sockets)[0]->put_sample(sample); } else { // For frame data CTKVector *xv0; (*input_sockets)[0]->get_vector(xv0); for (CTKVector::iterator fp=xv0->begin(); fp end(); ++fp) if (*fp<pram_1) *fp=param_1; (*output_sockets)[0]->put_vector(xv0); }
Now, the get_vector and put_vector can handle sample data transparently. The get_vector will look first at the vector buffer and if that fails then look to the sample buffer. The put_vector will check if the vector is size 1, and if so it will send its contents via the sample buffer. This is an inefficient way of handling sample data, but it means that for blocks that are essentially designed for vector input/output (but which might get samples as a bizarre case) the compute method can now be written more simply. For example the Floor block compute can now be written (inefficiently but equivalently) as:
The methods read_vector(), write_vector() and flush_vector() - i.e. the methods for getting and putting more than one vector at a time - have been similarly rewritten so that they can handle sample data if necessary.
/// For frame OR sample data CTKVector *xv0; (*input_sockets)[0]->get_vector(xv0); for (CTKVector::iterator fp=xv0->begin(); fp end(); ++fp) if (*fp< param_1) *fp=param_1; (*output_sockets)[0]->put_vector(xv0);