head	1.5;
access;
symbols
	rel-0-2-1:1.4
	before_adj_struct:1.3.2.3
	jack:1.3.0.2
	rel-0-1-0:1.2
	rel-0-0-0:1.1;
locks; strict;
comment	@ * @;


1.5
date	2007.03.22.20.55.43;	author robertatwood;	state Exp;
branches;
next	1.4;

1.4
date	2006.04.05.21.53.36;	author robertatwood;	state Exp;
branches;
next	1.3;

1.3
date	2005.08.20.18.26.43;	author robertatwood;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2005.04.03.20.05.40;	author robertatwood;	state Exp;
branches;
next	1.1;

1.1
date	2004.04.16.11.36.56;	author robertatwood;	state Exp;
branches;
next	;

1.3.2.1
date	2005.12.28.16.13.35;	author robertatwood;	state Exp;
branches;
next	1.3.2.2;

1.3.2.2
date	2005.12.28.18.17.00;	author robertatwood;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	2006.01.04.00.06.03;	author robertatwood;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2006.04.05.21.42.24;	author robertatwood;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Updated GPL text to reflect new address of Free Software foundation
Prepare to move repository to savannah.nongnu.org
@
text
@/**************************************************************
This file is part of the Variseq program.
Variseq -- a variable pitch and step sample sequencer
Copyright (C) 2004  Robert Atwood r.atwood (at) imperial (dot) ac (dot) uk

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
See the file COPYING for more information
**************************************************************/

//#define NOPRINT
#include <stdlib.h>
#include <math.h>
#include <sndfile.h>
#include <samplerate.h>
#include "mysound.h"
#include "samples.h"
   /* resample the sound and store in a table */
   /* if the note is requested. Otherwise the slot in the */
   /* table remains empty. Store a flag in the "used" table */
   /* if this sample/note combination is in use */

   void samples::stretch(int samplenum,int oct,int notenum){
      float * outp, *inp;
      double omul,the_ratio;
      static SRC_DATA sr;
      static SRC_DATA * srab = &sr;
      int * thisused = *( *(used + samplenum) + oct);
      sbuf * thisbuf = *(*(str_samples+samplenum) + oct);
      sbuf * origsound = orig_samples + samplenum;
      /* just copy the buffer if no stretching is needed */
      if (thisused[notenum] == 2){ /* free the old if replacement is needed */
         free_sbuf(thisbuf+notenum);
      }
      if (notenum == 0 && oct == D_OCT){
          init_sbuf(thisbuf+notenum,44100);
          copy_sbuf( thisbuf + notenum, orig_samples + samplenum);
      }else{
      /* use libsamplerate to resample the sound */
            omul = pow(2.0,(double)(D_OCT - oct));
            the_ratio = noteratio[notenum] * omul;

            thisbuf[notenum].binfo = (SF_INFO *)calloc(1,sizeof(SF_INFO));

            #ifndef NOPRINT
            printf("Stretching  ( %i ) %i, ratio %f\n",oct,notenum,the_ratio);
            #endif

            /* set up the parameters */
            #ifndef NOPRINT
            printf("setting up srab data struct\n");
            printf("allocating\n");
            #endif
            //srab = (SRC_DATA *)calloc(1,sizeof(SRC_DATA));
            #ifndef NOPRINT
            printf("output frames\n");
            #endif
            srab->output_frames = origsound->binfo->frames;
            #ifndef NOPRINT
            printf("input frames\n");
            #endif
            srab->input_frames = origsound->binfo->frames;
            #ifndef NOPRINT
            printf("ratio\n");
            #endif
            srab->src_ratio = the_ratio;

            #ifndef NOPRINT
            printf("setting up input and output\n");
            #endif
            outp = (float *)calloc(srab->output_frames * origsound->binfo->channels, sizeof(float));
            inp = origsound->buffer;
            srab->data_in = inp;
            srab->data_out = outp;
            /* do the stretch */

/*
enum
{
   SRC_SINC_BEST_QUALITY      = 0,
   SRC_SINC_MEDIUM_QUALITY      = 1,
   SRC_SINC_FASTEST         = 2,
   SRC_ZERO_ORDER_HOLD         = 3,
   SRC_LINEAR               = 4
} ;
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* !! IT APPEARS THAT LINEAR HAS A BUG !! */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */

            #ifndef NOPRINT
            printf("calling libsamplerate stretch\n");
            #endif
            src_simple(srab,SRC_SINC_BEST_QUALITY,origsound->binfo->channels);
               /* put into the sample table */
            #ifndef NOPRINT
            printf("done\n");
            #endif

            #ifndef NOPRINT
            printf("transferring data to table\n");
            printf("frames\n");
            #endif
            thisbuf[notenum].binfo->frames = srab->output_frames_gen;
            #ifndef NOPRINT
            printf("samplerate\n");
            #endif
            thisbuf[notenum].binfo->samplerate = origsound->binfo->samplerate;
            #ifndef NOPRINT
            printf("channels\n");
            #endif
            thisbuf[notenum].binfo->channels = origsound->binfo->channels;
            #ifndef NOPRINT
            printf("format\n");
            #endif
            thisbuf[notenum].binfo->format = origsound->binfo->format;
            #ifndef NOPRINT
            printf("sections\n");
            #endif
            thisbuf[notenum].binfo->sections = origsound->binfo->sections;
            #ifndef NOPRINT
            printf("seekable\n");
            #endif
            thisbuf[notenum].binfo->seekable = origsound->binfo->seekable;
            #ifndef NOPRINT
            printf("output buffer pointer\n");
            #endif
            thisbuf[notenum].buffer = outp;
            #ifndef NOPRINT
            printf("Frames in, out: %li %li \n",srab->input_frames,srab->output_frames_gen);
            #endif
            //free(srab);
            #ifndef NOPRINT
            printf("done\n");
            #endif
      }
      #ifndef NOPRINT
      printf("Setting the sample used flag\n");
      #endif
      thisused[notenum] = 1;
      #ifndef NOPRINT
      system("free");
      printf("returning....\n");
      #endif
      return;
   };
/* $Id: stretch.C,v 1.4 2006/04/05 21:53:36 robertatwood Exp $ */
@


1.4
log
@Jack version is the main branch now
@
text
@d18 1
a18 1
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
d21 1
d158 1
a158 1
/* $Id: stretch.C,v 1.3.2.4 2006/04/05 21:42:24 robertatwood Exp $ */
@


1.3
log
@Added a save/restore workspace function
Added window to display names of samples
@
text
@d21 2
a22 1

d42 3
d104 1
a104 1
            src_simple(srab,SRC_SINC_FASTEST,origsound->binfo->channels);
d152 1
d157 1
a157 1
/* $Id: stretch.C,v 1.2 2005/08/01 00:47:42 robert Exp $ */
@


1.3.2.1
log
@Checkpoint-problem with sample table address
@
text
@a40 3
      if (thisused[notenum] == 1){
         free_sbuf(thisbuf);
      }
d152 1
a152 1
/* $Id: stretch.C,v 1.3 2005/08/20 18:26:43 robertatwood Exp $ */
@


1.3.2.2
log
@Appears to work but needs file name placed in the textbox after replacement
@
text
@d41 2
a42 2
      if (thisused[notenum] == 2){ /* free the old if replacement is needed */
         free_sbuf(thisbuf+notenum);
d155 1
a155 1
/* $Id: stretch.C,v 1.3.2.1 2005/12/28 16:13:35 robertatwood Exp $ */
@


1.3.2.3
log
@Jack input as well, and scrambling in compile-time option
@
text
@d21 1
a21 1
#define NOPRINT
d155 1
a155 1
/* $Id: stretch.C,v 1.3.2.2 2005/12/28 18:17:00 robertatwood Exp $ */
@


1.3.2.4
log
@Jack or portaudio version with compile-time selection
Autoscramblizer option , input option
@
text
@d21 1
a21 2
//#define NOPRINT
#include <stdlib.h>
d103 1
a103 1
            src_simple(srab,SRC_SINC_BEST_QUALITY,origsound->binfo->channels);
a150 1
      system("free");
d155 1
a155 1
/* $Id: stretch.C,v 1.3.2.3 2006/01/04 00:06:03 robertatwood Exp $ */
@


1.2
log
@Changed the buffer writing so that samples extend into unused notes.
Altered file choose usage to correctly use the FLTK chooser
@
text
@d93 3
d100 1
a100 1
            src_simple(srab,SRC_LINEAR,origsound->binfo->channels);
d152 1
a152 1
/* $Id: stretch.C,v 1.1.1.1 2004/05/23 20:34:45 robert Exp $ */
@


1.1
log
@Initial version uploaded to Sourceforge
@
text
@d97 1
a97 1
            src_simple(srab,SRC_SINC_BEST_QUALITY,origsound->binfo->channels);
d149 1
a149 1
/* $Id: stretch.C,v 1.6 2004/04/13 09:39:00 robert Exp $ */
@

