xiRetimer

fit recorded audio to a tempo
git clone https://git.ce9e.org/xiRetimer.git

commit
3c2970db2f559685f372facd7c89f752caf683e8
parent
9170f49a8cee8acdadbe226e2ccb1aacbda49b7e
Author
xi <tobias.bengfort@gmx.net>
Date
2010-11-04 13:07
lin

Diffstat

M README 3 ++-
M src/marker.cpp 9 +++++++++
M src/marker.h 3 ++-
M src/sample.cpp 10 +++++++---
M xiRetimer 0

5 files changed, 20 insertions, 5 deletions


diff --git a/README b/README

@@ -11,8 +11,9 @@ timestretch - rubberband
   11    11 
   12    12 TODO
   13    13 
   -1    14 draw to different buffers only when needed
   -1    15 getRatio(float) -> interpolation
   14    16 exits with error
   15    -1 draw to different buffers onlly when needed
   16    17 bugtracking
   17    18 im/export different kinds of audio files (libmad)
   18    19 soundtouch

diff --git a/src/marker.cpp b/src/marker.cpp

@@ -61,12 +61,20 @@ float Marker::getRatio() {
   61    61     return NULL;
   62    62 }
   63    63 
   -1    64 /*
   64    65 float Marker::getRatio(int i) {
   65    66   if (i>=0 && i<getLength()-1)
   66    67     return (getNew(i+1)-getNew(i))/(getOld(i+1)-getOld(i));
   67    68   else
   68    69     return NULL;
   69    70 }
   -1    71 */
   -1    72 
   -1    73 float Marker::getRatio(float o) {
   -1    74   // TODO not exact at all
   -1    75   float n=100;
   -1    76   return ((old2new(o+1/n)-old2new(o-1/n))/(2/n));
   -1    77 }
   70    78 
   71    79 int Marker::getLength() {
   72    80   return anew.getLength();
@@ -101,6 +109,7 @@ int Marker::resort(int pi) {
  101   109 }
  102   110 
  103   111 float Marker::old2new(float o) {
   -1   112 // !!linear
  104   113 // converts old 0-1 values to new 0-1 values
  105   114   int i=getAreaOld(o);
  106   115   // linear interpolation

diff --git a/src/marker.h b/src/marker.h

@@ -22,7 +22,8 @@ public:
   22    22   float getOld(int pi);
   23    23   void setNew(int pi, float pnew);
   24    24   float getRatio(); // factor by wich the whole sample is stretched; used to guess the length of the output array;
   25    -1   float getRatio(int i); // factor by wich the is area is stretched;
   -1    25 //  float getRatio(int i); // factor by wich this area is stretched;
   -1    26   float getRatio(float o); // factor by wich is stretched on this place;
   26    27   int getLength();
   27    28   void print();
   28    29   // 0-1 conversion

diff --git a/src/sample.cpp b/src/sample.cpp

@@ -1,5 +1,7 @@
    1     1 #include "sample.h"
    2     2 
   -1     3 // TODO quality!!!
   -1     4 
    3     5 Sample::Sample(Marker* m) {
    4     6   marker=m;
    5     7   length=0;
@@ -45,7 +47,7 @@ int Sample::loadFile(const char* fileName) {
   45    47     return 1;
   46    48   }
   47    49   // setup data
   48    -1   olength=sfinfo.frames; // apropriate length
   -1    50   olength=sfinfo.frames; // expected length
   49    51   delete[] odata;
   50    52   odata=new float[olength];
   51    53   
@@ -94,7 +96,7 @@ int Sample::writeFile(const char* fileNameOut) {
   94    96 
   95    97 int Sample::process() {
   96    98   //reads from odata and writes to data
   97    -1   const int bufferLength=100000;  // important
   -1    99   const int bufferLength=4096; // important // 
   98   100   float **ibuf = new float *[1];
   99   101   ibuf[0]=new float[bufferLength];
  100   102   float **obuf = new float *[1];
@@ -105,7 +107,7 @@ int Sample::process() {
  105   107   delete[] data;
  106   108   data=new float[length];
  107   109   for (int i=0; i<marker->getLength()-1; ++i) {
  108    -1     float ratio=marker->getRatio(i);
   -1   110 //    float ratio=marker->getRatio(i); // redesign: getRatio(o)
  109   111     int count=0; // position in section (o)
  110   112     int frames=int((marker->getOld(i+1)-marker->getOld(i))*olength); // length of section (o)
  111   113     while (count<frames && count2<olength && avail2<length) {
@@ -114,7 +116,9 @@ int Sample::process() {
  114   116         ibuf[0][j]=odata[count2+j];
  115   117         count++;
  116   118       }
   -1   119       float ratio=marker->getRatio(count2/(float)olength);
  117   120       count2+=bufferLength;
   -1   121       if (count2>olength) count2=olength;
  118   122       // process ibuf
  119   123       RubberBand::RubberBandStretcher ts(sfinfo.samplerate, 1, 0, ratio);
  120   124       ts.setMaxProcessSize(bufferLength*10);

diff --git a/xiRetimer b/xiRetimer

Binary files differ.