Exemplo n.º 1
0
	bool bin_index_t::file_node::first(data_t& key,data_t& val) const
	{
		open_index_file();

		index_t ind;
		if(!first_item(root_page,ind))return false;

		key=ind.key;
		key.resize(key_len);
		val.resize(ind.data_len);
		load_data(ind.data_offset,val);
		return true;
	}
Exemplo n.º 2
0
	bool bin_index_t::file_node::next(data_t& key,data_t& val) const
	{
		validate_key_len(key);
		open_index_file();

		if(!root_page)
			return false;
		
		index_t ind;
		align_key(key,ind);

		if(!next_item(root_page,ind))return false;

		key=ind.key;
		key.resize(key_len);
		val.resize(ind.data_len);
		load_data(ind.data_offset,val);
		return true;
	}
	void points2bin(const points_t& pts,data_t& bin)
	{
		bin.resize(pts.size()*2);
		for(unsigned i=0;i<pts.size();i++)
		{
			const point& p=pts[i];
			if(p.x<=-128||p.x>127||p.y<=-128||p.y>127)
				throw std::runtime_error("points2bin(): invalid point: ("+
				boost::lexical_cast<std::string>(p.x)+","
				+boost::lexical_cast<std::string>(p.y)+")");

			char x=p.x;
			char y=p.y;

			bin[i*2]=*reinterpret_cast<const unsigned char*>(&x);
			bin[i*2+1]=*reinterpret_cast<const unsigned char*>(&y);
		}
	}
Exemplo n.º 4
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);
}