Show the spectrogram image

This commit is contained in:
Alexander Kojevnikov 2010-05-06 17:09:52 +10:00
parent 28ade26079
commit 491db7c663
2 changed files with 28 additions and 6 deletions

View File

@ -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);

View File

@ -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);
}
}
}