[PLUG-AV] VU Metre for a mixing desk
James Bromberger
james at rcpt.to
Sat Apr 23 16:27:49 WST 2011
Hi all,
Have a read of this code, and then try running it (Under linux, with
GStreamer and GTK perl libraries). Its only 60 lines, and hopefully you
can see what it does! Perhaps you'd like to try writing some code too? :)
James
#!/usr/bin/perl
use strict;
use warnings;
use GStreamer -init;
use Gtk2 -init;
my $loop = Glib::MainLoop->new;
my $pipeline = GStreamer::Pipeline->new("sample");
my $caps = GStreamer::Caps->from_string("audio/x-raw-int,channels=2");
my $testsrc = GStreamer::ElementFactory->make("audiotestsrc", "src");
my $convert = GStreamer::ElementFactory->make("audioconvert", "convert");
my $level = GStreamer::ElementFactory->make("level", "vu0");
my $sink = GStreamer::ElementFactory->make("fakesink", "sink");
$testsrc->set("wave", 'gaussian-noise');
$pipeline->add($testsrc, $convert, $level, $sink);
$testsrc->link($convert);
$convert->link_filtered($level, $caps);
$level->link($sink);
$level->set("message", 1);
$level->set("interval", 100000000000);
$pipeline->get_bus->add_watch(\&hdl_level, $loop);
$pipeline->set_state("playing");
my $window = Gtk2::Window->new();
my $hbox = Gtk2::HBox->new();
my $vu00 = Gtk2::ProgressBar->new();
$vu00->set_orientation('bottom-to-top');
my $vu01 = Gtk2::ProgressBar->new();
$vu01->set_orientation('bottom-to-top');
$hbox->add($vu00);
$hbox->add($vu01);
$window->add($hbox);
$window->signal_connect('delete_event' => sub { $loop->quit; });
$window->show_all;
$loop->run;
$pipeline->set_state("null");
exit;
sub pow_rms {
my $val = shift;
return 10 ** ($val / 20);
}
sub hdl_level {
my ($bus, $message, $loop) = @_;
return 1 unless $message->type & 'element' &&
$message->get_structure->{name} eq "level";
my $num_channels = scalar @{$message->get_structure->{fields}[5][2]};
print pow_rms($message->get_structure->{fields}[5][2][0][0]) . "\n";
for (my $i = 0; $i< scalar @{$message->get_structure->{fields}[5][2]};
$i++) {
my $expr = '$' . $message->src->get_name . $i . "->set_fraction(" .
pow_rms($message->get_structure->{fields}[5][2][$i][0]) . ")";
eval $expr;
}
return 1;
}
--
Mobile: +61 422 166 708, Email: james_AT_rcpt.to
More information about the AV
mailing list