📄 xoverlays.c
字号:
/* * This material contains unpublished, proprietary software of * Entropic Research Laboratory, Inc. Any reproduction, distribution, * or publication of this work must be authorized in writing by Entropic * Research Laboratory, Inc., and must bear the notice: * * "Copyright (c) 1987-1990 AT&T, Inc. * "Copyright (c) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-1996 Entropic Research Laboratory, Inc. * All rights reserved" * * The copyright notice above does not evidence any actual or intended * publication of this source code. * * Written by: David Talkin * Checked by: * Revised by: * * Brief description: * */static char *sccs_id = "@(#)xoverlays.c 1.19 9/28/98 ATT/ESI/ERL";#include <stdio.h>#include <esps/esps.h>#include <Objects.h>#include <fcntl.h>#include <spectrogram.h>#include <tracks.h>#include <xview/scrollbar.h>#include <xview/font.h>#include <Xp_pw.h>#define ALMOST 0.95#define P_F_Y_LOC (17 + v->readout_height)#define P_F_X_LOC 0extern char overlayname[]; /* in globals.c */extern char objectname[];static void dotospect(), set_spect_scale();void cmap_spect();static o_yoff = 5, o_xoff = -4; /* x and y offsets required to center "*" */static o_off = -2, o_siz = 5; /* x & y offset to center box; side of box */extern int options;extern int scrollbar_height, readout_bar_height;extern Xv_Font def_font;extern int def_font_height, def_font_width;extern void set_pvd();extern double assign_value(), signal_get_value(), get_displayed_value();extern int debug_level;char *expand_name();#define BW_OVERLAYS 1View *setup_general_overlay();View *setup_formant_overlay(), *setup_pole_overlay(), *create_dummy_sf();/*************************************************************************//* How can spectrogram overlays be supported in a reasonably principled way? Several signals need to be overlaid on spectrograms. It would be highly desirable if all elements of all overlaid signals could be plotted in unique colors AND using xor so that rapid changes could be made without redrawing the whole image. Some of the plotted signals will be immutable, while others will be modified interactively. If modifications are performed, the modified signal must be renamed and written out to disc at some point. Overlays could have roughly the same status as reticles except that they are based on signals and can be modified. The signals used must be linked to the "host" signal so that when the host must be redisplayed, all overlays are also replotted. This linkage can be through the views. The host's view list will contain views which refer to signals other than those at the head of the list. These data for the overlays may have null view lists, or may also be displayed in other views. The procedure: Generate the host view as usual. Get the name(s) of the file(s) to be overlaid. Get these signals linked into the Object list. Create the views describing how to plot the overlay. Link these views into the host's view list. Call redoit(). NON-SPECTROGAM OVERLAYS *//*********************************************************************/double o_x_to_time(s,v,x) register View *v; register Signal *s; register int x;{ register int i; register double time, t; x -= *(v->x_offset); if(x < 0) x = 0; time = v->start_time + (double)x * *(v->x_scale) / PIX_PER_CM; if (time > (t = ET(v))) time = t; i = 0.5 + ((time - s->start_time) * s->freq); return(s->start_time + ((double)i)/s->freq);}/*********************************************************************/#define DIST(d) \ ((!(d)) ? -1 : \ iabs(y - (vh->y_offset[k] - (int)((d)[ind]*PIX_PER_CM/vh->y_scale[k]))))overlay_xy_to_chan(v,x,y) register View *v; int x, y;{ register Signal *s; if(v && (s = v->sig)) { if(v->dims == 1) return(v->elements[0]); /* special-case for speed */ else { int i, mini, mind, j, ind, k, isspect; View *vh = v; double time; if(v->extra && (v->extra_type == VIEW_OVERLAY)) vh = (View*) v->extra; isspect = isa_spectrogram_view(vh); time = (vh->x_to_time)? vh->x_to_time(vh, x) : generic_x_to_time(vh, x); if (!s->data) { fprintf(stderr, "NULL signal data array in overlay_xy_to_chan.\n"); return 0; } ind = time_to_index(s, time); mind = 5000; /* needs to be bigger than biggest y screen in pixels */ mini = 0; for (i = 0; i < v->dims; i++) { if((k=i) >= vh->dims) k = vh->dims-1; if(isspect) /* sgram views only use first scale and offset element */ k = 0; switch(s->type & VECTOR_SIGNALS) { case P_SHORTS: j = DIST(((short**)(s->data))[v->elements[i]]); break; case P_DOUBLES: j = DIST(((double**)(s->data))[v->elements[i]]); break; case P_FLOATS: j = DIST(((float**)(s->data))[v->elements[i]]); break; case P_INTS: j = DIST(((int**)(s->data))[v->elements[i]]); break; case P_CHARS: j = DIST(((char**)(s->data))[v->elements[i]]); break; case P_MIXED: { caddr_t s_data; if(! s->types) { fprintf(stderr, "s->types null for P_MIXED in overlay_xy_to_chan\n"); return(0); } s_data = ((caddr_t *) s->data)[v->elements[i]]; switch (s->types[v->elements[i]]) { case P_SHORTS: j = DIST((short *) s_data); break; case P_DOUBLES: j = DIST((double *) s_data); break; case P_FLOATS: j = DIST((float *) s_data); break; case P_INTS: j = DIST((int *) s_data); break; case P_CHARS: j = DIST((char *) s_data); break; } } break; }#undef DIST(d) if (j < 0) { fprintf(stderr, "NULL signal data in overlay_xy_to_chan.\n"); return 0; } else if (j < mind) { mind = j; mini = i; } } return(v->elements[mini]); } } if(debug_level) fprintf(stderr,"Bad args to overlay_xy_to_chan %x\n", v); return(0);} /****************************************************************************/overlay_general(v) View *v;{ return(plot_waves(v));}/****************************************************************************/overlay_spectrograms(v) View *v;{ View *vh; int x, y, i, j, dim; double time, tinc, freq; caddr_t data; Pixwin *pw; Signal *s; struct rect *rect; int color; char plotstr[2]; if(v && (vh = (View*)v->extra) && (s = v->sig)) { if (((s->type & SPECIAL_SIGNALS) == SIG_GENERAL) && s->data && (s->buff_size > 0)) { pw = canvas_pixwin(v->canvas); rect = (struct rect *) xv_get(v->canvas, WIN_RECT); strcpy(plotstr, "*"); tinc = 1.0/s->freq; for (i = 0; i < s->buff_size; i++) { if (((time = (tinc*i) + BUF_START_TIME(s)) >= vh->start_time) && (time <= ET(vh))) { x = o_time_to_x(vh, time); for(j = 0; j < v->dims ; j++) { freq = get_displayed_value(s, v, j, i); y = vh->yval_to_y(vh, freq); if(vh->overlay_as_number) { plotstr[0] = '1' + j; pw_ttext(pw, x + o_xoff, y + o_yoff, PIX_SRC|PIX_COLOR(FOREGROUND_COLOR), def_font, plotstr); } else { color = YA1_COLOR + v->elements[j] + 1; pw_write(pw, x + o_off, y + o_off, o_siz, o_siz, PIX_SRC|PIX_COLOR(color), NULL, 0, 0); } } } } return TRUE; } else show_notice(1,"Apparently bogus SIG_GENERAL in overlay_spectrograms"); } else show_notice(1,"Bad argument(s) to overlay_spectrograms"); return FALSE;}/****************************************************************************/dummy_cursor(v) View *v;{ return(TRUE);}/****************************************************************************/general_overlay_print(v) View *v;{ static int char_width = -1; int i, j, k, xloc; caddr_t data; View *vh = (View *) v->extra; double time, value, tm; char tmp[200]; Frame frm; Pixwin *pw; Signal *s = v->sig; List *li; time = vh->cursor_time; if (time < vh->start_time) time = vh->start_time; if (time > (tm = ET(vh))) time = tm; i = time_to_index(s, time); if(v->xy_to_chan) k = v->cursor_channel; else k = overlay_xy_to_chan(v, vh->time_to_x(vh,time), vh->yval_to_y(vh, vh->cursor_yval)); value = signal_get_value(s, k, i); if(char_width <= 0) char_width = (int) xv_get(def_font, FONT_DEFAULT_CHAR_WIDTH); if(v->overlay_n <= 0) { /* For the first overlay... */ for (j = 0, li = s->idents; j < k && li; j++, li = li->next) { } sprintf(tmp, "%10s:%8.2f ", li ? li->str : "", value); xloc = P_F_X_LOC; } else { xloc = P_F_X_LOC + (char_width * ((v->overlay_n * 11) + 15)); sprintf(tmp,"%8.2f ",value); } pw = (Pixwin *) canvas_paint_window(v->canvas); pw_text(pw, xloc, P_F_Y_LOC, PIX_SRC|PIX_COLOR(YA1_COLOR+v->overlay_n+1), def_font, tmp);} /****************************************************************************/overlay_formants(v) View *v;{ View *vh; int x, y, i, j, fe, chan; double time, tinc; Pixwin *pw; Signal *s; struct rect *rect; if (v && (vh = (View*)v->extra) && (s = v->sig)) { if (((s->type & VECTOR_SIGNALS) == P_DOUBLES || (s->type & SPECIAL_SIGNALS) == SIG_FORMANTS) && (s->buff_size > 0)) { pw = canvas_pixwin(v->canvas); rect = (struct rect*)xv_get(v->canvas, WIN_RECT); fe = v->dims; /* s->dim/2; number of formants */ if(s->dim && !fe) fe = 1; /* in case single formant and no bw. */ if(vh->overlay_as_number) { /* B&W for screen dump hardcopy */ char fnum[2]; fnum[1] = 0; for (tinc = 1.0/s->freq, i=0; i < s->buff_size; i++) { if (((time = (tinc*i)+BUF_START_TIME(s)) >= vh->start_time) && (time <= ET(vh))) { for (j=0, x=o_time_to_x(vh,time) + o_xoff; j < fe; j++) { vh->cursor_channel = chan = v->elements[j]; y = vh->yval_to_y(vh, signal_get_value(s,j,i)) + o_yoff; *fnum = '1' + chan; pw_text(pw, x, y, PIX_SRC|PIX_COLOR(FOREGROUND_COLOR), def_font, fnum); } } } } else { /* regular color plots */ for(tinc = 1.0/s->freq, i=0; i < s->buff_size; i++) { if (((time = (tinc*i)+BUF_START_TIME(s)) >= vh->start_time) && (time <= ET(vh))) { x = o_time_to_x(vh, time); for (j = 0; j < fe; j++) { vh->cursor_channel = chan = v->elements[j]; y = vh->yval_to_y(vh, signal_get_value(s,j,i)); pw_write(pw, x + o_off, y + o_off, o_siz, o_siz, PIX_SRC|PIX_COLOR(YA1_COLOR + chan + 1), NULL, 0, 0); } } } } return(TRUE); } else show_notice(1,"Apparently bogus signal in overlay_formants"); } else show_notice(1,"Bad argument(s) to overlay_formants"); return(FALSE);}/****************************************************************************/formant_cursor(v) View *v;{ return(TRUE);}/****************************************************************************/formant_print(v) View *v;{ int i,j,k,fe; register View *vh = (View*)v->extra; double time, freq, amin, tm, val, tv; char tmp[100]; /* Frame frm; */ Pixwin *pw; time = vh->cursor_time; if (time < vh->start_time) time = vh->start_time; if (time > (tm = ET(vh))) time = tm; freq = vh->cursor_yval; if (freq < vh->start_yval) freq = vh->start_yval; if (freq > vh->end_yval) freq = vh->end_yval; i = time_to_index(v->sig, time); fe = v->sig->dim/2; for(amin=1.0e8,j=0,k=0; j < fe; j++) { if((tm = fabs((tv = signal_get_value(v->sig,j,i)) - freq)) < amin) { val = tv; amin = tm; k = j; } } sprintf(tmp, "F:%5.0f B:%5.0f", val, signal_get_value(v->sig,k+fe,i)); /* pw = (Pixwin*)xv_get(v->canvas, WIN_PIXWIN); */ pw = canvas_pixwin(v->canvas); pw_text(pw, 200, P_F_Y_LOC, PIX_SRC|PIX_COLOR(YA1_COLOR+k+1), def_font, tmp);} /****************************************************************************/overlay_poles(v) View *v;{ View *vh;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -