X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fframework%2Fmlt_frame.c;h=e3e4f3f4ae25146ecc444aca1fca25884a3346a5;hb=c3ed1af8d2f360901ec37c4f5862fd9d60a0ddcd;hp=46c2aaebc4c29d6eea3f0c425e7e12b42188acd7;hpb=a580a839a05757f17185ef78b849f3e53dbd0ccc;p=melted diff --git a/src/framework/mlt_frame.c b/src/framework/mlt_frame.c index 46c2aae..e3e4f3f 100644 --- a/src/framework/mlt_frame.c +++ b/src/framework/mlt_frame.c @@ -200,6 +200,8 @@ int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *for mlt_properties properties = mlt_frame_properties( this ); mlt_get_image get_image = mlt_frame_pop_get_image( this ); mlt_producer producer = mlt_properties_get_data( properties, "test_card_producer", NULL ); + + *width = *width >> 1 << 1; if ( get_image != NULL ) { @@ -226,6 +228,7 @@ int mlt_frame_get_image( mlt_frame this, uint8_t **buffer, mlt_image_format *for mlt_properties_set_data( properties, "image", *buffer, *width * *height * 2, NULL, NULL ); mlt_properties_set_int( properties, "width", *width ); mlt_properties_set_int( properties, "height", *height ); + mlt_properties_set_double( properties, "aspect_ratio", mlt_frame_get_aspect_ratio( test_frame ) ); mlt_properties_set( properties, "rescale.interp", "none" ); mlt_properties_set( properties, "scale", "off" ); } @@ -339,49 +342,55 @@ int mlt_frame_get_audio( mlt_frame this, int16_t **buffer, mlt_audio_format *for return 0; } -unsigned char *mlt_frame_get_waveform( mlt_frame this, double fps, int w, int h ) +unsigned char *mlt_frame_get_waveform( mlt_frame this, int w, int h ) { - /* Currently, w is not honored - the user must scale to desired height. - Get the integer property waveform_width after calling to see the - produced width (currently equal to # samples). */ int16_t *pcm = NULL; mlt_properties properties = mlt_frame_properties( this ); mlt_audio_format format = mlt_audio_pcm; - int frequency = 32000; /* lower frequency available? */ + int frequency = 32000; // lower frequency available? int channels = 2; + double fps = mlt_properties_get_double( properties, "fps" ); int samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) ); - /* get the pcm data */ + // Get the pcm data mlt_frame_get_audio( this, &pcm, &format, &frequency, &channels, &samples ); - mlt_properties_set_int( properties, "waveform_width", samples ); - /* make an 8-bit buffer large enough to hold rendering */ - int size = samples * h; + // Make an 8-bit buffer large enough to hold rendering + int size = w * h; unsigned char *bitmap = ( unsigned char* )mlt_pool_alloc( size ); if ( bitmap != NULL ) memset( bitmap, 0, size ); mlt_properties_set_data( properties, "waveform", bitmap, size, ( mlt_destructor )mlt_pool_release, NULL ); - /* render - pcm data has channels interleaved */ - int vertical_resolution = h / channels; + // Render vertical lines + int16_t *ubound = pcm + samples * channels; + int skip = samples / w - 1; int i, j, k; - for ( i = 0; i < samples; i++ ) + // Iterate sample stream and along x coordinate + for ( i = 0; i < w && pcm < ubound; i++ ) { + // pcm data has channels interleaved for ( j = 0; j < channels; j++ ) { - /* the height of a "bar" is the ratio of the sample multiplied by the vertical resolution */ - int pcm_scaled = ( int )( ( double )( *pcm ) / 32768 * vertical_resolution / 2 ); - int height = pcm_scaled < 0 ? -pcm_scaled : pcm_scaled; - int offset = j * samples * vertical_resolution; - int displacement = pcm_scaled < 0 ? ( vertical_resolution / 2 ) : ( vertical_resolution / 2 - pcm_scaled ); - unsigned char *p = &bitmap[ offset + i + displacement * samples ]; + // Determine sample's magnitude from 2s complement; + int pcm_magnitude = *pcm < 0 ? ~(*pcm) + 1 : *pcm; + // The height of a line is the ratio of the magnitude multiplied by + // half the vertical resolution + int height = ( int )( ( double )( pcm_magnitude ) / 32768 * h / 2 ); + // Determine the starting y coordinate - left channel above center, + // right channel below - currently assumes 2 channels + int displacement = ( h / 2 ) - ( 1 - j ) * height; + // Position buffer pointer using y coordinate, stride, and x coordinate + unsigned char *p = &bitmap[ i + displacement * w ]; + // Draw vertical line for ( k = 0; k < height; k++ ) - p[ samples * k ] = 0xFF; + p[ w * k ] = 0xFF; pcm++; } + pcm += skip * channels; } return bitmap;