On 04/21/2010 03:43 AM, Niels Mayer wrote:
I don't know anything about the kluppe code, but are the underlying libraries you're using re-entrant? My brief perusal
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.

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.



Thanks for taking the time to ponder this one.

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.


                    struct timeval time, pause;

                    pause.tv_sec  = data->playbackdelay;
                    pause.tv_usec = 0;
                    
                     looperdata_set_vol(data,0);   

                    (void) select(0, 0, 0, 0, &pause);
                //    sleep((int)data->playbackdelay);
                   
                    looperdata_set_vol(data,vol);

                    /* return to start of loop */
                    data->playindex += data->loopstart - data->loopend;



Patrick Shirkey
Boost Hardware Ltd


Niels
http://nielsmayer.com

On Tue, Apr 20, 2010 at 6:12 AM, Patrick Shirkey <pshirkey@boosthardware.com> wrote:
Hi,

I'm trying to add a threaded timer to kluppes looperdata.c
looperdata_calc_sample_stereo function so that I can add a delayed
restart to the loop process.

Can anyone tell me why the "while" statement in the following code locks
up the audio stream for the loop it is being run on? I end up with a
buzz throughout the delay period instead of a nice quiet delay period.



#include <stdlib.h>
#include <signal.h>
#include <stdio.h>

/* This flag controls termination of the main loop.  */
volatile sig_atomic_t isdelay_countdown = 1;

/* The signal handler just clears the flag and re-enables itself.  */
void catch_alarm (int sig){
  isdelay_countdown = 0;
  signal (sig, catch_alarm);
}



    vol = data->vol;

                if(data->playbackdelay > 0){

                    /* Establish a handler for SIGALRM signals.  */
                    signal (SIGALRM, catch_alarm);

                     isdelay_countdown = 1;

                      /* Call alarm to countdown length of
playbackdelay  */
                      alarm ((int)data->playbackdelay);

                      /* Check the flag once in a while to see when to
quit.  */
                      while(isdelay_countdown){
                        looperdata_set_vol(data,0);
                        data->isplaying = 0;
                     }


                }

/* return to start of loop */

                    looperdata_set_vol(data,vol);
                    data->isplaying = 1;
                    data->playindex += data->loopstart - data->loopend;




--
Patrick Shirkey
Boost Hardware Ltd

_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-dev