1 // -*- mode: c++ -*- 2 #ifndef SMS_H 3 #define SMS_H 4 5 #include "config.h" 6 #ifdef MULTITHREADED 7 #include "pthread.h" 8 #endif 9 #include "sbsms.h" 10 #include "track.h" 11 #include "grain.h" 12 #include "buffer.h" 13 #include <queue> 14 #include <list> 15 using namespace std; 16 17 namespace _sbsms_ { 18 19 enum { 20 minTrial2Band = 1, 21 minTrial1Band = 2 22 }; 23 24 class SynthRenderer : public SBSMSRenderer, public SampleBufBase { 25 public: 26 SynthRenderer(int channels, int h); 27 ~SynthRenderer(); 28 void startTime(int c, const TimeType &time, int n); 29 void render(int c, SBSMSTrack *t); 30 void endTime(int c); 31 long read(audio *out, long n); 32 33 protected: 34 int channels; 35 float *synthBuf[2]; 36 int synthBufLength[2]; 37 ArrayRingBuffer<float> *sines[2]; 38 TimeType time[2]; 39 int n[2]; 40 #ifdef MULTITHREADED 41 pthread_mutex_t bufferMutex; 42 #endif 43 }; 44 45 class SMS { 46 public: 47 SMS(SMS *lo, int N, int band, int bandMax, int h, int res, int N0, int N1, int N2, int channels, audio *peak2); 48 ~SMS(); 49 void render(int c, list<SBSMSRenderer*> &renderers); 50 void add(grain *g0, grain *g1, grain *g2, int c); 51 void assignStart(long offset, int c); 52 void assignInit(long offset, int c); 53 void assignFind(long offset, int c); 54 bool assignConnect(long offset, int c, bool bLastDitch); 55 void start(long offset, int c); 56 void splitMerge(int c); 57 void mark(long offset, int c); 58 void advance(int c); 59 void trial2(int c); 60 void trial2Start(int c); 61 void trial2End(int c); 62 void adjust2(); 63 void trial1(int c); 64 void trial1Start(int c); 65 void trial1End(int c); 66 void adjust1(float stretch, float pitch0, float pitch1); 67 void adjustInit(ArrayRingBuffer<float> **trialRingBuf, 68 GrainBuf *trialGrainBuf); 69 void adjust(GrainBuf *trialGrainBuf, 70 queue<float*> *magQueue, 71 int minCutSep, 72 float **_mag1, 73 float **_dmag1, 74 audio **x1, 75 const TimeType &time, 76 Slice **slice); 77 void prepad1(audio *buf, long n); 78 void prepad0(audio *buf, long n); 79 int getTrial2Latency(); 80 81 protected: 82 void connect(TrackPoint *tp0, TrackPoint *tp1, int ilo, int c); 83 void mark(long offset, long offsetlo, int c); 84 TrackPoint *nearestForward(TrackPoint **begin, TrackPoint *tp0, float *minCost2, float maxCost2, float maxDF2, float dMCoeff2, float dNCoeff2 = 0.0f); 85 TrackPoint *nearestReverse(TrackPoint **begin, TrackPoint *tp0, float *minCost2, float maxCost2, float maxDF2, float dMCoeff2, float dNCoeff2 = 0.0f); 86 TrackPoint *nearestForward2(TrackPoint **begin, TrackPoint *tp0, float *minCost2, float maxCost2, float maxDF2, float dMCoeff2, float dNCoeff2 = 0.0f); 87 TrackPoint *nearestReverse2(TrackPoint **begin, TrackPoint *tp0, float *minCost2, float maxCost2, float maxDF2, float dMCoeff2, float dNCoeff2 = 0.0f); 88 float interp2(int k, int ko1, float kf); 89 float findExtremum(float *mag, float *mag2, int k, float *y); 90 void calcmags(float *mag, audio *x); 91 int findCut(float *dmag, int k, int maxK); 92 Track *createTrack(int c, TrackPoint *tp, const TimeType &time, bool bStitch); 93 void returnTrackIndex(int c, Track *t); 94 95 list<TrackPoint*> ended[2]; 96 list<TrackPoint*> started[2]; 97 int minTrackSize; 98 int peakWidth0; 99 int peakWidth1; 100 int peakWidth2; 101 int minCutSep1; 102 int minCutSep2; 103 int minK; 104 int maxK; 105 float peakThresh; 106 float maxCost2; 107 float maxDF; 108 float dMCoeff2; 109 float dNCoeff2; 110 float maxDFSplitMerge; 111 float maxCost2SplitMerge; 112 float dMCoeff2SplitMerge; 113 float maxCost2Match; 114 float maxDFMatch; 115 float dMCoeff2Match; 116 float maxCost2Stereo; 117 float maxDFStereo; 118 float dMCoeff2Stereo; 119 float maxFMatchM; 120 float minFMatchL; 121 float minFLo; 122 float maxFHi; 123 float minFMid; 124 float maxFMid; 125 int kStart; 126 int kEnd; 127 int kLo; 128 int kHi; 129 float mNorm; 130 float localFavorRatio; 131 queue<Slice*> adjust2SliceQueue[2]; 132 queue<Slice*> adjust1SliceQueue[2]; 133 RingBuffer<Slice*> sliceBuffer[2]; 134 Slice* sliceM0[2]; 135 Slice* sliceL0[2]; 136 Slice* sliceH0[2]; 137 Slice* sliceM1[2]; 138 Slice* sliceL1[2]; 139 Slice* sliceM2[2]; 140 Slice* sliceH1[2]; 141 audio* x10[2]; 142 audio* x11[2]; 143 float* dmag1[2]; 144 float* mag11[2]; 145 audio* x00[2]; 146 audio* x01[2]; 147 float* dmag0[2]; 148 float* mag01[2]; 149 float *mag2[2]; 150 audio* x2[2]; 151 float* dec2[2]; 152 float *peak20; 153 float *peak2N; 154 int N; 155 int Nover2; 156 SMS *lo; 157 SMS *hi; 158 queue<TrackIndexType> trackIndex[2]; 159 queue<float*> mag1Queue[2]; 160 queue<float*> mag0Queue[2]; 161 float *trial2Buf[2]; 162 ArrayRingBuffer<float> *trial2RingBuf[2]; 163 GrainBuf *trial2GrainBuf; 164 float *trial1Buf[2]; 165 ArrayRingBuffer<float> *trial1RingBuf[2]; 166 GrainBuf *trial1GrainBuf; 167 list<Track*> assignTracks[2]; 168 list<Track*> renderTracks[2]; 169 TimeType addtime[2]; 170 TimeType assigntime[2]; 171 TimeType trial2time[2]; 172 TimeType adjust2time; 173 TimeType trial1time[2]; 174 TimeType adjust1time; 175 TimeType synthtime[2]; 176 queue<int> nRender[2]; 177 double h2cum; 178 int channels; 179 long res; 180 long resMask; 181 int h; 182 float M; 183 double h1; 184 int band; 185 #ifdef MULTITHREADED 186 pthread_mutex_t sliceMutex[2]; 187 pthread_mutex_t magMutex[2]; 188 pthread_mutex_t renderMutex[2]; 189 pthread_mutex_t trial2Mutex[2]; 190 pthread_mutex_t trial1Mutex[2]; 191 pthread_mutex_t trackMutex[2]; 192 #endif 193 bool bAssignDone[2]; 194 }; 195 196 } 197 198 #endif 199