- commit
- 604f600b74ed49bd1d5774eadba9c26d248085d1
- parent
- 8f7f438335d24d8025431e777e5a3ba111ab896e
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2010-11-04 17:59
merge lin
Diffstat
| A | src/rbprocess.h | 71 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/rbprocess.h b/src/rbprocess.h
@@ -0,0 +1,71 @@
-1 1 #ifndef __XIRBPROCESS_H
-1 2 #define __XIRBPROCESS_H
-1 3
-1 4 #include "marker.h"
-1 5 #include <rubberband/RubberBandStretcher.h>
-1 6
-1 7 /*
-1 8 this is called by sample.process()
-1 9 this uses the rubberband library
-1 10 */
-1 11
-1 12 void RBprocess(float* odata, int olength, float* data, int length, Marker* marker) {
-1 13 // TODO better Quality by loading more into the buffer than needed
-1 14
-1 15 const int bufferLength=4096; // important
-1 16 float **ibuf = new float *[1];
-1 17 ibuf[0]=new float[bufferLength];
-1 18 float **obuf = new float *[1];
-1 19 int avail2=0; // position in data
-1 20
-1 21 for (int i=0; i<olength; i+=bufferLength) {
-1 22 float ratio=marker->getRatio(i/(float)olength);
-1 23
-1 24
-1 25 // load odata to ibuf
-1 26 for (int j=0; j<bufferLength; ++j) {
-1 27 if (i+j<olength)
-1 28 ibuf[0][j]=odata[i+j];
-1 29 else
-1 30 ibuf[0][j]=0;
-1 31 }
-1 32
-1 33 // process ibuf
-1 34 RubberBand::RubberBandStretcher ts(44100, 1, 0, ratio);
-1 35 ts.setMaxProcessSize(bufferLength*10);
-1 36 ts.study(ibuf, bufferLength, true);
-1 37 int a1=-1;
-1 38 int a2=0;
-1 39 while (a1!=a2) {
-1 40 ts.process(ibuf, ts.getSamplesRequired(), false);
-1 41 a1=a2;
-1 42 a2=ts.available();
-1 43 }
-1 44 ts.process(ibuf, bufferLength, true);
-1 45 int avail=ts.available();
-1 46 obuf[0]=new float[avail];
-1 47 ts.retrieve(obuf, avail);
-1 48
-1 49 // write obuf to data
-1 50 for (int j=0; j<avail && j+avail2<length; ++j) {
-1 51 float value = obuf[0][j];
-1 52 if (value > 1.f) value = 1.f;
-1 53 if (value < -1.f) value = -1.f;
-1 54 data[avail2+j] = value;
-1 55 }
-1 56 avail2+=avail;
-1 57
-1 58 delete[] obuf[0];
-1 59 }
-1 60 for (int i=avail2; i<length; ++i) {
-1 61 data[i]=0;
-1 62 }
-1 63
-1 64 delete[] ibuf[0];
-1 65 delete[] ibuf;
-1 66 delete[] obuf;
-1 67
-1 68 }
-1 69
-1 70 #endif
-1 71