Minor make/configure mods and mlt_frame_waveform mod
[melted] / src / framework / mlt_frame.c
index fc67de8..7674633 100644 (file)
@@ -339,13 +339,14 @@ 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 )
 {
        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 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
@@ -369,10 +370,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;