Beispiel #1
0
void session_interface::load_data(data_t &data,std::string const &s)
{
    data.clear();
    char const *begin=s.data(),*end=begin+s.size();
    while(begin < end) {
        packed p(begin,end);
        begin +=sizeof(p);
        if(end - begin >= int(p.key_size + p.data_size)) {
            string key(begin,begin+p.key_size);
            begin+=p.key_size;
            string val(begin,begin+p.data_size);
            begin+=p.data_size;
            entry &ent=data[key];
            ent.exposed = p.exposed;
            ent.value.swap(val);
        }
        else {
            throw cppcms_error("sessions::format violation data");
        }

    }

}
Beispiel #2
0
/** This is an autarc function to precalculate the frequency 
 * domain filter partitions that a \b Convolver needs. It does 
 * not require an instantiation of a \b Convolver. However, it is 
 * not very efficient since an FFT plan is created with every call.
 * @param container place to store the partitions.
 * @param filter impulse response of the filter
 * @param filter_size size of the impulse response
 * @param partition_size size of the partitions (this is the 
 * partition size that the outside world sees, internally it is twice as long)
 */
void Convolver::prepare_impulse_response(data_t& container, const float *filter,
		const unsigned int filter_size, const unsigned int partition_size)
{

	// find out how many complete partitions we have
	unsigned int no_of_partitions = filter_size / partition_size;

	// if there is even one more
	if (filter_size % partition_size)
		no_of_partitions++;

	// empty container
	container.clear();

	// allocate memory
	container.resize(2 * no_of_partitions * partition_size, 0.0f);

	// define temporary buffers
	data_t fft_buffer;
	data_t zeros;

	// allocate memory and initialize to 0
	fft_buffer.resize(2 * partition_size, 0.0f);
	zeros.resize(2 * partition_size, 0.0f);

	// create fft plans for halfcomplex data format
	fftwf_plan fft_plan = fftwf_plan_r2r_1d(2 * partition_size, &fft_buffer[0],
			&fft_buffer[0], FFTW_R2HC, FFTW_ESTIMATE);

	// convert filter partitionwise to frequency domain

	/////// process complete partitions //////////////

	for (unsigned int partition = 0u; partition < no_of_partitions - 1;
			partition++)
	{
		std::copy(filter + partition * partition_size,
				filter + (partition + 1) * partition_size, fft_buffer.begin());

		// zero pad
		std::copy(zeros.begin(), zeros.begin() + partition_size,
				fft_buffer.begin() + partition_size);

		// fft
		fftwf_execute(fft_plan);
		sort_coefficients(fft_buffer, 2 * partition_size);

		// add the partition to the filter
		std::copy(fft_buffer.begin(), fft_buffer.begin() + 2 * partition_size,
				container.begin() + 2 * partition * partition_size);

	}

	////// end process complete partitions

	//// process potentially incomplete last partition ////////////

	// zeros
	std::copy(zeros.begin(), zeros.end(), fft_buffer.begin());

	// add filter coefficients
	std::copy(filter + (no_of_partitions - 1) * partition_size,
			filter + filter_size, fft_buffer.begin());

	// fft
	fftwf_execute(fft_plan);
	sort_coefficients(fft_buffer, 2 * partition_size);

	// add the partition to the filter
	std::copy(fft_buffer.begin(), fft_buffer.end(),
			container.begin() + 2 * (no_of_partitions - 1) * partition_size);

	///// end process potentially incomplete partition ////////

	// clean up
	fftwf_destroy_plan(fft_plan);
}