33 |
EventGenerator::EventGenerator(uint SampleRate) { |
EventGenerator::EventGenerator(uint SampleRate) { |
34 |
uiSampleRate = SampleRate; |
uiSampleRate = SampleRate; |
35 |
uiSamplesProcessed = 0; |
uiSamplesProcessed = 0; |
36 |
FragmentTime.end = CreateTimeStamp(); |
FragmentTime.end = RTMath::CreateTimeStamp(); |
37 |
} |
} |
38 |
|
|
39 |
/** |
/** |
47 |
void EventGenerator::UpdateFragmentTime(uint SamplesToProcess) { |
void EventGenerator::UpdateFragmentTime(uint SamplesToProcess) { |
48 |
// update time stamp for this audio fragment cycle |
// update time stamp for this audio fragment cycle |
49 |
FragmentTime.begin = FragmentTime.end; |
FragmentTime.begin = FragmentTime.end; |
50 |
FragmentTime.end = CreateTimeStamp(); |
FragmentTime.end = RTMath::CreateTimeStamp(); |
51 |
// recalculate sample ratio for this audio fragment |
// recalculate sample ratio for this audio fragment |
52 |
time_stamp_t fragmentDuration = FragmentTime.end - FragmentTime.begin; |
time_stamp_t fragmentDuration = FragmentTime.end - FragmentTime.begin; |
53 |
FragmentTime.sample_ratio = (float) uiSamplesProcessed / (float) fragmentDuration; |
FragmentTime.sample_ratio = (float) uiSamplesProcessed / (float) fragmentDuration; |
59 |
* Create a new event with the current time as time stamp. |
* Create a new event with the current time as time stamp. |
60 |
*/ |
*/ |
61 |
Event EventGenerator::CreateEvent() { |
Event EventGenerator::CreateEvent() { |
62 |
return Event(this, CreateTimeStamp()); |
return Event(this, RTMath::CreateTimeStamp()); |
|
} |
|
|
|
|
|
/** |
|
|
* Creates a real time stamp for the current moment. Out of efficiency this |
|
|
* is implemented in inline assembly for each CPU independently; we currently |
|
|
* don't use a generic solution for CPUs that are not yet covered by the |
|
|
* assembly code, instead an error message is prompted on compile time, forcing |
|
|
* the user to contact us. |
|
|
*/ |
|
|
EventGenerator::time_stamp_t EventGenerator::CreateTimeStamp() { |
|
|
#if defined(__i386__) || defined(__x86_64__) |
|
|
uint64_t t; |
|
|
__asm__ __volatile__ ("rdtsc" : "=A" (t)); |
|
|
return t >> 8; |
|
|
#elif defined(__ia64__) |
|
|
time_stamp_t t; |
|
|
__asm__ __volatile__ ("mov %0=ar.itc" : "=r"(t)); |
|
|
return t; |
|
|
#elif defined(__powerpc__) |
|
|
time_stamp_t t; |
|
|
__asm__ __volatile__ ( |
|
|
"98: mftb %0\n" |
|
|
"99:\n" |
|
|
".section __ftr_fixup,\"a\"\n" |
|
|
" .long %1\n" |
|
|
" .long 0\n" |
|
|
" .long 98b\n" |
|
|
" .long 99b\n" |
|
|
".previous" |
|
|
: "=r" (t) : "i" (0x00000100) |
|
|
); |
|
|
return t; |
|
|
#elif defined(__alpha__) |
|
|
time_stamp_t t; |
|
|
__asm__ __volatile__ ("rpcc %0" : "=r"(t)); |
|
|
return t; |
|
|
#else // we don't want to use a slow generic solution |
|
|
# error "Sorry, LinuxSampler lacks time stamp code for your system." |
|
|
# error "Please report this error and the CPU you are using to the LinuxSampler developers mailing list!" |
|
|
#endif |
|
63 |
} |
} |
64 |
|
|
65 |
/** |
/** |