📄 waves_mode_funcs.c
字号:
#include "fft-spectra.h"#define MARGIN 20#define WAVENUMS_IN_VIEWPORT 5static GdkPoint *points=NULL; /* Points for drawing the curve */static GdkGC *gc_bg=NULL, *gc_points=NULL, *gc_text=NULL; static int *sound_data=NULL;static float wavenums_in_viewport=WAVENUMS_IN_VIEWPORT; /* Display this many waves in the window */static float wavelength=0; /* Number of samples per 1 wave */extern PangoLayout *pango_layout; /* Pango for rendering text */static int ymin=INT_MAX,ymax=-INT_MAX; void waves_read_profile(int *width, int *height){ gc_bg = get_gc( sconf_get_string_or_die(settings,"waves_bg_color") ); gc_points = get_gc( sconf_get_string_or_die(settings,"waves_points_color") ); gc_text = get_gc( sconf_get_string_or_die(settings,"waves_text_color") ); if ( !sconf_get_int(settings,"waves_width",width) ) exit_nicely("Could not read config value of \"%s/waves_width\".\n", settings?settings:"default"); if ( !sconf_get_int(settings,"waves_height",height) ) exit_nicely("Could not read config value of \"%s/waves_height\".\n", settings?settings:"default");}void waves_gtk_configure(void){ if (points) FREE(points); MALLOC(points,GdkPoint,main_width); if (!sound_data) MALLOC(sound_data,int,ndata_in);}void waves_main_draw(GdkPixmap *pixmap, int width,int height){ static int min,max,ifreq, pos_max; int ipixel,idata,nsamples_needed,idx, tw,th; int line_length,len,x,y; float yscale,xscale,ith_sample; char buf[BUFLEN]; /* Clean the area */ gdk_draw_rectangle(pixmap,gc_bg, TRUE, 0,0,width,height); /* Get the audio data */ if ( !(refresh_status&REFRESH_FFT_STOP) ) ifreq = get_data_sample_fft_max(ndata_in,sound_data,&min,&max,&pos_max); if (min<ymin) ymin=min; if (max>ymax) ymax=max; if ( intensity_scale_mode==INTENSITY_SCALE_CONSTANT ) { min = ymin; max = ymax; } /* Plot the data */ yscale = 1.0*height/(max-min); /* Number of samples needed for the requested number of waves with the given frequency. */ wavelength = esd_rate/idata_to_freq(ifreq); /* number of samples per 1 wave */ nsamples_needed = wavenums_in_viewport*wavelength; xscale = 1.0*width/(wavenums_in_viewport*wavelength); /* sample to pixel conversion */ if ( nsamples_needed<width) {#if 1 /* Shift the pos_max by modulo viewport to the left so that nsamples_needed+pos_max<ndata_in */ while ( nsamples_needed+pos_max>=ndata_in ) pos_max -= nsamples_needed; for (idata=0; idata<nsamples_needed; idata++) { ipixel = xscale*idata; if ( ipixel<0 ) break; if ( ipixel>=width ) break; idx = pos_max + idata; points[idata].x = ipixel; points[idata].y = (sound_data[idx]-min)*yscale; } gdk_draw_lines(pixmap,gc_points,points,idata);#else //TODO: draw more lines at once - will the results be still so shaky?? for (idata=0; idata<ndata_in; idata++) { idx = idata; }#endif } else { /* For a lower frequencies every i-th sample will be read and the high-frequency samples in between will be ignored. */ ith_sample = 1.0*nsamples_needed/width; for (ipixel=0; ipixel<width; ipixel++) { points[ipixel].x = ipixel; idx = ipixel*ith_sample; if (idx>=ndata_in) break; points[ipixel].y = (sound_data[idx]-min)*yscale; } gdk_draw_lines(pixmap,gc_points,points,ipixel); } /* Print frequency of the displayed wave */ x = MARGIN; y = MARGIN; len = snprintf(buf,BUFLEN,"%.0f Hz", idata_to_freq(ifreq)); pango_layout_set_text(pango_layout,buf,len); pango_layout_get_pixel_size(pango_layout, &tw,&th); gdk_draw_layout(pixmap, gc_text, x,y, pango_layout); /* Draw scale line with the length of one wavelength */ len = snprintf(buf,BUFLEN,"%.3f ms", 1e3/idata_to_freq(ifreq)); pango_layout_set_text(pango_layout,buf,len); pango_layout_get_pixel_size(pango_layout, &tw,&th); line_length = wavelength*xscale; x = width-(MARGIN+(line_length+tw)*0.5); y = height-MARGIN-th-2; if ( x>(width-MARGIN-tw) ) x=width-MARGIN-tw; gdk_draw_layout(pixmap, gc_text, x,y, pango_layout); x = (line_length<tw) ? width-MARGIN-(tw+line_length)*0.5 : width-MARGIN-line_length; y += th+2; gdk_draw_line(pixmap,gc_text,x,y,x+line_length,y); gdk_draw_line(pixmap,gc_text,x,y-2,x,y+2); gdk_draw_line(pixmap,gc_text,x+line_length,y-2,x+line_length,y+2);}void waves_init_intensity(void){ ymin = INT_MAX; ymax = -INT_MAX;}void waves_zoom_out(void){ wavenums_in_viewport /= 0.6; if ( wavenums_in_viewport*wavelength>ndata_in ) wavenums_in_viewport=ndata_in/wavelength;}void waves_zoom_in(void){ wavenums_in_viewport *= 0.6; if ( wavenums_in_viewport<1.2 ) wavenums_in_viewport=1.2;}void waves_zoom_restore(void){ wavenums_in_viewport = WAVENUMS_IN_VIEWPORT;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -