Hello,
I try to perform dynamic upsampling on a signal (SR=44,1kHz) to double the sample rate.
Here is the code  I wrote to test it.  It works using a raw audio file (cdparanoia -r 1) with a 1Khz sin signal.
When I look to my output signal with an oscilloscope it looks quite good but I get some noise (glitches?) that makes it really sound bad.
Is there something I do wrong ? Is it a libsamplerate problem ?

**************************
******My code*************
**************************



#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <samplerate.h>

int
main(int argc, const char *argv[])
{
  int TAILLEBUF = TAILLEBUF;
  int TAILLEBUF_OUT = TAILLEBUF;

  int16_t * p_readbuf= (int16_t *) malloc(sizeof(int16_t)*TAILLEBUF);
  float * pf_readbuf= ( float *) malloc(sizeof(float)*TAILLEBUF);
  float * pf_writebuf= ( float *) malloc(sizeof(float)*TAILLEBUF_OUT);

  int fini=0;
  int finiRead=0;

  int fd,fdread;    /* sound device file descriptor */
 
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 120000;
  int error;

  SRC_STATE * src_state;
  SRC_DATA src_data;
  src_data.src_ratio = atoi(argv[3]);
  src_data.input_frames=0;
  src_data.end_of_input = 0;
  src_data.data_out = pf_writebuf;
  src_data.output_frames=TAILLEBUF_OUT/2;

  src_state = src_new(2,2,&error);

  /* open sound device I'm working on my own sound card */
  fd = open("/dev/AudioDriver/data", O_WRONLY);
  if (fd < 0) {
    perror("open of /dev/AudioDriver/data failed");
    exit(1);
  }

/*My raw sound file*/
  fdread = open("./cdda.raw", O_RDONLY);
  if (fd < 0) {
    perror("open of cdda.raw failed");
    exit(1);
  }


  fd_set writefds[1];
  FD_ZERO(writefds);
  FD_SET(fd, writefds);
  int k=0;
       while (!finiRead) {

    /* read TAILLEBUF/2 Frames */

    int j;
    if(read(fdread,p_readbuf,TAILLEBUF*sizeof(int16_t))!=TAILLEBUF*sizeof(int16_t))
            finiRead=1;
   
    int i=0;
    /*Convert from 16bit integer to Float*/
           for(i=0;i<TAILLEBUF;i++)
      {
        pf_readbuf[i]=((p_readbuf[i])<<16) ;
        }
       
    if(src_data.input_frames==0)
      {
        src_data.data_in = pf_readbuf;
        src_data.input_frames=TAILLEBUF/2;
      }

    tv.tv_sec = 0;
    tv.tv_usec = 120000;
    fd_set writefds[1];
    FD_ZERO(writefds);
    FD_SET(fd, writefds);
    while(select(fd+1, NULL, writefds, NULL, &tv)!=1){   
      tv.tv_sec = 0;
      tv.tv_usec = 120000;
      fd_set writefds[1];
      FD_ZERO(writefds);
      FD_SET(fd, writefds);
    }

    int sent = 0;
     
      if((error = src_process(src_state,&src_data))!=0)printf("error\n");
   
      while(sent < src_data.output_frames_gen)
        {
          /*Convert my 2-floats frame to an unsigned long frame containing my to channels*/
          unsigned long frame;
          frame = (unsigned long) ((src_data.data_out[sent]))>>16;
          frame |= (((unsigned long) (src_data.data_out[sent+1])) & 0xFFFF0000);
          if(write(fd, &frame, sizeof(unsigned long))!=sizeof(unsigned long))
        {fini = 1;
        }
          sent += 2;
       }
  exit(0);
}

****************************
****************************
****************************


I hope that you can understand my english and that my code is clear enough for you to help me.
Thanks in advance.

Mathieu