示例#1
0
void HandleSpecKeydownEvent(long message, short /*modifiers*/)
{
    int nze=0;

	switch( message & charCodeMask )
	{
	case 0x1E:	nze++;	break;	//up
	case 0x1F:	nze--;	break;	//down

	case 0x1C:	//left
		soundspec_update_interval =
			(int32)(soundspec_update_interval*1.1);
		break;

	case 0x1D:	//right
		soundspec_update_interval =
			(int32)(soundspec_update_interval/1.1);
		if(soundspec_update_interval < 0.01 * play_mode->rate)
			soundspec_update_interval =
			(int32)(0.01 * play_mode->rate);
		break;
	}
	
	if(nze)
		initialize_exp_hz_table(soundspec_zoom - 4 * nze);
}
示例#2
0
/*ARGSUSED*/
static int ctl_open(int using_stdin, int using_stdout) {
  ctl.opened=1;
  initialize_exp_hz_table();

  /* The child process won't come back from this call  */
  xskin_pipe_open();

  return 0;
}
示例#3
0
static void draw_scope(double *values)
{
    static int32 call_cnt;
    int offset, expose,i;
    RGBColor pixels[SCOPE_HEIGHT];
    double work[SCOPE_HEIGHT];
    int nze;
	Rect righthalf={0,SCOPE_WIDTH - SCROLL_THRESHOLD,
				SCOPE_HEIGHT, SCOPE_WIDTH },
		lefthalf={0,0,
				SCOPE_HEIGHT, SCOPE_WIDTH - SCROLL_THRESHOLD-1 };

	nze = 0;
    make_logspectrogram(values, work);
    if( win.show ){
		set_draw_pixel(work, pixels);

		expose = 0;

		SetPortWindowPort(win.ref);
		offset = call_cnt % SCROLL_THRESHOLD;
		if(offset == 0)
		{						//scroll the window
			EraseRect(&lefthalf);
			ScrollRect(&win.ref->portRect,
					-(SCOPE_WIDTH - SCROLL_THRESHOLD), 0, 0);
			EraseRect(&righthalf);
		}
			//draw
		for( i=0; i<SCOPE_HEIGHT; i++ ){
			RGBForeColor(&pixels[i]);
			MoveTo(SCOPE_WIDTH - SCROLL_THRESHOLD + offset,i);
			Line(0,0);
		}
	}
	if( skin_need_speana ){
		skin_draw_spectrum(work);
	    //ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "." );
	}
    if(nze)
	initialize_exp_hz_table(soundspec_zoom - 4 * nze);
    call_cnt++;
}
示例#4
0
void open_soundspec(void)
{
    static int initflag = 0;

	if( win.show){
		ShowWindow(win.ref);
	}

    if(disp != NULL)
    {		//already opened
	ring_index = 0;
	next_wakeup_samples = outcnt;
	memset(ring_buffer, 0, ring_buffer_len * sizeof(int32));
	view_soundspec_flag = 1;
	return;
    }

    if(soundspec_update_interval == 0)
	soundspec_update_interval = (int32)(DEFAULT_UPDATE * play_mode->rate);

	disp=true;
	
    if(!initflag)
    {
	ring_buffer = (long*)safe_malloc(ring_buffer_len * sizeof(int32));
	realfft(NULL, FFTSIZE);
	initialize_exp_hz_table(DEFAULT_ZOOM);
	initflag = 1;
    }

    set_color_ring();

    ring_index = 0;
    next_wakeup_samples = outcnt;
    memset(ring_buffer, 0, sizeof(int32));
    view_soundspec_flag = 1;
}
示例#5
0
/* Re-initialize something */
void soundspec_reinit(void)
{
    initialize_exp_hz_table(soundspec_zoom);
}
示例#6
0
void soundspec_update_wave(int32 *buff, int samples)
{
    int i;

    if(buff == NULL) /* Initialize */
    {
	ring_index = 0;
	if(samples == 0)
	{
	    outcnt = 0;
	    next_wakeup_samples = 0;
	}
	if(ring_buffer != NULL)
	    memset(ring_buffer, 0, sizeof(int32));
	return;
    }

    if(!view_soundspec_flag && !ctl_speana_flag)
    {
	outcnt += samples;
	return;
    }

    if(ring_buffer == NULL)
    {
	ring_buffer = safe_malloc(ring_buffer_len * sizeof(int32));
	memset(ring_buffer, 0, sizeof(int32));
	if(soundspec_update_interval == 0)
	    soundspec_update_interval =
		(int32)(DEFAULT_UPDATE * play_mode->rate);
	realfft(NULL, FFTSIZE);
	initialize_exp_hz_table(soundspec_zoom);
    }

    if(ring_index + samples > ring_buffer_len)
    {
	int d;

	d = ring_buffer_len - ring_index;
	if(play_mode->encoding & PE_MONO)
	    memcpy(ring_buffer + ring_index, buff, d * 4);
	else
	{
	    int32 *p;
	    int n;

	    p = ring_buffer + ring_index;
	    n = d * 2;
	    for(i = 0; i < n; i += 2)
		*p++ = (buff[i] + buff[i + 1]) / 2;
	}
	ring_index = 0;
	outcnt += d;
	samples -= d;
    }

    if(play_mode->encoding & PE_MONO)
	memcpy(ring_buffer + ring_index, buff, samples * 4);
    else
    {
	int32 *p;
	int n;

	p = ring_buffer + ring_index;
	n = samples * 2;
	for(i = 0; i < n; i += 2)
	    *p++ = (buff[i] + buff[i + 1]) / 2;
    }

    ring_index += samples;
    outcnt += samples;
    if(ring_index == ring_buffer_len)
	ring_index = 0;

    if(next_wakeup_samples < outcnt - (ring_buffer_len - FFTSIZE))
    {
	/* next_wakeup_samples is too small */
	next_wakeup_samples = outcnt - (ring_buffer_len - FFTSIZE);
    }

    while(next_wakeup_samples < outcnt - FFTSIZE)
    {
	double x[FFTSIZE];
	struct drawing_queue *q;

	ringsamples(x, next_wakeup_samples % ring_buffer_len, FFTSIZE);
	q = new_queue();
	decibelspec(x, q->values);
	push_midi_time_vp(midi_trace.offset + next_wakeup_samples,
			  trace_draw_scope,
			  q);
	next_wakeup_samples += soundspec_update_interval;
    }
}
示例#7
0
static void draw_scope(double *values)
{
    static int32 call_cnt;
    int offset, expose;
    XEvent e;
    char pixels[SCOPE_HEIGHT*32];
    double work[SCOPE_HEIGHT];
    int nze;
    char *mname;
    KeySym k;

    make_logspectrogram(values, work);
    set_draw_pixel(work, pixels);

    expose = 0;
    nze = 0;
    while(QLength(disp) || XPending(disp))
    {
	XNextEvent(disp, &e);
	switch(e.type)
	{
	  case Expose:
	    expose++;
	    break;
	  case KeyPress:
	    k = xlookup_key(&e.xkey);
	    switch(k)
	    {
#ifdef XK_Down
	      case XK_Up:
#endif /* XK_Up */
#ifdef XK_KP_Up
	      case XK_KP_Up:
#endif /* XK_KP_Up */
		nze++;
		break;

#ifdef XK_Down
	      case XK_Down:
#endif /* XK_Down */
#ifdef XK_KP_Down
	      case XK_KP_Down:
#endif /* XK_KP_Down */
		nze--;
		break;

#ifdef XK_Left
	      case XK_Left:
#endif /* XK_Left */
#ifdef XK_KP_Left
	      case XK_KP_Left:
#endif /* XK_KP_Left */
		soundspec_update_interval =
		    (int32)(soundspec_update_interval*1.1);
		break;

#ifdef XK_Right
	      case XK_Right:
#endif /* XK_Right */
#ifdef XK_KP_Right
	      case XK_KP_Right:
#endif /* XK_KP_Right */
		soundspec_update_interval =
		    (int32)(soundspec_update_interval/1.1);
		if(soundspec_update_interval < 0.01 * play_mode->rate)
		    soundspec_update_interval =
			(int32)(0.01 * play_mode->rate);
		break;
	    }
	    break;

	  case ClientMessage:
	    if(wm_delete_window == e.xclient.data.l[0])
	    {
		mname = XGetAtomName(disp, e.xclient.message_type);
		if(mname != NULL && strcmp(mname, "WM_PROTOCOLS") == 0)
		{
		    /* Delete message from WM */
		    ctl->cmsg(CMSG_INFO, VERB_VERBOSE,
			      "Sound Spectrogram Window is closed");
		    close_soundspec();
		    XCloseDisplay(disp);
		    disp = NULL;
		    return;
		}
	    }
	    break;
	}
    }

    offset = call_cnt % SCROLL_THRESHOLD;
    if(offset == 0)
    {
	XCopyArea(disp, offscr, offscr, gc,
		  SCROLL_THRESHOLD, 0,
		  SCOPE_WIDTH - SCROLL_THRESHOLD,
		  SCOPE_HEIGHT,
		  0, 0);
	XSetForeground(disp, gc, BlackPixel(disp, DefaultScreen(disp)));
	XFillRectangle(disp, offscr, gc,
		       SCOPE_WIDTH - SCROLL_THRESHOLD, 0,
		       SCROLL_THRESHOLD, SCOPE_HEIGHT);
	XCopyArea(disp, offscr, win, gc,
		  0, 0, SCOPE_WIDTH, SCOPE_HEIGHT, 0, 0);
    }

    img->data = (char *)pixels;
    XPutImage(disp, offscr, gc, img, 0, 0,
	      SCOPE_WIDTH - SCROLL_THRESHOLD + offset, 0,
	      1, SCOPE_HEIGHT);
    if(!expose)
	XCopyArea(disp, offscr, win, gc,
		  SCOPE_WIDTH - SCROLL_THRESHOLD + offset, 0,
		  1, SCOPE_HEIGHT, SCOPE_WIDTH - SCROLL_THRESHOLD + offset, 0);
    else
    {
	XCopyArea(disp, offscr, win, gc,
		  0, 0, SCOPE_WIDTH, SCOPE_HEIGHT, 0, 0);
    }

    XSync(disp, False);
    if(nze)
	initialize_exp_hz_table(soundspec_zoom - 4 * nze);
    call_cnt++;
}