]> git.sesse.net Git - mlt/commitdiff
properly deal with evaluation of magnitude of 2s complement for waveform generation
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 30 Aug 2004 04:49:59 +0000 (04:49 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 30 Aug 2004 04:49:59 +0000 (04:49 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@400 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_frame.c

index fc67de8f2a395f18b70cf85e3ae802e4ee3f27a5..5593c6b93996a4390765e8344b3cc94bc7788319 100644 (file)
@@ -369,10 +369,11 @@ unsigned char *mlt_frame_get_waveform( mlt_frame this, double fps, int w, int h
                // pcm data has channels interleaved
                for ( j = 0; j < channels; j++ )
                {
-                       // The height of a line is the ratio of the sample multiplied by 
+                       // 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 pcm_scaled = ( int )( ( double )( *pcm ) / 32768 * h / 2 );
-                       int height = pcm_scaled < 0 ? -pcm_scaled : pcm_scaled;
+                       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;