mlt_audio_format format = mlt_audio_s16;
int frequency = 32000; // lower frequency available?
int channels = 2;
- double fps = mlt_profile_fps( NULL );
+ mlt_producer producer = mlt_frame_get_original_producer( this );
+ double fps = mlt_producer_get_fps( producer );
int samples = mlt_sample_calculator( fps, frequency, mlt_frame_get_position( this ) );
// Get the pcm data
// 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;
+ // the vertical resolution of a single channel
+ int height = h * pcm_magnitude / channels / 2 / 32768;
+ // Determine the starting y coordinate - left top, right bottom
+ int displacement = h * (j * 2 + 1) / channels / 2 - ( *pcm < 0 ? 0 : height );
// Position buffer pointer using y coordinate, stride, and x coordinate
- unsigned char *p = &bitmap[ i + displacement * w ];
+ unsigned char *p = bitmap + i + displacement * w;
// Draw vertical line
for ( k = 0; k < height; k++ )
#endif
+#if defined(SWIGPYTHON)
+%{
+typedef struct {
+ int size;
+ char* data;
+} binary_data;
+
+binary_data frame_get_waveform( Mlt::Frame &frame, int w, int h )
+{
+ binary_data result = {
+ w * h,
+ (char*) frame.get_waveform( w, h )
+ };
+ return result;
+}
+
+%}
+
+%typemap(out) binary_data {
+ $result = PyString_FromStringAndSize( $1.data, $1.size );
+}
+
+binary_data frame_get_waveform(Mlt::Frame&, int, int);
+
+#endif
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import mlt
+from PIL import Image
+
+mlt.Factory.init()
+profile = mlt.Profile()
+prod = mlt.Producer(profile, 'test.wav')
+size = (320, 240)
+for i in range(0, prod.get_length()):
+ frm = prod.get_frame()
+ wav = mlt.frame_get_waveform(frm, size[0], size[1])
+ img = Image.fromstring('L', size, wav)
+ img.save('test-%04d.pgm' % (i))