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 * |
31 |
#include "Filter.h" |
#include "Filter.h" |
32 |
#include "Voice.h" |
#include "Voice.h" |
33 |
|
|
34 |
#define SYNTHESIS_MODE_SET_CONSTPITCH(iMode,bVal) if (bVal) iMode |= 0x01; else iMode &= 0xfe /* (un)set mode bit 0 */ |
#define SYNTHESIS_MODE_SET_CONSTPITCH(iMode,bVal) if (bVal) iMode |= 0x01; else iMode &= ~0x01 /* (un)set mode bit 0 */ |
35 |
#define SYNTHESIS_MODE_SET_LOOP(iMode,bVal) if (bVal) iMode |= 0x02; else iMode &= 0xfd /* (un)set mode bit 1 */ |
#define SYNTHESIS_MODE_SET_LOOP(iMode,bVal) if (bVal) iMode |= 0x02; else iMode &= ~0x02 /* (un)set mode bit 1 */ |
36 |
#define SYNTHESIS_MODE_SET_INTERPOLATE(iMode,bVal) if (bVal) iMode |= 0x04; else iMode &= 0xfb /* (un)set mode bit 2 */ |
#define SYNTHESIS_MODE_SET_INTERPOLATE(iMode,bVal) if (bVal) iMode |= 0x04; else iMode &= ~0x04 /* (un)set mode bit 2 */ |
37 |
#define SYNTHESIS_MODE_SET_FILTER(iMode,bVal) if (bVal) iMode |= 0x08; else iMode &= 0xf7 /* (un)set mode bit 3 */ |
#define SYNTHESIS_MODE_SET_FILTER(iMode,bVal) if (bVal) iMode |= 0x08; else iMode &= ~0x08 /* (un)set mode bit 3 */ |
38 |
#define SYNTHESIS_MODE_SET_CHANNELS(iMode,bVal) if (bVal) iMode |= 0x10; else iMode &= 0xef /* (un)set mode bit 4 */ |
#define SYNTHESIS_MODE_SET_CHANNELS(iMode,bVal) if (bVal) iMode |= 0x10; else iMode &= ~0x10 /* (un)set mode bit 4 */ |
39 |
#define SYNTHESIS_MODE_SET_IMPLEMENTATION(iMode,bVal) if (bVal) iMode |= 0x20; else iMode &= 0xdf /* (un)set mode bit 5 */ |
#define SYNTHESIS_MODE_SET_IMPLEMENTATION(iMode,bVal) if (bVal) iMode |= 0x20; else iMode &= ~0x20 /* (un)set mode bit 5 */ |
40 |
#define SYNTHESIS_MODE_SET_PROFILING(iMode,bVal) if (bVal) iMode |= 0x40; else iMode &= ~0x40 /* (un)set mode bit 6 */ |
#define SYNTHESIS_MODE_SET_PROFILING(iMode,bVal) if (bVal) iMode |= 0x40; else iMode &= ~0x40 /* (un)set mode bit 6 */ |
41 |
|
|
42 |
#define SYNTHESIS_MODE_GET_CONSTPITCH(iMode) iMode & 0x01 |
#define SYNTHESIS_MODE_GET_CONSTPITCH(iMode) iMode & 0x01 |
70 |
public: |
public: |
71 |
template<typename VOICE_T> |
template<typename VOICE_T> |
72 |
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) { |
73 |
|
const float panLeft = Mul(Voice.PanLeft, Voice.pEngineChannel->GlobalPanLeft); |
74 |
|
const float panRight = Mul(Voice.PanRight, Voice.pEngineChannel->GlobalPanRight); |
75 |
if (IMPLEMENTATION == ASM_X86_MMX_SSE) { |
if (IMPLEMENTATION == ASM_X86_MMX_SSE) { |
76 |
float fPos = (float) Voice.Pos; |
float fPos = (float) Voice.Pos; |
77 |
SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount, |
SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount, |
81 |
Voice.LoopCyclesLeft, |
Voice.LoopCyclesLeft, |
82 |
(void *)&fPos, |
(void *)&fPos, |
83 |
Voice.PitchBase, |
Voice.PitchBase, |
84 |
Voice.PitchBend); |
Voice.PitchBend, |
85 |
|
&panLeft, &panRight); |
86 |
|
#if ARCH_X86 |
87 |
if (INTERPOLATE) EMMS; |
if (INTERPOLATE) EMMS; |
88 |
|
#endif |
89 |
Voice.Pos = (double) fPos; |
Voice.Pos = (double) fPos; |
90 |
} else { |
} else { |
91 |
SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount, |
SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount, |
95 |
Voice.LoopCyclesLeft, |
Voice.LoopCyclesLeft, |
96 |
(void *)&Voice.Pos, |
(void *)&Voice.Pos, |
97 |
Voice.PitchBase, |
Voice.PitchBase, |
98 |
Voice.PitchBend); |
Voice.PitchBend, |
99 |
|
&panLeft, &panRight); |
100 |
} |
} |
101 |
} |
} |
102 |
|
|
103 |
//protected: |
//protected: |
104 |
|
|
105 |
template<typename VOICE_T> |
template<typename VOICE_T> |
106 |
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) { |
107 |
const float loopEnd = Float(LoopEnd); |
const float loopEnd = Float(LoopEnd); |
108 |
const float PBbyPB = Mul(PitchBase, PitchBend); |
const float PBbyPB = Mul(PitchBase, PitchBend); |
109 |
const float f_LoopStart = Float(LoopStart); |
const float f_LoopStart = Float(LoopStart); |
114 |
while (i < Samples && LoopCyclesLeft) { |
while (i < Samples && LoopCyclesLeft) { |
115 |
if (CONSTPITCH) { |
if (CONSTPITCH) { |
116 |
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 |
117 |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i); |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
118 |
} |
} |
119 |
else Synthesize(Voice, Pos, pSrc, i); |
else Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
120 |
if (WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos)) LoopCyclesLeft--; |
if (WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos)) LoopCyclesLeft--; |
121 |
} |
} |
122 |
// render on without loop |
// render on without loop |
123 |
while (i < Samples) Synthesize(Voice, Pos, pSrc, i); |
while (i < Samples) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
124 |
} |
} |
125 |
else { // render loop (endless loop) |
else { // render loop (endless loop) |
126 |
while (i < Samples) { |
while (i < Samples) { |
127 |
if (CONSTPITCH) { |
if (CONSTPITCH) { |
128 |
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 |
129 |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i); |
while (i < processEnd) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
130 |
} |
} |
131 |
else Synthesize(Voice, Pos, pSrc, i); |
else Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight); |
132 |
WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos); |
WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos); |
133 |
} |
} |
134 |
} |
} |
135 |
} |
} |
136 |
else { // no looping |
else { // no looping |
137 |
while (i < Samples) { Synthesize(Voice, Pos, pSrc, i);} |
while (i < Samples) { Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);} |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
141 |
template<typename VOICE_T> |
template<typename VOICE_T> |
142 |
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) { |
143 |
Synthesize(pSrc, Pos, |
Synthesize(pSrc, Pos, |
144 |
Voice.pEngine->pSynthesisParameters[Event::destination_vco][i], |
Voice.pEngine->pSynthesisParameters[Event::destination_vco][i], |
145 |
Voice.pEngine->pOutputLeft, |
Voice.pEngineChannel->pOutputLeft, |
146 |
Voice.pEngine->pOutputRight, |
Voice.pEngineChannel->pOutputRight, |
147 |
i, |
i, |
148 |
Voice.pEngine->pSynthesisParameters[Event::destination_vca], |
Voice.pEngine->pSynthesisParameters[Event::destination_vca], |
149 |
&Voice.PanLeft, |
PanLeft, |
150 |
&Voice.PanRight, |
PanRight, |
151 |
Voice.FilterLeft, |
Voice.FilterLeft, |
152 |
Voice.FilterRight, |
Voice.FilterRight, |
153 |
Voice.pEngine->pBasicFilterParameters[i], |
Voice.pEngine->pBasicFilterParameters[i], |
190 |
} |
} |
191 |
#if ARCH_X86 |
#if ARCH_X86 |
192 |
case ASM_X86_MMX_SSE: { |
case ASM_X86_MMX_SSE: { |
193 |
int result; |
int result = 0; |
194 |
__asm__ __volatile__ ( |
__asm__ __volatile__ ( |
195 |
"movss (%2), %%xmm0 # load LoopEnd\n\t" |
"movss (%2), %%xmm0 # load LoopEnd\n\t" |
196 |
"movss (%1), %%xmm1 # load Pos\n\t" |
"movss (%1), %%xmm1 # load Pos\n\t" |
197 |
"comiss %%xmm0, %%xmm1 # LoopEnd <> Pos\n\t" |
"comiss %%xmm0, %%xmm1 # LoopEnd <> Pos\n\t" |
|
"movl $0,%%eax # result = 0\n\t" |
|
198 |
"jb 1f # jump if no work needs to be done\n\t" |
"jb 1f # jump if no work needs to be done\n\t" |
199 |
"movss (%3), %%xmm2 # load LoopSize\n\t" |
"movss (%3), %%xmm2 # load LoopSize\n\t" |
200 |
"subss %%xmm0, %%xmm1 # Pos - LoopEnd\n\t" |
"subss %%xmm0, %%xmm1 # Pos - LoopEnd\n\t" |
209 |
//done with fmodf |
//done with fmodf |
210 |
"addss %%xmm0, %%xmm3 # add LoopStart\n\t" |
"addss %%xmm0, %%xmm3 # add LoopStart\n\t" |
211 |
"movss %%xmm3, (%1) # update Pos\n\t" |
"movss %%xmm3, (%1) # update Pos\n\t" |
212 |
"movl $1,%%eax # result = 1\n\t" |
"movl $1, (%0) # result = 1\n\t" |
213 |
".balign 16 \n\t" |
".balign 16 \n\t" |
214 |
"1:\n\t" |
"1:\n\t" |
215 |
: "=a" (result) /* %0 */ |
:: "r" (&result), /* %0 */ |
216 |
: "r" (vPos), /* %1 */ |
"r" (vPos), /* %1 */ |
217 |
"r" (&LoopEnd), /* %2 */ |
"r" (&LoopEnd), /* %2 */ |
218 |
"r" (&LoopSize), /* %3 */ |
"r" (&LoopSize), /* %3 */ |
219 |
"r" (&LoopStart) /* %4 */ |
"r" (&LoopStart) /* %4 */ |
224 |
} |
} |
225 |
} |
} |
226 |
|
|
227 |
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) { |
228 |
switch (IMPLEMENTATION) { |
switch (IMPLEMENTATION) { |
229 |
// pure C++ implementation (thus platform independent) |
// pure C++ implementation (thus platform independent) |
230 |
case CPP: { |
case CPP: { |