Exemple #1
0
int pvck(struct cmd_context *cmd, int argc, char **argv)
{
	int i;

	/* FIXME: validate cmdline options */
	/* FIXME: what does the cmdline look like? */
	/*
	 * Use what's on the cmdline directly, and avoid calling into
	 * some of the other infrastructure functions, so as to avoid
	 * hitting some of the lvmcache behavior, scanning other devices,
	 * etc.
	 */
	for (i = 0; i < argc; i++) {
		/* FIXME: warning and/or check if in use? */
		log_verbose("Scanning %s", argv[i]);

		pv_analyze(cmd, argv[i],
			   arg_uint64_value(cmd, labelsector_ARG,
					   UINT64_C(0)));
	}

	return ECMD_PROCESSED;
}
Exemple #2
0
//-----------------------------------------------------------------------------
// Name: displayFunc( )
// Desc: callback function invoked to draw the client area
//-----------------------------------------------------------------------------
void displayFunc( )
{
    static const int LP = 4;
    static long int count = 0;
    static char str[1024];
    static unsigned int wf = 0;
    static SAMPLE buffer[PVC_BUFFER_SIZE];
    static SAMPLE buffer2[PVC_BUFFER_SIZE];
    static polar_window * win[2] = { NULL, NULL };
    static int which = 0;
    static float _inc = 0.0f;

    int i;
    float pitch, power, fval;

    if( g_freeze ) return;

    // clear the color and depth buffers
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix( );

    // rotate the sphere about y axis
    glRotatef( g_angle_y += g_inc, 0.0f, 1.0f, 0.0f );

    // color waveform
    glColor3f( 0.4f, 0.4f, 1.0f );

    // wait for data
    while( !g_ready )
#if !defined(__OS_WINDOWS__)
        usleep( 0 );
#else
        Sleep( 0 );
#endif

    // g_mutex.lock();
    // get the window
    memcpy( buffer, g_audio_buffer, g_buffer_size * sizeof(SAMPLE) );
    memset( g_another_buffer, 0, g_buffer_size * sizeof(SAMPLE) );
    // g_mutex.unlock();

    g_ready = FALSE;

    // analyze buffer
    pv_analyze( g_pvc, buffer, g_hop_size );

    // get phase windows out of queue
    while( win[which] = pv_deque( g_pvc ) )
    {
        // unwrap phase
        pv_unwrap_phase( win[which] );
        // fix phase using last window and expected hop_size
        if( g_phase_fix && win[!which] )
            pv_phase_fix( win[!which], win[which], g_factor );
        // freq shift
        pv_freq_shift( g_pvc, win[which], g_factor2 );
        // ifft
        pv_unwrap_phase( win[which] );
        // overlap/add
        pv_overlap_add( g_pvc, win[which], (int)(g_hop_size * g_factor + .5f) );
        which = !which;
        // reclaim the window
        pv_reclaim( g_pvc, win[which] );
    }

    // get buffer
    pv_synthesize( g_pvc, g_another_buffer );

    // apply the window
    GLfloat x = -1.8f, inc = 3.6f / g_buffer_size, y = 1.0f;
    //apply_window( (float*)buffer, g_window, g_buffer_size );

    // draw the time domain waveform
    glBegin( GL_LINE_STRIP );
    GLint ii = ( g_buffer_size - (g_buffer_size/g_time_view) ) / 2;
    for( i = ii; i < ii + g_buffer_size / g_time_view; i++ )
    {
        glVertex3f( x, g_gain * g_time_scale * .75f * g_another_buffer[i] + y, 0.0f );
        x += inc * g_time_view;
    }
    glEnd();

    // apply the window
    x = -1.8f, inc = 3.6f / g_buffer_size, y = .5f;

    // fft
    memcpy( buffer, g_another_buffer, g_buffer_size * sizeof(SAMPLE) );
    rfft( (float *)buffer, g_buffer_size/2, FFT_FORWARD );

    x = -1.8f;
    y = -1.2f;
    complex * cbuf = (complex *)buffer;

    // color the spectrum
    glColor3f( 0.4f, 1.0f, 0.4f );

    // draw the frequency domain representation
    glBegin( GL_LINE_STRIP );
    for( i = 0; i < g_buffer_size/g_freq_view; i++ )
    {
        g_spectrums[wf][i].x = x;
        if( !g_usedb )
            g_spectrums[wf][i].y = g_gain * g_freq_scale * .7f *
                                   ::pow( 25 * cmp_abs( cbuf[i] ), .5 ) + y;
        else
            g_spectrums[wf][i].y = g_gain * g_freq_scale * .8f *
                                   ( 20.0f * log10( cmp_abs(cbuf[i])/8.0 ) + 80.0f ) / 80.0f + y + .73f;
        x += inc * g_freq_view;
    }
    glEnd();

    g_draw[wf] = true;

    for( i = 0; i < g_depth; i++ )
    {
        if( g_draw[(wf+i)%g_depth] )
        {
            Pt2D * pt = g_spectrums[(wf+i)%g_depth];
            fval = (g_depth-i)/(float)g_depth;
            glColor3f( .4f * fval, 1.0f * fval, .4f * fval );
            x = -1.8f;
            glBegin( GL_LINE_STRIP );
            for( int j = 0; j < g_buffer_size/g_freq_view; j++, pt++ )
                glVertex3f( x + j*(inc*g_freq_view), pt->y, -i * g_space + g_z );
            glEnd();
        }
    }

    if( !g_wutrfall )
        g_draw[wf] = false;

    wf--;
    wf %= g_depth;

    // factor
    sprintf( str, "time-expansion factor: %.2f", g_factor );
    draw_string( .5f, 0.2f, 0.0f, str, .45f );
    sprintf( str, "frequency-expansion factor: %.2f", g_factor2 );
    draw_string( .5f, 0.1f, 0.0f, str, .45f );
    sprintf( str, "analysis window: %i", g_window_size );
    draw_string( .5f, 0.0f, 0.0f, str, .45f );
    sprintf( str, "hop size: %i", g_hop_size );
    draw_string( .5f, -0.1f, 0.0f, str, .45f );

    sprintf( str, "phase adjustment: %s", g_phase_fix ? "ON" : "OFF" );
    draw_string( .5f, -0.2f, 0.0f, str, .45f );
    glPushMatrix();
    glTranslatef( 1.25f, -0.175f, 0.0f );
    if( g_phase_fix )
        glColor3f( 1.0f, .7f, .3f );
    else
        glColor3f( .6f, .6f, 1.0f );
    glutSolidSphere( g_phase_fix ? .05f + .005f * fabs(sin(_inc)) : .01f, 10, 10 );
    glPopMatrix();

    sprintf( str, "# delay: %i buffers (%.0f ms)", pv_get_ready_len( g_pvc ),
             pv_get_ready_len( g_pvc ) * g_buffer_size / 44100.0f * 1000.0f );
    draw_string( .5f, -0.4f, 0.0f, str, .45f );

    glPopMatrix( );

    // swap the buffers
    glFlush( );
    glutSwapBuffers( );

    g_buffer_count_b++;
    _inc += .1f;
}