<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<br>
On 04/21/2010 03:43 AM, Niels Mayer wrote:
<blockquote
 cite="mid:k2m6fb2fb121004201043n460190b6g2a633333e9874772@mail.gmail.com"
 type="cite">I don't know anything about the kluppe code, but are the
underlying libraries you're using re-entrant? My brief perusal
  <div>of your code raised red-flags due to use of signal(2) and
alarm(2). Execution ends up jumping around
asynchronously&&indeterminately, in audio code or threads that
probably should never have that happen. For example. lets say you had a
piece of code that needed to execute within a certain amount of time in
order to generate a data-stream w/o interruption -- lowlevel code that
never expected to be jumped out of to take care of some random
"application level" business that it shouldn't need to concern itself
over.</div>
  <div>
  <div><br>
  </div>
  <div>This probably requires an event-driven architecture, where
everything is driven by IO. Looked at that way, a timer timing out is
just another thing to select(2)  on; as long as your code doesn't block
on I/O, you never need to worry about reentrancy.</div>
  <div><br>
  </div>
  </div>
</blockquote>
<br>
<br>
Thanks for taking the time to ponder this one.<br>
<br>
Based on what I understand from your suggestion above I have changed
the code to the following. However I still get the buzz during the
pause period at the end of the loop. So it seems that the audio stream
is being output with non zero values even though I have expressly set
it to be silent prior to the select/sleep kicking in. If anyone has
thoughts on why this is happening the way that it is I would appreciate
your insight.<br>
<br>
<br>
                    struct timeval time, pause;<br>
<br>
                    pause.tv_sec  = data->playbackdelay;<br>
                    pause.tv_usec = 0;<br>
                     <br>
                     looperdata_set_vol(data,0);    <br>
<br>
                    (void) select(0, 0, 0, 0, &pause);<br>
                //    sleep((int)data->playbackdelay);<br>
                    <br>
                    looperdata_set_vol(data,vol);<br>
<br>
                    /* return to start of loop */<br>
                    data->playindex += data->loopstart -
data->loopend;<br>
<br>
<br>
<br>
<pre class="moz-signature" cols="72">
Patrick Shirkey
Boost Hardware Ltd</pre>
<br>
<br>
<blockquote
 cite="mid:k2m6fb2fb121004201043n460190b6g2a633333e9874772@mail.gmail.com"
 type="cite">
  <div>
  <div>Niels</div>
  <div><a moz-do-not-send="true" href="http://nielsmayer.com">http://nielsmayer.com</a><br>
  <br>
  <div class="gmail_quote">On Tue, Apr 20, 2010 at 6:12 AM, Patrick
Shirkey <span dir="ltr"><<a moz-do-not-send="true"
 href="mailto:pshirkey@boosthardware.com">pshirkey@boosthardware.com</a>></span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br>
    <br>
I'm trying to add a threaded timer to kluppes looperdata.c<br>
looperdata_calc_sample_stereo function so that I can add a delayed<br>
restart to the loop process.<br>
    <br>
Can anyone tell me why the "while" statement in the following code locks<br>
up the audio stream for the loop it is being run on? I end up with a<br>
buzz throughout the delay period instead of a nice quiet delay period.<br>
    <br>
    <br>
    <br>
#include <stdlib.h><br>
#include <signal.h><br>
#include <stdio.h><br>
    <br>
/* This flag controls termination of the main loop.  */<br>
volatile sig_atomic_t isdelay_countdown = 1;<br>
    <br>
/* The signal handler just clears the flag and re-enables itself.  */<br>
void catch_alarm (int sig){<br>
  isdelay_countdown = 0;<br>
  signal (sig, catch_alarm);<br>
}<br>
    <br>
    <br>
    <br>
    vol = data->vol;<br>
    <br>
                if(data->playbackdelay > 0){<br>
    <br>
                    /* Establish a handler for SIGALRM signals.  */<br>
                    signal (SIGALRM, catch_alarm);<br>
    <br>
                     isdelay_countdown = 1;<br>
    <br>
                      /* Call alarm to countdown length of<br>
playbackdelay  */<br>
                      alarm ((int)data->playbackdelay);<br>
    <br>
                      /* Check the flag once in a while to see when to<br>
quit.  */<br>
                      while(isdelay_countdown){<br>
                        looperdata_set_vol(data,0);<br>
                        data->isplaying = 0;<br>
                     }<br>
    <br>
    <br>
                }<br>
    <br>
/* return to start of loop */<br>
    <br>
                    looperdata_set_vol(data,vol);<br>
                    data->isplaying = 1;<br>
                    data->playindex += data->loopstart -
data->loopend;<br>
    <font color="#888888"><br>
    <br>
    <br>
    <br>
--<br>
Patrick Shirkey<br>
Boost Hardware Ltd<br>
    <br>
_______________________________________________<br>
Linux-audio-dev mailing list<br>
    <a moz-do-not-send="true"
 href="mailto:Linux-audio-dev@lists.linuxaudio.org">Linux-audio-dev@lists.linuxaudio.org</a><br>
    <a moz-do-not-send="true"
 href="http://lists.linuxaudio.org/listinfo/linux-audio-dev"
 target="_blank">http://lists.linuxaudio.org/listinfo/linux-audio-dev</a><br>
    </font></blockquote>
  </div>
  <br>
  </div>
  </div>
</blockquote>
</body>
</html>