commit 491db7c66360362ead0d5da2a0017547e8cde350
parent 28ade26079755807921599ecb47aa9af9c8d6273
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date: Thu, 6 May 2010 17:09:52 +1000
Show the spectrogram image
Diffstat:
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/spek-source.vala b/src/spek-source.vala
@@ -73,7 +73,7 @@ namespace Spek {
source.pad = new_pad;
source.pad.link (sinkpad);
source.spectrum.set ("bands", source.bands);
- //source.spectrum.set ("threshold", -99);
+ source.spectrum.set ("threshold", -100);
source.spectrum.set ("message-magnitude", true);
source.spectrum.set ("post-messages", true);
source.spectrum.set_state (State.PAUSED);
diff --git a/src/spek-window.vala b/src/spek-window.vala
@@ -1,9 +1,11 @@
+using Gdk;
using Gtk;
namespace Spek {
public class Window : Gtk.Window {
private Source source;
+ private Gtk.Image image;
public Window () {
this.title = Config.PACKAGE_STRING;
@@ -18,8 +20,12 @@ namespace Spek {
quit.clicked.connect (s => this.destroy());
toolbar.insert (quit, -1);
+ image = new Gtk.Image ();
+ image.size_allocate.connect (on_image_size_allocate);
+
var vbox = new VBox (false, 0);
vbox.pack_start (toolbar, false, true, 0);
+ vbox.pack_start (image, true, true, 0);
this.add (vbox);
this.show_all ();
}
@@ -30,17 +36,33 @@ namespace Spek {
STOCK_CANCEL, ResponseType.CANCEL,
STOCK_OPEN, ResponseType.ACCEPT, null);
if (chooser.run () == ResponseType.ACCEPT) {
- source = new Source (chooser.get_filename (), 10, 100, source_callback);
+ var width = image.allocation.width;
+ var height = image.allocation.height;
+ image.pixbuf = new Pixbuf (Colorspace.RGB, false, 8, width, height);
+ // TODO: clear the pixbuf
+ source = new Source (chooser.get_filename (), height, width, source_callback);
}
chooser.destroy ();
}
+ private void on_image_size_allocate (Rectangle allocation) {
+ // TODO: re-create the source
+ }
+
private void source_callback (int sample, float[] values) {
- stdout.printf ("%d:", sample);
- foreach (var value in values) {
- stdout.printf (" %.2f", value);
+ var x = sample;
+ unowned uchar[] pixels = image.pixbuf.get_pixels ();
+ var rowstride = image.pixbuf.rowstride;
+ for (int y = 0; y < values.length; y++) {
+ var i = (values.length - y - 1) * rowstride + x * 3;
+ var level = float.min (1f, Math.log10f (101f + values[y]) / 2f);
+ var value = (uchar) (level * 255);
+ pixels[i] = value;
+ pixels[i + 1] = value;
+ pixels[i + 2] = value;
}
- stdout.printf ("\n");
+ var allocation = image.allocation;
+ image.queue_draw_area (allocation.x + x, allocation.y, 1, allocation.height);
}
}
}