Wider::Wider(unsigned int order) : Ambisonic(order) { m_wide = NUMBEROFLINEARPOINTS - 1; m_wide_matrix = new double[NUMBEROFLINEARPOINTS * m_number_of_harmonics]; double weight_order = log((double)(m_order + 1)); for(unsigned int j = 0; j < NUMBEROFLINEARPOINTS; j++) { m_wide_matrix[j * m_number_of_harmonics] = (1. - ((double)j / (double)(NUMBEROFLINEARPOINTS-1))) * weight_order + 1.; } for(unsigned int i = 1; i < m_number_of_harmonics; i++) { double minus = clip_min(log((double)getHarmonicDegree(i)), 0.); minus = -minus; double dot = clip_min(log((double)getHarmonicDegree(i) + 1.), 0.); dot += minus; dot = 1. / dot; for(unsigned int j = 0; j < NUMBEROFLINEARPOINTS; j++) { double weight = (1. - ((double)j / (double)(NUMBEROFLINEARPOINTS-1))) * weight_order + 1.; double scale = ((double)j / (double)(NUMBEROFLINEARPOINTS-1)) * weight_order; double new_weight = (minus + scale) * dot; new_weight = clip_minmax(new_weight, 0., 1.); m_wide_matrix[j * m_number_of_harmonics + i] = new_weight * weight; } } }
void hoa_map_float(t_hoa_map *x, double f) { if(x->f_map->getNumberOfSources() == 1) { if(x->f_mode == hoa_sym_polar) { if(proxy_getinlet((t_object *)x) == 1) { x->f_lines->setRadius(0, clip_min(f, 0.)); } else if(proxy_getinlet((t_object *)x) == 2) { x->f_lines->setAzimuth(0, f); } } else if(x->f_mode == hoa_sym_cartesian) { if(proxy_getinlet((t_object *)x) == 1) { float ord = ordinate(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0)); x->f_lines->setRadius(0, radius(f, ord)); x->f_lines->setAzimuth(0, azimuth(f, ord)); } else if(proxy_getinlet((t_object *)x) == 2) { float abs = abscissa(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0)); x->f_lines->setRadius(0, radius(abs, f)); x->f_lines->setAzimuth(0, azimuth(abs, f)); } } } }
void *hoa_map_3D_tilde_new(t_symbol *s, long argc, t_atom *argv) { t_hoa_map_3D_tilde *x = NULL; t_binbuf *d; int order = 1; int numberOfSources = 1; if (!(d = binbuf_via_atoms(argc,argv))) return NULL; x = (t_hoa_map_3D_tilde *)eobj_new(hoa_map_3D_tilde_class); if (x) { if(atom_gettype(argv) == A_LONG) order = clip_min(atom_getlong(argv), 0); if(argc > 1 && atom_gettype(argv+1) == A_LONG) numberOfSources = clip_minmax(atom_getlong(argv+1), 1, 255); if(argc > 2 && atom_gettype(argv+2) == A_SYM) { if(atom_getsym(argv+2) == gensym("car") || atom_getsym(argv+2) == gensym("cartesian")) x->f_mode = 1; else x->f_mode = 0; } else x->f_mode = 0; x->f_ramp = 100; x->f_map = new Hoa3D::Map(order, numberOfSources); x->f_lines = new MapPolarLines3D(x->f_map->getNumberOfSources()); x->f_lines->setRamp(0.1 * sys_getsr()); for (int i = 0; i < x->f_map->getNumberOfSources(); i++) { x->f_lines->setRadiusDirect(i, 1); x->f_lines->setAzimuthDirect(i, 0.); x->f_lines->setElevationDirect(i, 0.); } if(x->f_map->getNumberOfSources() == 1) eobj_dspsetup(x, 4, x->f_map->getNumberOfHarmonics()); else eobj_dspsetup(x, x->f_map->getNumberOfSources(), x->f_map->getNumberOfHarmonics()); if(x->f_map->getNumberOfSources() == 1) x->f_sig_ins = new t_float[4 * SYS_MAXBLKSIZE]; else x->f_sig_ins = new t_float[x->f_map->getNumberOfSources() * SYS_MAXBLKSIZE]; x->f_sig_outs = new t_float[x->f_map->getNumberOfHarmonics() * SYS_MAXBLKSIZE]; x->f_lines_vector = new float[x->f_map->getNumberOfSources() * 3]; ebox_attrprocess_viabinbuf(x, d); } return (x); }
void *hoa_decoder_new(t_symbol *s, long argc, t_atom *argv) { // @arg 0 @name ambisonic-order @optional 0 @type int @digest The ambisonic order of decomposition // @description First argument is the ambisonic order of decomposition. // @arg 1 @name number-of-channels @optional 0 @type int @digest The number of channels // @description Second argument is the number of channels t_hoa_decoder *x = NULL; int order = 1; int number_of_channels = 4; x = (t_hoa_decoder *)object_alloc((t_class*)hoa_decoder_class); if(x) { x->f_mode = hoa_sym_ambisonic; x->f_pinna = gensym("large"); if(atom_gettype(argv) == A_LONG || atom_gettype(argv) == A_FLOAT) order = clip_min(atom_getfloat(argv), 1); if(atom_gettype(argv+1) == A_LONG || atom_gettype(argv+1) == A_FLOAT) number_of_channels = clip_min(atom_getfloat(argv+1), 1); x->f_decoder = new Hoa3D::Decoder(order, number_of_channels); x->f_number_of_angles = x->f_decoder->getNumberOfChannels() * 2; dsp_setup((t_pxobject *)x, x->f_decoder->getNumberOfHarmonics()); for (int i = 0; i < x->f_decoder->getNumberOfChannels(); i++) outlet_new(x, "signal"); x->f_ins = new double[x->f_decoder->getNumberOfHarmonics() * SYS_MAXBLKSIZE]; x->f_outs = new double[x->f_decoder->getNumberOfChannels() * SYS_MAXBLKSIZE]; for(int i = 0; i < x->f_decoder->getNumberOfChannels() * 2; i+= 2) { x->f_angles_of_channels[i] = x->f_decoder->getChannelAzimuth(i/2) / HOA_2PI * 360; x->f_angles_of_channels[i+1] = x->f_decoder->getChannelElevation(i/2) / HOA_2PI * 360; } attr_args_process(x, argc, argv); } return (x); }
Decoder::Decoder(unsigned int order, unsigned int numberOfLoudspeakers) : Ambisonic(order) { m_number_of_loudspeakers = clip_min(numberOfLoudspeakers, 4); m_loudspeakers_azimuth = new double[m_number_of_loudspeakers]; m_loudspeakers_elevation = new double[m_number_of_loudspeakers]; m_harmonics_vector = new double[m_number_of_harmonics]; m_decoder_matrix = new double[m_number_of_loudspeakers * m_number_of_harmonics]; m_decoder_matrix_float = new float[m_number_of_loudspeakers * m_number_of_harmonics]; m_encoder = new Encoder(m_order); }
t_pd_err ramp_set(t_hoa_map_3D_tilde *x, t_object *attr, long argc, t_atom *argv) { if(argc && argv) { if(atom_gettype(argv) == A_LONG || atom_gettype(argv) == A_FLOAT) { x->f_ramp = clip_min(atom_getfloat(argv), 0); x->f_lines->setRamp(x->f_ramp / 1000. * sys_getsr()); } } return 0; }
void hoa_map_3D_tilde_float(t_hoa_map_3D_tilde *x, float f) { if(x->f_map->getNumberOfSources() == 1) { if(x->f_mode == 0) { if(eobj_getproxy((t_object *)x) == 1) { x->f_lines->setRadius(0, clip_min(f, 0.)); } else if(eobj_getproxy((t_object *)x) == 2) { x->f_lines->setAzimuth(0, f); } else if(eobj_getproxy((t_object *)x) == 3) { x->f_lines->setElevation(0, f); } } else if(x->f_mode == 1) { if(eobj_getproxy((t_object *)x) == 1) { float abs = f; float ord = ordinate(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0)); float hei = height(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0)); x->f_lines->setRadius(0, radius(abs, ord, hei)); x->f_lines->setAzimuth(0, azimuth(abs, ord, hei)); x->f_lines->setElevation(0, elevation(abs, ord, hei)); } else if(eobj_getproxy((t_object *)x) == 2) { float abs = abscissa(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0)); float ord = f; float hei = height(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0)); x->f_lines->setRadius(0, radius(abs, ord, hei)); x->f_lines->setAzimuth(0, azimuth(abs, ord, hei)); x->f_lines->setElevation(0, elevation(abs, ord, hei)); } else if(eobj_getproxy((t_object *)x) == 3) { float abs = abscissa(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0)); float ord = ordinate(x->f_lines->getRadius(0), x->f_lines->getAzimuth(0), x->f_lines->getElevation(0)); float hei = f; x->f_lines->setRadius(0, radius(abs, ord, hei)); x->f_lines->setAzimuth(0, azimuth(abs, ord, hei)); x->f_lines->setElevation(0, elevation(abs, ord, hei)); } } } }
void Line::setRampInSample(const long samps) { m_ramp = clip_min(samps, (long)1); }
void HoaToolsAudioProcessor::PolarLines::setRamp(unsigned int ramp) { m_ramp = clip_min(ramp, (long)1); }
void draw_background(t_hoa_scope *x, t_object *view, t_rect *rect) { int i; double y1, y2, rotateAngle; t_jmatrix transform; t_jrgba black, white; black = white = x->f_color_bg; black.red = clip_min(black.red - contrast_black, 0.); black.green = clip_min(black.green - contrast_black, 0.); black.blue = clip_min(black.blue - contrast_black, 0.); white.red = clip_max(white.red + contrast_white, 1.); white.green = clip_max(white.green + contrast_white, 1.); white.blue = clip_max(white.blue + contrast_white, 1.); t_jgraphics *g = jbox_start_layer((t_object *)x, view, hoa_sym_background_layer, rect->width, rect->height); if (g) { jgraphics_matrix_init(&transform, 1, 0, 0, -1, x->f_center, x->f_center); jgraphics_set_matrix(g, &transform); for(i = 0; i < (x->f_order * 2 + 2) ; i++) { rotateAngle = ((double)i / (x->f_order * 2 + 2) * HOA_2PI ) - (0.5 / (x->f_order * 2 + 2) * HOA_2PI); jgraphics_rotate(g, rotateAngle); y1 = x->f_radius / 5.; y2 = x->f_radius; if(rotateAngle > HOA_PI2 && rotateAngle < HOA_PI + HOA_PI2) { jgraphics_move_to(g, -1, long(y1)); jgraphics_line_to(g, -1, long(y2)); } else { jgraphics_move_to(g, 1, long(y1)); jgraphics_line_to(g, 1, long(y2)); } jgraphics_set_line_width(g, 2); jgraphics_set_source_jrgba(g, &white); jgraphics_stroke(g); jgraphics_move_to(g, 0, y1); jgraphics_line_to(g, 0, y2); jgraphics_set_source_jrgba(g, &black); jgraphics_set_line_width(g, 1); jgraphics_stroke(g); jgraphics_rotate(g, -rotateAngle); } jgraphics_matrix_init(&transform, 1, 0, 0, 1, x->f_center, x->f_center); jgraphics_set_matrix(g, &transform); for(i = 5; i > 0; i--) { jgraphics_set_line_width(g, 2); jgraphics_set_source_jrgba(g, &white); jgraphics_arc(g, 1, 1, (double)i / 5. * x->f_radius, 0., HOA_2PI); jgraphics_stroke(g); jgraphics_set_line_width(g, 1); jgraphics_set_source_jrgba(g, &black); jgraphics_arc(g, 0, 0, (double)i / 5.* x->f_radius, 0., HOA_2PI); jgraphics_stroke(g); } jbox_end_layer((t_object*)x, view, hoa_sym_background_layer); } jbox_paint_layer((t_object *)x, view, hoa_sym_background_layer, 0., 0.); }
void MapPolarLines3D::setRamp(unsigned int ramp) { m_ramp = clip_min(ramp, (long)1); }
void *hoa_map_new(t_symbol *s, long argc, t_atom *argv) { // @arg 0 @name ambisonic-order @optional 0 @type int @digest The ambisonic order of decomposition // @description First argument is the ambisonic order of decomposition. // @arg 1 @name number-of-sources @optional 0 @type int @digest The number of sources // @description Second argument is the number of sources to spatialize. // If there is a single source, <o>hoa.2d.map~</o> object owns 3 inlets, the first one correspond to the signal to encode, the two other ones are usefull to control source position at signal rate. If you have more than one source to spatialize, the number of signal inlets will be equal to the number of sources to encode, and coordinates will be given with list messages. t_hoa_map *x = NULL; int order = 1; int numberOfSources = 1; t_symbol* temp_mode; x = (t_hoa_map *)object_alloc(hoa_map_class); if (x) { x->f_ramp = 100; x->f_mode = hoa_sym_polar; if(argc && atom_gettype(argv) == A_LONG) order = clip_min(atom_getlong(argv), 0); if(argc > 1 && atom_gettype(argv+1) == A_LONG) numberOfSources = clip_minmax(atom_getlong(argv+1), 1, MAX_CHANNELS); if(argc > 2 && atom_gettype(argv+2) == A_SYM) { temp_mode = atom_getsym(argv+2); if(temp_mode == hoa_sym_cartesian) x->f_mode = hoa_sym_cartesian; else if(temp_mode == hoa_sym_polar) x->f_mode = hoa_sym_polar; } x->f_map = new Hoa2D::Map(order, numberOfSources); x->f_lines = new PolarLines(x->f_map->getNumberOfSources()); x->f_lines->setRamp(0.1 * sys_getsr()); for (int i = 0; i < x->f_map->getNumberOfSources(); i++) { x->f_lines->setRadiusDirect(i, 1); x->f_lines->setAzimuthDirect(i, 0.); } if(x->f_map->getNumberOfSources() == 1) x->f_sig_ins = new double[3 * 8192]; else x->f_sig_ins = new double[x->f_map->getNumberOfSources() * 8192]; x->f_sig_outs = new double[x->f_map->getNumberOfHarmonics() * 8192]; if(x->f_map->getNumberOfSources() == 1) dsp_setup((t_pxobject *)x, 3); else dsp_setup((t_pxobject *)x, x->f_map->getNumberOfSources()); for (int i = 0; i < x->f_map->getNumberOfHarmonics(); i++) outlet_new(x, "signal"); } return (x); }