in reply to Insight needed: Perl, C, Gtk2, Audio, Threads, IPC & Performance - Oh My!

This is only a comment, since it seems what you are doing is very complex. I didn't see you mention SDL::Mixer. You can have multiple channels of sound, see Tk Game Sound demo

If you can get SDL::Mixer to work for you, you should be able to incorporate it with Gtk2. You may be able to use the "do 1 loop" trick of Gtk2

Gtk2->main_iteration while Gtk2->events_pending;
to avoid having to use the Gtk2 Mainloop. You could let the SDL event loop run things, just repeadetly call the Gtk2->main_iteration to keep the gui responsive. As an example with Tk
#!/usr/bin/perl -w use strict; use Gtk2; use Tk; my $mw = MainWindow->new(-title=>'Tk Window'); Gtk2->init; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Gtk2 Window'); my $glabel = Gtk2::Label->new("This is a Gtk2 Label"); $window->add($glabel); $window->show_all; my $tktimer = $mw->repeat(10, sub{ Gtk2->main_iteration while Gtk2->events_pending; }); $mw->Button(-text=>' Quit ', -command => sub{exit} )->pack(); MainLoop; __END__

As far as threads go, the recent versions of Gtk2 have a way to share Gtk2 objects across threads, but it is tricky and not generally gauranteed to always work. It has an enter and leave method, to tell Gtk2 to enter and leave the thread.

use Gtk2 qw/-init -threads-init/; die "Glib::Object thread safetly failed" unless Glib::Object->set_threadsafe (TRUE); ..... ..... sub thread_work{ Gtk2::Gdk::Threads->enter; ......... ......... Gtk2::Gdk::Threads->leave; }

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Insight needed: Perl, C, Gtk2, Audio, Threads, IPC & Performance - Oh My!
by Joost (Canon) on Jun 02, 2006 at 00:34 UTC
    Actually, the mixing part of the program is more or less done already - it's all handled by compiled C plugins. I discarded SDL from consideration because it doesn't seem to give me enough low level access: I need to be able to generate audio streams quickly and dump them on the sound device (something like 40 samples at a time, that's once every ~0.001 second).

    SDL has a lot of nice routines for playing & mixing long samples & streams, but nothing that gives me that kind of response. Or so it seems to me reading the docs. If you or anyone else have tried something like this with SDL, I'd be happy to hear your stories :-)

      I use SDL_mixer, and I would echo your conclusion: it doesn't give enough low level access. It's fine for playing one background music track and doing fire & forget sound effects, but that's it. For my project, that's just barely kinda mostly sorta good enough for now, but the next time I revisit audio I'll be switching to either OpenAL or the raw ALSA API. I want to be able to change the volume of a triggered sound effect while it's playing. I want an immediate notification of when a sound has completed so I can sequence something else (non-audio) after it. I want to get feedback about how far through a sound I am. I want to do pitch bending. I wouldn't mind some 3D sound processing (although I think SDL_mixer can do some of that.)