Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fftw_complex *genenerate_fft_noise(uint width, uint height, double power, double lower, double upper) {
- fftw_plan plan;
- uint size = width * height;
- fftw_complex *in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * size);
- fftw_complex *out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * size);
- fftw_complex *in_end = in + size;
- fftw_complex *out_end = out + size;
- fftw_complex *p;
- for (p = in; p < in_end; p++) {
- double a = 2. * PI * Random() / UINT32_MAX;
- (*p)[0] = std::cos(a);
- (*p)[1] = std::sin(a);
- }
- plan = fftw_plan_dft_2d(MapSizeY(), MapSizeX(), in, out, FFTW_FORWARD, FFTW_ESTIMATE);
- fftw_execute(plan);
- fftw_destroy_plan(plan);
- p = out;
- for (size_t y = 0; y < height; y++) {
- auto fy = fftfreq(y, height);
- for (size_t x = 0; x < width; x++, p++) {
- auto f = std::hypot(fy, fftfreq(x, width));
- auto e = (f > lower ? std::pow(f, power) : 0.);
- (*p)[0] *= e;
- (*p)[1] *= e;
- }
- }
- plan = fftw_plan_dft_2d(height, width, out, in, FFTW_BACKWARD, FFTW_ESTIMATE);
- fftw_execute(plan);
- fftw_destroy_plan(plan);
- fftw_free(out);
- normalize(in, in_end);
- return in;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement