3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
|
* Copyright (C) 2005 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
67 |
|
|
68 |
template<implementation_t IMPLEMENTATION, channels_t CHANNELS, bool USEFILTER, bool INTERPOLATE, bool DOLOOP, bool CONSTPITCH> |
template<implementation_t IMPLEMENTATION, channels_t CHANNELS, bool USEFILTER, bool INTERPOLATE, bool DOLOOP, bool CONSTPITCH> |
69 |
class Synthesizer : public __RTMath<IMPLEMENTATION>, public LinuxSampler::Resampler<INTERPOLATE> { |
class Synthesizer : public __RTMath<IMPLEMENTATION>, public LinuxSampler::Resampler<INTERPOLATE> { |
70 |
|
|
71 |
|
// declarations of derived functions (see "Name lookup, |
72 |
|
// templates, and accessing members of base classes" in |
73 |
|
// the gcc manual for an explanation of why this is |
74 |
|
// needed). |
75 |
|
using __RTMath<IMPLEMENTATION>::Mul; |
76 |
|
using __RTMath<IMPLEMENTATION>::Float; |
77 |
|
using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleMonoCPP; |
78 |
|
using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleStereoCPP; |
79 |
|
#if ARCH_X86 |
80 |
|
using LinuxSampler::Resampler<INTERPOLATE>::GetNext4SamplesMonoMMXSSE; |
81 |
|
using LinuxSampler::Resampler<INTERPOLATE>::GetNext4SamplesStereoMMXSSE; |
82 |
|
#endif |
83 |
|
|
84 |
public: |
public: |
85 |
template<typename VOICE_T> |
template<typename VOICE_T> |
86 |
inline static void SynthesizeFragment(VOICE_T& Voice, uint Samples, sample_t* pSrc, uint i) { |
inline static void SynthesizeFragment(VOICE_T& Voice, uint Samples, sample_t* pSrc, uint i) { |
87 |
|
const float panLeft = Mul(Voice.PanLeft, Voice.pEngineChannel->GlobalPanLeft); |
88 |
|
const float panRight = Mul(Voice.PanRight, Voice.pEngineChannel->GlobalPanRight); |
89 |
if (IMPLEMENTATION == ASM_X86_MMX_SSE) { |
if (IMPLEMENTATION == ASM_X86_MMX_SSE) { |
90 |
float fPos = (float) Voice.Pos; |
float fPos = (float) Voice.Pos; |
91 |
SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount, |
SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount, |
95 |
Voice.LoopCyclesLeft, |
Voice.LoopCyclesLeft, |
96 |
(void *)&fPos, |
(void *)&fPos, |
97 |
Voice.PitchBase, |
Voice.PitchBase, |
98 |
Voice.PitchBend); |
Voice.PitchBend, |
99 |
|
&panLeft, &panRight); |
100 |
#if ARCH_X86 |
#if ARCH_X86 |
101 |
if (INTERPOLATE) EMMS; |
if (INTERPOLATE) EMMS; |
102 |
#endif |
#endif |
109 |
Voice.LoopCyclesLeft, |
Voice.LoopCyclesLeft, |
110 |
(void *)&Voice.Pos, |
(void *)&Voice.Pos, |
111 |
Voice.PitchBase, |
Voice.PitchBase, |
112 |
Voice.PitchBend); |
Voice.PitchBend, |
113 |
|
&panLeft, &panRight); |
114 |
} |
} |
115 |
} |
} |
116 |
|
|
117 |
//protected: |
//protected: |
118 |
|
|
119 |
template<typename VOICE_T> |
template<typename VOICE_T> |
120 |
inline static void SynthesizeFragment(VOICE_T& Voice, uint Samples, sample_t* pSrc, uint& i, uint& LoopPlayCount, uint LoopStart, uint LoopEnd, uint LoopSize, uint& LoopCyclesLeft, void* Pos, float& PitchBase, float& PitchBend) { |
inline static void SynthesizeFragment(VOICE_T& Voice, uint Samples, sample_t* pSrc, uint& i, uint& LoopPlayCount, uint LoopStart, uint LoopEnd, uint LoopSize, uint& LoopCyclesLeft, void* Pos, float& PitchBase, float& PitchBend, const float* PanLeft, const float* PanRight) { |
121 |
const float loopEnd = Float(LoopEnd); |
const float loopEnd = Float(LoopEnd); |
122 |
const float PBbyPB = Mul(PitchBase, PitchBend); |
const float PBbyPB = Mul(PitchBase, PitchBend); |
123 |
const float f_LoopStart = Float(LoopStart); |
const float f_LoopStart = Float(LoopStart); |
128 |
while (i < Samples && LoopCyclesLeft) { |
while (i < Samples && LoopCyclesLeft) { |
129 |
if (CONSTPITCH) { |
if (CONSTPITCH) { |
130 |
const uint processEnd = Min(Samples, i + DiffToLoopEnd(loopEnd,Pos, PBbyPB) + 1); //TODO: instead of +1 we could also round up |
const uint processEnd = Min(Samples, i + DiffToLoopEnd(loopEnd,Pos, PBbyPB) + 1); //TODO: instead of +1 we could also round up |
131 |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i); |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
132 |
} |
} |
133 |
else Synthesize(Voice, Pos, pSrc, i); |
else Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
134 |
if (WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos)) LoopCyclesLeft--; |
if (WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos)) LoopCyclesLeft--; |
135 |
} |
} |
136 |
// render on without loop |
// render on without loop |
137 |
while (i < Samples) Synthesize(Voice, Pos, pSrc, i); |
while (i < Samples) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
138 |
} |
} |
139 |
else { // render loop (endless loop) |
else { // render loop (endless loop) |
140 |
while (i < Samples) { |
while (i < Samples) { |
141 |
if (CONSTPITCH) { |
if (CONSTPITCH) { |
142 |
const uint processEnd = Min(Samples, i + DiffToLoopEnd(loopEnd, Pos, PBbyPB) + 1); //TODO: instead of +1 we could also round up |
const uint processEnd = Min(Samples, i + DiffToLoopEnd(loopEnd, Pos, PBbyPB) + 1); //TODO: instead of +1 we could also round up |
143 |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i); |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
144 |
} |
} |
145 |
else Synthesize(Voice, Pos, pSrc, i); |
else Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
146 |
WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos); |
WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos); |
147 |
} |
} |
148 |
} |
} |
149 |
} |
} |
150 |
else { // no looping |
else { // no looping |
151 |
while (i < Samples) { Synthesize(Voice, Pos, pSrc, i);} |
while (i < Samples) { Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);} |
152 |
} |
} |
153 |
} |
} |
154 |
|
|
155 |
template<typename VOICE_T> |
template<typename VOICE_T> |
156 |
inline static void Synthesize(VOICE_T& Voice, void* Pos, sample_t* pSrc, uint& i) { |
inline static void Synthesize(VOICE_T& Voice, void* Pos, sample_t* pSrc, uint& i, const float* PanLeft, const float* PanRight) { |
157 |
Synthesize(pSrc, Pos, |
Synthesize(pSrc, Pos, |
158 |
Voice.pEngine->pSynthesisParameters[Event::destination_vco][i], |
Voice.pEngine->pSynthesisParameters[Event::destination_vco][i], |
159 |
Voice.pEngine->pOutputLeft, |
Voice.pEngineChannel->pOutputLeft, |
160 |
Voice.pEngine->pOutputRight, |
Voice.pEngineChannel->pOutputRight, |
161 |
i, |
i, |
162 |
Voice.pEngine->pSynthesisParameters[Event::destination_vca], |
Voice.pEngine->pSynthesisParameters[Event::destination_vca], |
163 |
&Voice.PanLeft, |
PanLeft, |
164 |
&Voice.PanRight, |
PanRight, |
165 |
Voice.FilterLeft, |
Voice.FilterLeft, |
166 |
Voice.FilterRight, |
Voice.FilterRight, |
167 |
Voice.pEngine->pBasicFilterParameters[i], |
Voice.pEngine->pBasicFilterParameters[i], |
238 |
} |
} |
239 |
} |
} |
240 |
|
|
241 |
inline static void Synthesize(sample_t* pSrc, void* Pos, float& Pitch, float* pOutL, float* pOutR, uint& i, float* Volume, float* PanL, float* PanR, Filter& FilterL, Filter& FilterR, biquad_param_t& bqBase, biquad_param_t& bqMain) { |
inline static void Synthesize(sample_t* pSrc, void* Pos, float& Pitch, float* pOutL, float* pOutR, uint& i, float* Volume, const float* PanL, const float* PanR, Filter& FilterL, Filter& FilterR, biquad_param_t& bqBase, biquad_param_t& bqMain) { |
242 |
switch (IMPLEMENTATION) { |
switch (IMPLEMENTATION) { |
243 |
// pure C++ implementation (thus platform independent) |
// pure C++ implementation (thus platform independent) |
244 |
case CPP: { |
case CPP: { |