Re: [gtk-list] Sound with GTK



On Wed, 17 Jun 1998, Pete Hollobon wrote:

> Hi,
> 
> I'm currently writing a program to play samples with real-time adjustable
> rate.  At the moment, I'm forking a child to actually send the sample to
> /dev/audio, and the parent changes the pitch with IOCTL on the same
> file descriptor and does various other things.
> 
> I'm not too happy with this approach, as I'd like to be able to set
> cue-points on teh same and various other things that would require
> communication with the child playing the sample.  I tried using
> the timeout functions, but they made the whole app very jerky.
> 
> I also have the problem that GDK gives me "an X io error occured" error,
> due to me closing the connection to X.
> 
> Anyone got any ideas about a better implementation?

you might want to hook into gtk's main loop.
i'm working on a new tracker for linux (BEAST) which does realtime
playback as well and uses gtk as gui.
for hooking into the main loop, i'm using the following code:

main()
{
  [...]

  /* hook directly into gtk's main loop, ready, go! ;)
   */
  gtk_timeout_add (0, bst_iteration, NULL);
  gtk_main ();
  
  [...]
}

static gint
bst_iteration (gpointer data)
{
  if (bse_main_can_block ())
    while (bse_main_need_iteration ())
      bse_main_iteration ();
  else
    bse_main_iteration ();

  if (!gtk_events_pending ())
    {
      /* let BSE do the blocking if gtk has nothing to do
       */
      bse_main_trigger_ticks ();
      bse_main_iteration ();
    }

  /* let gtk do the blocking if we aren't on a time critical mission
   */
  gtk_timeout_add (bse_main_can_block () ? 0 : 100, bst_iteration, NULL);

  return FALSE;
}

where
bse_main_can_block() returns whether audio data needs to be processed and
if bse_main_iteration() would block if called (e.g. when the audio queue
is full), e.g. if i'm writing to a file, this function returns FALSE, if
i'm writing to /dev/dsp this function returns TRUE.
bse_main_need_iteration() returns TRUE as long as the audio queue is not full.
bse_main_iteration() puts out the samples to /dev/dsp and if that's full, it'll
block.
bse_main_trigger_ticks() is just invoking callbacks from BSE to adjust the
GUI to the current playposition.


> 
> Cheers,
> Pete
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]