xiRetimer

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

commit
bfc5f4878b16802da2f9d8c020fc19fc5d8f714c
parent
294d5d098f878a9a0473765b2e4ebd8c75df8e7c
Author
Tobias Bengfort <tobias.bengfort@gmx.net>
Date
2010-11-21 20:33
improved intpoly

Diffstat

M README 2 +-
M README.in 2 +-
M src/curve.cpp 2 +-
M src/intmode_poly.h 155 +++++++++++++++++++++++++++++++++----------------------------
M src/marker.cpp 5 ++++-
M src/marker.h 1 +
M src/sample.cpp 2 --
M src/sample.h 1 +
M xiRetimer 0
M xiretimer.dbp 8 ++++++++

10 files changed, 100 insertions, 78 deletions


diff --git a/README b/README

@@ -1,6 +1,6 @@
    1     1 xiRetimer v 0.2
    2     2 
    3    -1 Tool to fir recordet Audio to a tempo.
   -1     3 Tool to fit recordet Audio to a tempo.
    4     4 
    5     5 playback - sdl
    6     6 gui - wxwidgets

diff --git a/README.in b/README.in

@@ -1,6 +1,6 @@
    1     1 xiRetimer v @VERSION@
    2     2 
    3    -1 Tool to fir recordet Audio to a tempo.
   -1     3 Tool to fit recordet Audio to a tempo.
    4     4 
    5     5 playback - sdl
    6     6 gui - wxwidgets

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

@@ -84,6 +84,6 @@ void Curve::clearMarker() {marker->reset();}
   84    84 
   85    85 bool Curve::showIntLine() {
   86    86   // TODO showIntLine
   87    -1   return false;
   -1    87   return true;
   88    88 }
   89    89 

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

