- commit
- 68c8aa6ae4e544e81c2d53160a382f5731571b26
- parent
- ad26cf9ba6d26e3557767efd7436044e0210f436
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2010-10-30 16:19
file in out
Diffstat
| M | rb_expermients/fio.h | 74 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- |
| M | rb_expermients/rtlayer.cpp | 8 | -------- |
| M | rb_expermients/rtlayer.h | 1 | - |
| M | src/marker.cpp | 19 | +++++++++++++++++++ |
| M | src/marker.h | 3 | +++ |
5 files changed, 94 insertions, 11 deletions
diff --git a/rb_expermients/fio.h b/rb_expermients/fio.h
@@ -1,10 +1,80 @@ 1 1 #ifndef __XIFIO_H 2 2 #define __XIFIO_H 3 34 -1 #include <sndfile>-1 4 #include <sndfile.h> -1 5 #include <iostream> -1 6 #include "../src/marker.h" -1 7 -1 8 using namespace std; -1 9 -1 10 class fio{ -1 11 -1 12 }; 5 13 6 14 int main() {7 -1-1 15 // create marker -1 16 Marker marker; -1 17 marker.add(0,0); -1 18 marker.add(1,1); -1 19 -1 20 // load files -1 21 -1 22 const char *fileName="test.wav"; -1 23 const char *fileNameOut="testo.wav"; -1 24 -1 25 SNDFILE *sndfile; -1 26 SNDFILE *sndfileOut; -1 27 SF_INFO sfinfo; -1 28 SF_INFO sfinfoOut; -1 29 -1 30 sndfile = sf_open(fileName, SFM_READ, &sfinfo); -1 31 if (!sndfile) { -1 32 cerr << "ERROR: Failed to open input file \"" << fileName << "\": " -1 33 << sf_strerror(sndfile) << endl; -1 34 return 1; -1 35 } -1 36 -1 37 // int outFrames=int(marker.getRatio()*sfinfo.frames); -1 38 sfinfoOut.channels = sfinfo.channels; -1 39 sfinfoOut.format = sfinfo.format; -1 40 // sfinfoOut.frames = outFrames; -1 41 sfinfoOut.samplerate = sfinfo.samplerate; -1 42 sfinfoOut.sections = sfinfo.sections; -1 43 sfinfoOut.seekable = sfinfo.seekable; -1 44 -1 45 sndfileOut = sf_open(fileNameOut, SFM_WRITE, &sfinfoOut) ; -1 46 if (!sndfileOut) { -1 47 cerr << "ERROR: Failed to open output file \"" << fileNameOut << "\" for writing: " -1 48 << sf_strerror(sndfileOut) << endl; -1 49 return 1; -1 50 } -1 51 -1 52 const int bufferLength=441000; -1 53 float ptr[bufferLength]; -1 54 -1 55 // cut -1 56 for (int i=0; i<marker.length()-1; ++i) { -1 57 int frames=int((marker.getOld(i+1)-marker.getOld(i))*sfinfo.frames*sfinfo.channels); // number of frames to read -1 58 int count = 0; -1 59 int count2 = 0; -1 60 int frames2=-1; -1 61 while (count2<frames) { -1 62 if (frames-count2 < bufferLength) -1 63 frames2=frames-count2; -1 64 else -1 65 frames2=bufferLength; -1 66 count = sf_read_float(sndfile, ptr, frames2); -1 67 count2 += count; -1 68 // time stretch here -1 69 // sf_write_float(sndfileOut, ptr, int(count*ratio)); -1 70 sf_write_float(sndfileOut, ptr, count*1); -1 71 } -1 72 -1 73 } -1 74 -1 75 sf_close(sndfile); -1 76 sf_close(sndfileOut); -1 77 8 78 } 9 79 10 80 #endif
diff --git a/rb_expermients/rtlayer.cpp b/rb_expermients/rtlayer.cpp
@@ -6,11 +6,3 @@ RTlayer::RTlayer() {
6 6
7 7 RTlayer::~RTlayer() {
8 8 }
9 -1
10 -1 float RTlayer::getRatio(int i) {
11 -1 if (i>=0 && i<marker.length()-1)
12 -1 return (marker.getNew(i+1)-marker.getNew(i))/(marker.getOld(i+1)-marker.getOld(i));
13 -1 else
14 -1 return NULL;
15 -1 }
16 -1
diff --git a/rb_expermients/rtlayer.h b/rb_expermients/rtlayer.h
@@ -10,7 +10,6 @@ class RTlayer {
10 10 public:
11 11 RTlayer();
12 12 ~RTlayer();
13 -1 float getRatio(int i);
14 13 Marker marker;
15 14 };
16 15
diff --git a/src/marker.cpp b/src/marker.cpp
@@ -30,10 +30,29 @@ void Marker::setNew(int pi, float pnew) {
30 30 anew.set(resort(pi), pnew);
31 31 }
32 32
-1 33 float Marker::getRatio() {
-1 34 if (length()>0)
-1 35 return (getNew(length()-1)-getNew(0))/(getOld(length()-1)-getOld(0));
-1 36 else
-1 37 return NULL;
-1 38 }
-1 39
-1 40 float Marker::getRatio(int i) {
-1 41 if (i>=0 && i<length()-1)
-1 42 return (getNew(i+1)-getNew(i))/(getOld(i+1)-getOld(i));
-1 43 else
-1 44 return NULL;
-1 45 }
-1 46
33 47 int Marker::length() {
34 48 return anew.length();
35 49 }
36 50
-1 51 void Marker::println() {
-1 52 aold.println();
-1 53 anew.println();
-1 54 }
-1 55
37 56 int Marker::resort(int pi) {
38 57 if (!(pi>=0 && pi<length())) return -1;
39 58 // write anew and indices into arrays
diff --git a/src/marker.h b/src/marker.h
@@ -13,7 +13,10 @@ public: 13 13 float getNew(int pi); 14 14 float getOld(int pi); 15 15 void setNew(int pi, float pnew); -1 16 float getRatio(); -1 17 float getRatio(int i); 16 18 int length(); -1 19 void println(); 17 20 private: 18 21 Buffer anew; 19 22 Buffer aold;