34 |
#define SYNTHESIS_MODE_SET_FILTER(iMode,bVal) if (bVal) iMode |= 0x02; else iMode &= ~0x02 /* (un)set mode bit 1 */ |
#define SYNTHESIS_MODE_SET_FILTER(iMode,bVal) if (bVal) iMode |= 0x02; else iMode &= ~0x02 /* (un)set mode bit 1 */ |
35 |
#define SYNTHESIS_MODE_SET_LOOP(iMode,bVal) if (bVal) iMode |= 0x04; else iMode &= ~0x04 /* (un)set mode bit 2 */ |
#define SYNTHESIS_MODE_SET_LOOP(iMode,bVal) if (bVal) iMode |= 0x04; else iMode &= ~0x04 /* (un)set mode bit 2 */ |
36 |
#define SYNTHESIS_MODE_SET_CHANNELS(iMode,bVal) if (bVal) iMode |= 0x08; else iMode &= ~0x08 /* (un)set mode bit 3 */ |
#define SYNTHESIS_MODE_SET_CHANNELS(iMode,bVal) if (bVal) iMode |= 0x08; else iMode &= ~0x08 /* (un)set mode bit 3 */ |
37 |
#define SYNTHESIS_MODE_SET_IMPLEMENTATION(iMode,bVal) if (bVal) iMode |= 0x10; else iMode &= ~0x10 /* (un)set mode bit 4 */ |
#define SYNTHESIS_MODE_SET_BITDEPTH24(iMode,bVal) if (bVal) iMode |= 0x10; else iMode &= ~0x10 /* (un)set mode bit 4 */ |
38 |
#define SYNTHESIS_MODE_SET_PROFILING(iMode,bVal) if (bVal) iMode |= 0x20; else iMode &= ~0x20 /* (un)set mode bit 5 */ |
#define SYNTHESIS_MODE_SET_IMPLEMENTATION(iMode,bVal) if (bVal) iMode |= 0x20; else iMode &= ~0x20 /* (un)set mode bit 5 */ |
39 |
|
#define SYNTHESIS_MODE_SET_PROFILING(iMode,bVal) if (bVal) iMode |= 0x40; else iMode &= ~0x40 /* (un)set mode bit 6 */ |
40 |
|
|
41 |
#define SYNTHESIS_MODE_GET_INTERPOLATE(iMode) iMode & 0x01 |
#define SYNTHESIS_MODE_GET_INTERPOLATE(iMode) iMode & 0x01 |
42 |
#define SYNTHESIS_MODE_GET_FILTER(iMode) iMode & 0x02 |
#define SYNTHESIS_MODE_GET_FILTER(iMode) iMode & 0x02 |
43 |
#define SYNTHESIS_MODE_GET_LOOP(iMode) iMode & 0x04 |
#define SYNTHESIS_MODE_GET_LOOP(iMode) iMode & 0x04 |
44 |
#define SYNTHESIS_MODE_GET_CHANNELS(iMode) iMode & 0x08 |
#define SYNTHESIS_MODE_GET_CHANNELS(iMode) iMode & 0x08 |
45 |
#define SYNTHESIS_MODE_GET_IMPLEMENTATION(iMode) iMode & 0x10 |
#define SYNTHESIS_MODE_GET_BITDEPTH24(iMode) iMode & 0x10 |
46 |
|
#define SYNTHESIS_MODE_GET_IMPLEMENTATION(iMode) iMode & 0x20 |
47 |
|
|
48 |
|
|
49 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
50 |
|
|
64 |
* format capable sampler engine. This means resampling / interpolation |
* format capable sampler engine. This means resampling / interpolation |
65 |
* for pitching the audio signal, looping, filter and amplification. |
* for pitching the audio signal, looping, filter and amplification. |
66 |
*/ |
*/ |
67 |
template<channels_t CHANNELS, bool DOLOOP, bool USEFILTER, bool INTERPOLATE> |
template<channels_t CHANNELS, bool DOLOOP, bool USEFILTER, bool INTERPOLATE, bool BITDEPTH24> |
68 |
class Synthesizer : public __RTMath<CPP>, public LinuxSampler::Resampler<INTERPOLATE> { |
class Synthesizer : public __RTMath<CPP>, public LinuxSampler::Resampler<INTERPOLATE,BITDEPTH24> { |
69 |
|
|
70 |
// declarations of derived functions (see "Name lookup, |
// declarations of derived functions (see "Name lookup, |
71 |
// templates, and accessing members of base classes" in |
// templates, and accessing members of base classes" in |
73 |
// needed). |
// needed). |
74 |
//using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleMonoCPP; |
//using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleMonoCPP; |
75 |
//using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleStereoCPP; |
//using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleStereoCPP; |
76 |
using LinuxSampler::Resampler<INTERPOLATE>::Interpolate1StepMonoCPP; |
using LinuxSampler::Resampler<INTERPOLATE,BITDEPTH24>::Interpolate1StepMonoCPP; |
77 |
using LinuxSampler::Resampler<INTERPOLATE>::Interpolate1StepStereoCPP; |
using LinuxSampler::Resampler<INTERPOLATE,BITDEPTH24>::Interpolate1StepStereoCPP; |
78 |
|
|
79 |
public: |
public: |
80 |
//protected: |
//protected: |
134 |
return 1; |
return 1; |
135 |
} |
} |
136 |
|
|
137 |
|
static int getSample(sample_t* src, int pos) { |
138 |
|
if (BITDEPTH24) { |
139 |
|
pos *= 3; |
140 |
|
unsigned char* p = (unsigned char*)src; |
141 |
|
return p[pos] << 8 | p[pos + 1] << 16 | p[pos + 2] << 24; |
142 |
|
} else { |
143 |
|
return src[pos]; |
144 |
|
} |
145 |
|
} |
146 |
|
|
147 |
static void SynthesizeSubSubFragment(SynthesisParam* pFinalParam, uint uiToGo) { |
static void SynthesizeSubSubFragment(SynthesisParam* pFinalParam, uint uiToGo) { |
148 |
float fVolumeL = pFinalParam->fFinalVolumeLeft; |
float fVolumeL = pFinalParam->fFinalVolumeLeft; |
149 |
float fVolumeR = pFinalParam->fFinalVolumeRight; |
float fVolumeR = pFinalParam->fFinalVolumeRight; |
189 |
if (USEFILTER) { |
if (USEFILTER) { |
190 |
Filter filterL = pFinalParam->filterLeft; |
Filter filterL = pFinalParam->filterLeft; |
191 |
for (int i = 0; i < uiToGo; ++i) { |
for (int i = 0; i < uiToGo; ++i) { |
192 |
samplePoint = pSrc[i + pos_offset]; |
samplePoint = getSample(pSrc, i + pos_offset); |
193 |
samplePoint = filterL.Apply(samplePoint); |
samplePoint = filterL.Apply(samplePoint); |
194 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
#ifdef CONFIG_INTERPOLATE_VOLUME |
195 |
fVolumeL += fDeltaL; |
fVolumeL += fDeltaL; |
200 |
} |
} |
201 |
} else { // no filter needed |
} else { // no filter needed |
202 |
for (int i = 0; i < uiToGo; ++i) { |
for (int i = 0; i < uiToGo; ++i) { |
203 |
samplePoint = pSrc[i + pos_offset]; |
samplePoint = getSample(pSrc, i + pos_offset); |
204 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
#ifdef CONFIG_INTERPOLATE_VOLUME |
205 |
fVolumeL += fDeltaL; |
fVolumeL += fDeltaL; |
206 |
fVolumeR += fDeltaR; |
fVolumeR += fDeltaR; |
250 |
Filter filterL = pFinalParam->filterLeft; |
Filter filterL = pFinalParam->filterLeft; |
251 |
Filter filterR = pFinalParam->filterRight; |
Filter filterR = pFinalParam->filterRight; |
252 |
for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) { |
for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) { |
253 |
samplePoint.left = pSrc[ii + pos_offset]; |
samplePoint.left = getSample(pSrc, ii + pos_offset); |
254 |
samplePoint.right = pSrc[ii + pos_offset + 1]; |
samplePoint.right = getSample(pSrc, ii + pos_offset + 1); |
255 |
samplePoint.left = filterL.Apply(samplePoint.left); |
samplePoint.left = filterL.Apply(samplePoint.left); |
256 |
samplePoint.right = filterR.Apply(samplePoint.right); |
samplePoint.right = filterR.Apply(samplePoint.right); |
257 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
#ifdef CONFIG_INTERPOLATE_VOLUME |
263 |
} |
} |
264 |
} else { // no filter needed |
} else { // no filter needed |
265 |
for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) { |
for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) { |
266 |
samplePoint.left = pSrc[ii + pos_offset]; |
samplePoint.left = getSample(pSrc, ii + pos_offset); |
267 |
samplePoint.right = pSrc[ii + pos_offset + 1]; |
samplePoint.right = getSample(pSrc, ii + pos_offset + 1); |
268 |
#ifdef CONFIG_INTERPOLATE_VOLUME |
#ifdef CONFIG_INTERPOLATE_VOLUME |
269 |
fVolumeL += fDeltaL; |
fVolumeL += fDeltaL; |
270 |
fVolumeR += fDeltaR; |
fVolumeR += fDeltaR; |