@@ -6,74 +6,47 @@
    6     6 
    7     7 /*
    8     8 This defines a interpolytion mode used in marker
    9    -1 // TODO doesnt really work yet
   10     9 // TODO lots of optimisation to do
   11    10 */
   12    11 
   13    -1 float** invertMatrix(float** A) {
   14    -1   float** X=new float*[3];
   15    -1   for (int i=0; i<3; ++i) {
   16    -1     X[i]=new float[3];
   17    -1   }
   18    -1   int i,j;
   19    -1   float n=0; // determinant of A
   20    -1 
   21    -1   n+=A[0][0]*A[1][1]*A[2][2];
   22    -1   n+=A[0][1]*A[1][2]*A[2][0];
   23    -1   n+=A[0][2]*A[1][0]*A[2][1];
   24    -1 
   25    -1   n-=A[0][0]*A[1][2]*A[2][1];
   26    -1   n-=A[0][1]*A[1][0]*A[2][2];
   27    -1   n-=A[0][2]*A[1][1]*A[2][0];
   28    -1      
   29    -1   if(n*n<=0.00000000001) {
   30    -1     for (int i=0; i<3; ++i) {
   31    -1       for (int j=0; j<3; ++j) {
   32    -1         X[i][j]=0;
   33    -1       }
   34    -1     }
   35    -1     return X;
   36    -1   }
   -1    12 namespace _IntPoly {
   -1    13   void update(Marker* marker, int pi);
   -1    14   float calculate(float x);
   -1    15   float** invertMatrix(float** A);
   -1    16   float a=0,b=0,c=0,d=0;
   -1    17   int IPi,IPn;
   -1    18 }
   37    19 
   38    -1   X[0][0]=A[1][1]*A[2][2]-(A[2][1]*A[1][2]);
   39    -1   X[1][0]=(-1)*(A[1][0]*A[2][2]-(A[2][0]*A[1][2]));
   40    -1   X[2][0]=A[1][0]*A[2][1]-(A[2][0]*A[1][1]);
   41    -1      
   42    -1   X[0][1]=(-1)*(A[0][1]*A[2][2]-A[2][1]*A[0][2]);
   43    -1   X[1][1]=A[0][0]*A[2][2]-A[0][2]*A[2][0];
   44    -1   X[2][1]=(-1)*(A[0][0]*A[2][1]-A[2][0]*A[0][1]);
   45    -1  
   46    -1   X[0][2]=A[0][1]*A[1][2]-A[1][1]*A[0][2];
   47    -1   X[1][2]=(-1)*(A[0][0]*A[1][2]-A[1][0]*A[0][2]);
   48    -1   X[2][2]=A[0][0]*A[1][1]-A[1][0]*A[0][1];
   -1    20 float int_poly(Marker* marker, float old) {
   -1    21   int ii=marker->getAreaOld(old);
   -1    22   if (marker->_update || ii!=_IntPoly::IPi) _IntPoly::update(marker,ii);
   -1    23   marker->_update=false;
   -1    24   return _IntPoly::calculate(old);
   -1    25 }
   49    26 
   50    -1   for(i=0;i<3;i++) {
   51    -1     for(j=0;j<3;j++) {
   52    -1       X[i][j]=X[i][j]/n;
   53    -1     }
   54    -1   }
   55    -1  
   56    -1   return X;
   57    -1 } 
   -1    27 //*********************************************************************//
   58    28 
   59    -1 float int_poly(Marker* marker, float old) {
   60    -1   int i=marker->getAreaOld(old);
   61    -1   int n=marker->getLength();
   -1    29 float _IntPoly::calculate(float x) {
   -1    30   return _IntPoly::a*x*x*x+_IntPoly::b*x*x+_IntPoly::c*x+_IntPoly::d;
   -1    31 }
   62    32 
   63    -1   float x1=marker->getOld(i);
   64    -1   float x2=marker->getOld(i+1);
   65    -1   float y1=marker->getNew(i);
   66    -1   float y2=marker->getNew(i+1);
   -1    33 void _IntPoly::update(Marker* marker, int pi) {
   -1    34   IPn=marker->getLength();
   -1    35   IPi=pi;
   -1    36   float x1=marker->getOld(IPi);
   -1    37   float x2=marker->getOld(IPi+1);
   -1    38   float y1=marker->getNew(IPi);
   -1    39   float y2=marker->getNew(IPi+1);
   67    40   float d1;
   68    41   float d2;
   69    -1   if (i<=0)
   -1    42   if (IPi<=0)
   70    43     d1=(marker->getNew(1)-marker->getNew(0))/(marker->getOld(1)-marker->getOld(0));
   71    44   else
   72    -1     d1=(marker->getNew(i-1)-y2)/(marker->getOld(i-1)-x2);
   73    -1   if (i>=n-2)
   74    -1     d2=(marker->getNew(n-1)-marker->getNew(n-2))/(marker->getOld(n-1)-marker->getOld(n-2));
   -1    45     d1=(marker->getNew(IPi-1)-y2)/(marker->getOld(IPi-1)-x2);
   -1    46   if (IPi>=IPn-2)
   -1    47     d2=(marker->getNew(IPn-1)-marker->getNew(IPn-2))/(marker->getOld(IPn-1)-marker->getOld(IPn-2));
   75    48   else
   76    -1     d2=(y1-marker->getNew(i+2))/(x1-marker->getOld(i+2));
   -1    49     d2=(y1-marker->getNew(IPi+2))/(x1-marker->getOld(IPi+2));
   77    50 
   78    51   float** M=new float*[3];
   79    52   for (int j=0; j<3; ++j) {
@@ -101,9 +74,11 @@ float int_poly(Marker* marker, float old) {
  101    74     }
  102    75   }
  103    76   if (zeros==9) {
  104    -1     float c=(y2-y1)/(x2-x1);
  105    -1     float d=y1;
  106    -1     return c*(old-x1)+d;
   -1    77     a=0;
   -1    78     b=0;
   -1    79     c=(y2-y1)/(x2-x1);
   -1    80     d=y1;
   -1    81     return;
  107    82   }
  108    83     
  109    84 
@@ -112,25 +87,61 @@ float int_poly(Marker* marker, float old) {
  112    87   }
  113    88   delete[] M;
  114    89 
  115    -1   float a=I[0][0]*d1+I[0][1]*d2+I[0][2]*(y2-y1);
  116    -1   float b=I[1][0]*d1+I[1][1]*d2+I[1][2]*(y2-y1);
  117    -1   float c=I[2][0]*d1+I[2][1]*d2+I[2][2]*(y2-y1);
  118    -1   float d=y1-a*x1*x1*x1-b*x1*x1-c*x1;
   -1    90   _IntPoly::a=I[0][0]*d1+I[0][1]*d2+I[0][2]*(y2-y1);
   -1    91   _IntPoly::b=I[1][0]*d1+I[1][1]*d2+I[1][2]*(y2-y1);
   -1    92   _IntPoly::c=I[2][0]*d1+I[2][1]*d2+I[2][2]*(y2-y1);
   -1    93   _IntPoly::d=y1-_IntPoly::a*x1*x1*x1-_IntPoly::b*x1*x1-_IntPoly::c*x1;
  119    94 
  120    95   for (int j=0; j<3; ++j) {
  121    96     delete[] I[j];
  122    97   }
  123    98   delete[] I;
   -1    99 }
  124   100 
  125    -1 /*
  126    -1 std::cout << " a " << a;
  127    -1 std::cout << " b " << b;
  128    -1 std::cout << " c " << c;
  129    -1 std::cout << " d " << d;
  130    -1 std::cout << std::endl;
  131    -1 */
   -1   101 float** _IntPoly::invertMatrix(float** A) {
   -1   102   float** X=new float*[3];
   -1   103   for (int i=0; i<3; ++i) {
   -1   104     X[i]=new float[3];
   -1   105   }
   -1   106   int i,j;
   -1   107   float n=0; // determinant of A
  132   108 
  133    -1   return a*old*old*old+b*old*old+c*old+d;
  134    -1 }
   -1   109   n+=A[0][0]*A[1][1]*A[2][2];
   -1   110   n+=A[0][1]*A[1][2]*A[2][0];
   -1   111   n+=A[0][2]*A[1][0]*A[2][1];
   -1   112 
   -1   113   n-=A[0][0]*A[1][2]*A[2][1];
   -1   114   n-=A[0][1]*A[1][0]*A[2][2];
   -1   115   n-=A[0][2]*A[1][1]*A[2][0];
   -1   116      
   -1   117   if(n*n<=0.00000000001) {
   -1   118     for (int i=0; i<3; ++i) {
   -1   119       for (int j=0; j<3; ++j) {
   -1   120         X[i][j]=0;
   -1   121       }
   -1   122     }
   -1   123     return X;
   -1   124   }
   -1   125 
   -1   126   X[0][0]=A[1][1]*A[2][2]-(A[2][1]*A[1][2]);
   -1   127   X[1][0]=(-1)*(A[1][0]*A[2][2]-(A[2][0]*A[1][2]));
   -1   128   X[2][0]=A[1][0]*A[2][1]-(A[2][0]*A[1][1]);
   -1   129      
   -1   130   X[0][1]=(-1)*(A[0][1]*A[2][2]-A[2][1]*A[0][2]);
   -1   131   X[1][1]=A[0][0]*A[2][2]-A[0][2]*A[2][0];
   -1   132   X[2][1]=(-1)*(A[0][0]*A[2][1]-A[2][0]*A[0][1]);
   -1   133  
   -1   134   X[0][2]=A[0][1]*A[1][2]-A[1][1]*A[0][2];
   -1   135   X[1][2]=(-1)*(A[0][0]*A[1][2]-A[1][0]*A[0][2]);
   -1   136   X[2][2]=A[0][0]*A[1][1]-A[1][0]*A[0][1];
   -1   137 
   -1   138   for(i=0;i<3;i++) {
   -1   139     for(j=0;j<3;j++) {
   -1   140       X[i][j]=X[i][j]/n;
   -1   141     }
   -1   142   }
   -1   143  
   -1   144   return X;
   -1   145 } 
  135   146 
  136   147 #endif

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

