]> git.sesse.net Git - mlt/commitdiff
Improve audio waveform resault reliability.
authorDan Dennedy <dan@dennedy.org>
Thu, 19 Aug 2010 08:21:31 +0000 (01:21 -0700)
committerDan Dennedy <dan@dennedy.org>
Thu, 19 Aug 2010 08:21:31 +0000 (01:21 -0700)
This scales the audio sample rate up to meet the requested image
resolution, 16 KHz at a time.

src/framework/mlt_frame.c

index 3b644d1330babb7ea61e5ef4082c27677789c12c..546d5b478e17a0ad2e84d72b341a2cf161857d30 100644 (file)
@@ -698,6 +698,13 @@ unsigned char *mlt_frame_get_waveform( mlt_frame this, int w, int h )
        double fps = mlt_producer_get_fps( mlt_producer_cut_parent( producer ) );
        int samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) );
 
+       // Increase audio resolution proportional to requested image size
+       while ( samples < w )
+       {
+               frequency += 16000;
+               samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) );
+       }
+
        // Get the pcm data
        mlt_frame_get_audio( this, (void**)&pcm, &format, &frequency, &channels, &samples );
 
@@ -711,8 +718,7 @@ unsigned char *mlt_frame_get_waveform( mlt_frame this, int w, int h )
        // Render vertical lines
        int16_t *ubound = pcm + samples * channels;
        int skip = samples / w;
-       if ( !skip )
-               return NULL;
+       skip = !skip ? 1 : skip;
        unsigned char gray = 0xFF / skip;
        int i, j, k;