1 // -*- mode: c++ -*- 2 #ifndef SBSMS_INCLUDE 3 #define SBSMS_INCLUDE 4 5 #include <stdio.h> 6 7 namespace _sbsms_ { 8 9 typedef float t_fft[2]; 10 typedef t_fft audio; 11 typedef long long int SampleCountType; 12 typedef long long int TimeType; 13 typedef unsigned char TrackIndexType; 14 15 enum { 16 maxBands = 10, 17 numQualityParams = 52 18 }; 19 20 struct SBSMSQualityParams { 21 int bands; 22 int H; 23 int N[maxBands]; 24 int N0[maxBands]; 25 int N1[maxBands]; 26 int N2[maxBands]; 27 int res[maxBands]; 28 }; 29 30 class SBSMSQuality { 31 public: 32 SBSMSQuality(const SBSMSQualityParams *params); 33 SBSMSQualityParams params; 34 long getFrameSize(); 35 long getMaxPresamples(); 36 }; 37 38 extern const SBSMSQualityParams SBSMSQualityStandard; 39 40 struct SBSMSFrame { 41 float ratio0; 42 float ratio1; 43 audio *buf; 44 long size; 45 }; 46 47 typedef long (*SBSMSResampleCB)(void *cbData, SBSMSFrame *frame); 48 49 class SBSMSInterface /* not final */ { 50 public: ~SBSMSInterface()51 virtual ~SBSMSInterface() {} samples(audio * buf,long n)52 virtual long samples(audio *buf, long n) { return 0; } 53 virtual float getStretch(float t)=0; 54 virtual float getMeanStretch(float t0, float t1)=0; 55 virtual float getPitch(float t)=0; 56 virtual long getPresamples()=0; 57 virtual SampleCountType getSamplesToInput()=0; 58 virtual SampleCountType getSamplesToOutput()=0; 59 }; 60 61 class SBSMSTrackPoint { 62 public: ~SBSMSTrackPoint()63 virtual ~SBSMSTrackPoint() {} 64 virtual float getF()=0; 65 virtual float getM()=0; 66 virtual float getPhase()=0; 67 }; 68 69 class SBSMSTrack { 70 public: ~SBSMSTrack()71 virtual ~SBSMSTrack() {} 72 virtual SBSMSTrackPoint *getSBSMSTrackPoint(const TimeType &time)=0; 73 virtual TrackIndexType getIndex()=0; 74 virtual bool isFirst(const TimeType &synthtime)=0; 75 virtual bool isLast(const TimeType &synthtime)=0; 76 }; 77 78 class SBSMSRenderer { 79 public: ~SBSMSRenderer()80 virtual ~SBSMSRenderer() {} startFrame()81 virtual void startFrame() {} startTime(int c,const TimeType & time,int n)82 virtual void startTime(int c, const TimeType &time, int n) {} render(int c,SBSMSTrack * t)83 virtual void render(int c, SBSMSTrack *t) {} endTime(int c)84 virtual void endTime(int c) {} endFrame()85 virtual void endFrame() {} end(const SampleCountType & samples)86 virtual void end(const SampleCountType &samples) {} 87 }; 88 89 enum SBSMSError { 90 SBSMSErrorNone = 0, 91 SBSMSErrorInvalidRate 92 }; 93 94 class SBSMSImp; 95 96 class SBSMS { 97 public: 98 SBSMS(int channels, SBSMSQuality *quality, bool bSynthesize); 99 ~SBSMS(); 100 101 long read(SBSMSInterface *iface, audio *buf, long n); 102 void addRenderer(SBSMSRenderer *renderer); 103 void removeRenderer(SBSMSRenderer *renderer); 104 long renderFrame(SBSMSInterface *iface); 105 long getInputFrameSize(); 106 SBSMSError getError(); 107 friend class SBSMSImp; 108 protected: 109 SBSMSImp *imp; 110 }; 111 112 enum SlideType { 113 SlideIdentity = 0, 114 SlideConstant, 115 SlideLinearInputRate, 116 SlideLinearOutputRate, 117 SlideLinearInputStretch, 118 SlideLinearOutputStretch, 119 SlideGeometricInput, 120 SlideGeometricOutput 121 }; 122 123 class SlideImp; 124 125 class Slide { 126 public: 127 Slide(SlideType slideType, float rate0 = 1.0f, float rate1 = 1.0f, const SampleCountType &n = 0); 128 ~Slide(); 129 float getTotalStretch(); 130 float getStretchedTime(float t); 131 float getInverseStretchedTime(float t); 132 float getRate(float t); 133 float getStretch(float t); 134 float getMeanStretch(float t0, float t1); 135 float getRate(); 136 float getStretch(); 137 void step(); 138 protected: 139 SlideImp *imp; 140 }; 141 142 class SBSMSInterfaceSlidingImp; 143 144 class SBSMSInterfaceSliding /* not final */ : public SBSMSInterface { 145 public: 146 SBSMSInterfaceSliding(Slide *rateSlide, 147 Slide *pitchSlide, 148 bool bPitchReferenceInput, 149 const SampleCountType &samplesToInput, 150 long preSamples, 151 SBSMSQuality *quality); 152 virtual ~SBSMSInterfaceSliding(); 153 virtual float getStretch(float t); 154 virtual float getMeanStretch(float t0, float t1); 155 virtual float getPitch(float t); 156 virtual long getPresamples(); 157 virtual SampleCountType getSamplesToInput(); 158 virtual SampleCountType getSamplesToOutput(); 159 160 friend class SBSMSInterfaceSlidingImp; 161 protected: 162 SBSMSInterfaceSlidingImp *imp; 163 }; 164 165 class ResamplerImp; 166 167 class Resampler { 168 public: 169 Resampler(SBSMSResampleCB func, void *data, SlideType slideType = SlideConstant); 170 ~Resampler(); 171 long read(audio *audioOut, long frames); 172 void reset(); 173 long samplesInOutput(); 174 175 protected: 176 ResamplerImp *imp; 177 }; 178 179 } 180 181 #endif 182