@@ -1,5 +1,4 @@
    1     1 #include "marker.h"
    2    -1 
    3     2 #include "intmode_poly.h"
    4     3 
    5     4 Marker::Marker() {
@@ -8,6 +7,7 @@ Marker::Marker() {
    8     7   add(0,0);
    9     8   add(1,1);
   10     9   interpolationMode=0;
   -1    10   _update=true;
   11    11 }
   12    12 
   13    13 Marker::~Marker() {
@@ -36,6 +36,7 @@ void Marker::add(float pold, float pnew) {
   36    36   }
   37    37   anew.add(pnew);
   38    38   aold.add(pold);
   -1    39   _update=true;
   39    40 }
   40    41   
   41    42 void Marker::remove(int pi) {
@@ -43,6 +44,7 @@ void Marker::remove(int pi) {
   43    44   int i=resort(pi);
   44    45   anew.remove(i);
   45    46   aold.remove(i);
   -1    47   _update=true;
   46    48 }
   47    49 
   48    50 float Marker::getNew(int pi) {
@@ -55,6 +57,7 @@ float Marker::getOld(int pi) {
   55    57 
   56    58 void Marker::setNew(int pi, float pnew) {
   57    59   anew.set(resort(pi), pnew);
   -1    60   _update=true;
   58    61 }
   59    62 
   60    63 int Marker::getInterpolationMode() {return interpolationMode;}

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

@@ -46,6 +46,7 @@ public:
   46    46   float getRatio(float o); // factor by wich is stretched on this place;
   47    47   int getInterpolationMode();
   48    48   void setInterpolationMode(int m);
   -1    49   bool _update; // used by interpolation modes to determine if data has to be updated
   49    50 private:
   50    51   xiArray anew;
   51    52   xiArray aold;

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

@@ -1,6 +1,4 @@
    1     1 #include "sample.h"
    2    -1 #include <pthread.h>
    3    -1 
    4     2 #include "rbprocess.h"
    5     3 
    6     4 Sample::Sample(Marker* m) {

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

@@ -3,6 +3,7 @@
    3     3 
    4     4 #include <sndfile.h>
    5     5 #include <iostream>
   -1     6 #include <pthread.h>
    6     7 #include "marker.h"
    7     8 
    8     9 /*

diff --git a/xiRetimer b/xiRetimer

Binary files differ.

diff --git a/xiretimer.dbp b/xiretimer.dbp

@@ -8,6 +8,14 @@ Maintainer: xi <tobias.bengfort@fu-berlin.de>
    8     8 Priority: optional
    9     9 Architecture: all
   10    10 Depends: libsndfile1, libsdl1.2debian, libwxbase2.8-0 | libwxbase2.8-0
   -1    11 Description: Tool to fit recordet Audio to a tempo
   -1    12  This is basicly some kind of gui to rubberband, where some other modes than rubberband itself are available.
   -1    13  .
   -1    14  dependencies:
   -1    15  .
   -1    16  playback - sdl
   -1    17  gui - wxwidgets
   -1    18  timestretch - rubberband (optional)
   11    19 
   12    20 <</CTRL>>
   13    21 <<FILES>>