void random_test(int filter, int level) { int16_t *a = tmp+10; float sintable[N]; float costable[N]; float dr[N]; float di[N]; float sr[N]; float si[N]; double power[N]; int i; int j; double total; int n_cycles = 10000; int amplitude = 100; double p0 = 0; for(i=0;i<N;i++){ power[i] = 0; } for(j=0;j<n_cycles;j++){ for(i=0;i<N;i++){ a[i] = 0; } if (level == 0) { for(i=0;i<(N>>4);i++){ a[i]=floor(0.5 + amplitude*random_std()); } } else if (level<5) { for(i=((N>>5)<<level);i<((N>>4)<<level);i++){ a[i]=floor(0.5 + amplitude*random_std()); } } else if (level==5) {
void test_warping (size_t large_size = 1000, size_t small_size = 300) { LOG("building warping object : " << large_size << " --> " << small_size); TestWarpFwd warp_fwd; Spline w(large_size, small_size, warp_fwd); LOG("defining input sequence"); Vector<float> large_in(large_size); Vector<float> small_out(small_size); Vector<float> large_out(large_size); for (size_t i = 0; i < large_size; ++i) { float t = (0.5f + i) / large_size; large_in[i] = sin(4 * 2 * M_PI * t) * t + 0.1 * random_std(); } LOG("transforming forward and backward"); w.transform_fwd(large_in, small_out); w.transform_bwd(small_out, large_out); LOG("RMS inversion error = " << rms_error(large_in, large_out) << " (should be ~ 0.1)"); }
double gain_test(int filter, int level, int n_levels) { int16_t *a = tmp+10; double gain; int i; int j; double p1,p2; gain = 0; for(j=0;j<10000;j++){ p1 = 0; p2 = 0; for(i=0;i<N;i++){ a[i] = 0; } if (level == 0) { for(i=0;i<N>>n_levels;i++){ a[i]=floor(0.5 + 100 * random_std()); } } else { for(i=N>>(n_levels-level+1);i<N>>(n_levels-level);i++){ a[i]=floor(0.5 + 100 * random_std()); } } for(i=0;i<N;i++){ p1 += a[i]*a[i]; } for(i=0;i<n_levels;i++){ interleave(a,N>>(n_levels-1-i)); synth(a,N>>(n_levels-1-i),filter); } for(i=0;i<256;i++){ p2 += a[i]*a[i]; } gain += p2/p1; } //printf("%d %g %g\n", level, gain/10000, sqrt(gain/10000)); return sqrt(gain/10000); }
void generate_noise (Vector<int8_t> & noise, float sigma) { const float quantization_correction = 1 / 6.0f; sigma = sqrtf(sqr(sigma) + quantization_correction); for (size_t i = 0, I = noise.size; i < I; ++i) { noise[i] = roundi(sigma * random_std()); } }
void MapOptimizer::add_noise (float tol) { const size_t XY = dom.size * cod.size; float * restrict J_ = & m_joint.coeffRef(0,0); for (size_t xy = 0; xy < XY; ++xy) { J_[xy] *= expf(random_std()); } constrain_joint(tol); update_conditional(); }
void generate_noise (SchroFrame *frame, int n_transforms, double *weights) { int i; int j; int k; int l; int pos; int w, h, x_offset, y_offset, y_skip; int16_t *data; SchroFrameData *comp; for(k=0;k<3;k++){ comp = frame->components + k; for(l=0;l<1+3*n_transforms;l++){ pos = schro_subband_get_position (l); w = comp->width >> (n_transforms - SCHRO_SUBBAND_SHIFT(pos)); h = comp->height >> (n_transforms - SCHRO_SUBBAND_SHIFT(pos)); y_skip = 1<<(n_transforms - SCHRO_SUBBAND_SHIFT(pos)); if (pos&1) { x_offset = w; } else { x_offset = 0; } if (pos&2) { y_offset = y_skip / 2; } else { y_offset = 0; } //printf("%d %d w %d h %d x_offset %d y_offset %d y_skip %d\n", l, pos, w, h, x_offset, y_offset, y_skip); for(j=0;j<h;j++){ data = OFFSET(comp->data, (j*y_skip + y_offset)*comp->stride); data += x_offset; for(i=0;i<w;i++){ data[i] = rint(random_std()*AMPLITUDE*weights[l]); //data[i] = rint(random_std()*AMPLITUDE); } } } } }
void Harmony::sample (Vector<complex> & sound_accum) { const size_t F = m_points.size(); compute_prior(); for (size_t i = 0; i < F; ++i) { m_dmass[i] = m_attack * m_analysis[i] + (1.0f - m_sustain) * (m_prior[i] - m_mass[i]) + m_mass[i] * (expf(m_randomize_rate * random_std()) - 1); m_dmass[i] = max(m_dmass[i], TOL - m_mass[i]); } centralize_pitch(); m_synth.sample_accum(m_mass, m_dmass, sound_accum); m_mass += m_dmass; }
void NoisyKuramotoSynth::sample (Vector<complex> & sound_accum) { m_particles.pf_to_fp(); const size_t I = m_particles.num_particles; const size_t T = sound_accum.size; const float * restrict damplitude = m_particles.field(2); const float * restrict amplitude1 = m_particles.field(3); const float * restrict frequency = m_particles.field(4); const float * restrict bandwidth = m_particles.field(5); float * restrict phase_real = m_particles.field(0); float * restrict phase_imag = m_particles.field(1); complex * restrict sound = sound_accum; // initialize force float sum_m = 0; float sum_mx = 0; float sum_my = 0; for (size_t i = 0; i < I; ++i) { float b = bandwidth[i]; float s = max(0.0f, 1 - b); float a = amplitude1[i] + max(0.0f, -damplitude[i]); float m = a * s; sum_m += m; sum_mx += m * phase_real[i]; sum_my += m * phase_imag[i]; } float force_scale = 1 / max(1e-8f, sum_m); for (size_t t = 0; t < T; ++t) { float dt = static_cast<float>(t) / T - 1; const float noise = m_noise_scale * random_std(); const float force_x = force_scale * sum_mx; const float force_y = force_scale * sum_my; sum_mx = 0; sum_my = 0; float sum_ax = 0; float sum_ay = 0; for (size_t i = 0; i < I; ++i) { float x = phase_real[i]; float y = phase_imag[i]; float b = bandwidth[i]; float s = max(0.0f, 1 - b); // update state { float f = frequency[i]; float force = force_y * x - force_x * y; float bent = f * (1 + s * force + b * noise); float dx = -bent * y; float dy = bent * x; x += dx; y += dy; } // normalize { float r = sqrt(sqr(x) + sqr(y)); // here norm(x,y) >= 1 phase_real[i] = x /= r; phase_imag[i] = y /= r; } // update force { float a = amplitude1[i] + damplitude[i] * dt; sum_ax += x; sum_ay += y; float m = a * s; sum_mx += m * x; sum_my += m * y; } } sound[t] += complex(sum_ax, sum_ay); } m_particles.fp_to_pf(); }
for(j=0;j<n_cycles;j++){ for(i=0;i<N;i++){ a[i] = 0; } if (level == 0) { for(i=0;i<(N>>4);i++){ a[i]=floor(0.5 + amplitude*random_std()); } } else if (level<5) { for(i=((N>>5)<<level);i<((N>>4)<<level);i++){ a[i]=floor(0.5 + amplitude*random_std()); } } else if (level==5) { for(i=0;i<(N>>4);i++){ a[i]=floor(0.5 + amplitude*random_std()/3.608); } for(i=(N>>4);i<(N>>3);i++){ a[i]=floor(0.5 + amplitude*random_std()/1.972); } for(i=(N>>3);i<(N>>2);i++){ a[i]=floor(0.5 + amplitude*random_std()/1.382); } for(i=(N>>2);i<(N>>1);i++){ a[i]=floor(0.5 + amplitude*random_std()/0.991); } for(i=(N>>1);i<(N>>0);i++){ a[i]=floor(0.5 + amplitude*random_std()/0.821); } } else if (level==6) { double alpha = 1.282;