25 |
float** ModulationSystem::pDestinationParameter = NULL; |
float** ModulationSystem::pDestinationParameter = NULL; |
26 |
uint ModulationSystem::uiSampleRate; |
uint ModulationSystem::uiSampleRate; |
27 |
uint ModulationSystem::uiMaxSamplesPerCycle; |
uint ModulationSystem::uiMaxSamplesPerCycle; |
28 |
|
ModulationSystem::__FragmentTime__ ModulationSystem::FragmentTime; |
29 |
|
|
30 |
void ModulationSystem::Initialize(uint SampleRate, uint MaxSamplesPerCycle) { |
void ModulationSystem::Initialize(uint SampleRate, uint MaxSamplesPerCycle) { |
31 |
ModulationSystem::uiMaxSamplesPerCycle = MaxSamplesPerCycle; |
ModulationSystem::uiMaxSamplesPerCycle = MaxSamplesPerCycle; |
37 |
pDestinationParameter[i] = pDestinationParameter[i - 1] + MaxSamplesPerCycle; |
pDestinationParameter[i] = pDestinationParameter[i - 1] + MaxSamplesPerCycle; |
38 |
} |
} |
39 |
} |
} |
40 |
|
ModulationSystem::FragmentTime.end = ModulationSystem::CreateTimeStamp(); |
41 |
} |
} |
42 |
|
|
43 |
void ModulationSystem::Close() { |
void ModulationSystem::Close() { |
54 |
void ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_t dst, float val) { |
void ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_t dst, float val) { |
55 |
for (int i = 0; i < uiMaxSamplesPerCycle; i++) pDestinationParameter[dst][i] = val; |
for (int i = 0; i < uiMaxSamplesPerCycle; i++) pDestinationParameter[dst][i] = val; |
56 |
} |
} |
57 |
|
|
58 |
|
/** |
59 |
|
* Updates the time stamps for the beginning and end of the current audio |
60 |
|
* fragment. This is needed to be able to calculate the respective sample |
61 |
|
* point later for which an event belongs to. |
62 |
|
*/ |
63 |
|
void ModulationSystem::UpdateFragmentTime() { |
64 |
|
// update time stamp for this audio fragment cycle |
65 |
|
ModulationSystem::FragmentTime.begin = ModulationSystem::FragmentTime.end; |
66 |
|
ModulationSystem::FragmentTime.end = ModulationSystem::CreateTimeStamp(); |
67 |
|
|
68 |
|
// recalculate sample ratio for this audio fragment |
69 |
|
real_time_t fragmentDuration = ModulationSystem::FragmentTime.end - ModulationSystem::FragmentTime.begin; |
70 |
|
ModulationSystem::FragmentTime.sample_ratio = (float) ModulationSystem::uiMaxSamplesPerCycle / (float) fragmentDuration; |
71 |
|
} |
72 |
|
|
73 |
|
/** |
74 |
|
* Creates a real time stamp for the current moment. Out of efficiency this |
75 |
|
* is implemented in inline assembly for each CPU independently; we currently |
76 |
|
* don't use a generic solution for CPUs that are not yet covered by the |
77 |
|
* assembly code, instead an error message is prompted on compile time, forcing |
78 |
|
* the user to contact us. |
79 |
|
*/ |
80 |
|
ModulationSystem::real_time_t ModulationSystem::CreateTimeStamp() { |
81 |
|
#if defined(__i386__) || defined(__x86_64__) |
82 |
|
uint64_t t; |
83 |
|
__asm__ __volatile__ ("rdtsc" : "=A" (t)); |
84 |
|
return t >> 8; |
85 |
|
#elif defined(__ia64__) |
86 |
|
real_time_t t; |
87 |
|
__asm__ __volatile__ ("mov %0=ar.itc" : "=r"(t)); |
88 |
|
return t; |
89 |
|
#elif defined(__powerpc__) |
90 |
|
real_time_t t; |
91 |
|
__asm__ __volatile__ ( |
92 |
|
"98: mftb %0\n" |
93 |
|
"99:\n" |
94 |
|
".section __ftr_fixup,\"a\"\n" |
95 |
|
" .long %1\n" |
96 |
|
" .long 0\n" |
97 |
|
" .long 98b\n" |
98 |
|
" .long 99b\n" |
99 |
|
".previous" |
100 |
|
: "=r" (t) : "i" (0x00000100) |
101 |
|
); |
102 |
|
return t; |
103 |
|
#elif defined(__alpha__) |
104 |
|
real_time_t t; |
105 |
|
__asm__ __volatile__ ("rpcc %0" : "=r"(t)); |
106 |
|
return t; |
107 |
|
#else // we don't want to use a slow generic solution |
108 |
|
# error Sorry, LinuxSampler lacks time stamp code for your system. |
109 |
|
# error Please report this error and the CPU you are using to the LinuxSampler developers mailing list! |
110 |
|
#endif |
111 |
|
} |