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, 2006 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 * |
34 |
EventGenerator::EventGenerator(uint SampleRate) { |
EventGenerator::EventGenerator(uint SampleRate) { |
35 |
uiSampleRate = SampleRate; |
uiSampleRate = SampleRate; |
36 |
uiSamplesProcessed = 0; |
uiSamplesProcessed = 0; |
37 |
FragmentTime.end = CreateTimeStamp(); |
FragmentTime.end = RTMath::CreateTimeStamp(); |
38 |
} |
} |
39 |
|
|
40 |
/** |
/** |
48 |
void EventGenerator::UpdateFragmentTime(uint SamplesToProcess) { |
void EventGenerator::UpdateFragmentTime(uint SamplesToProcess) { |
49 |
// update time stamp for this audio fragment cycle |
// update time stamp for this audio fragment cycle |
50 |
FragmentTime.begin = FragmentTime.end; |
FragmentTime.begin = FragmentTime.end; |
51 |
FragmentTime.end = CreateTimeStamp(); |
FragmentTime.end = RTMath::CreateTimeStamp(); |
52 |
// recalculate sample ratio for this audio fragment |
// recalculate sample ratio for this audio fragment |
53 |
time_stamp_t fragmentDuration = FragmentTime.end - FragmentTime.begin; |
time_stamp_t fragmentDuration = FragmentTime.end - FragmentTime.begin; |
54 |
FragmentTime.sample_ratio = (float) uiSamplesProcessed / (float) fragmentDuration; |
FragmentTime.sample_ratio = (float) uiSamplesProcessed / (float) fragmentDuration; |
60 |
* Create a new event with the current time as time stamp. |
* Create a new event with the current time as time stamp. |
61 |
*/ |
*/ |
62 |
Event EventGenerator::CreateEvent() { |
Event EventGenerator::CreateEvent() { |
63 |
return Event(this, CreateTimeStamp()); |
return Event(this, RTMath::CreateTimeStamp()); |
64 |
} |
} |
65 |
|
|
66 |
/** |
/** |
67 |
* Creates a real time stamp for the current moment. Out of efficiency this |
* Create a new event for the given sample point position in the current |
68 |
* is implemented in inline assembly for each CPU independently; we currently |
* audio fragment. |
69 |
* don't use a generic solution for CPUs that are not yet covered by the |
* |
70 |
* assembly code, instead an error message is prompted on compile time, forcing |
* @param FragmentPos - actual sample point position in the current |
71 |
* the user to contact us. |
* audio fragment to which the new event belongs to |
72 |
*/ |
*/ |
73 |
EventGenerator::time_stamp_t EventGenerator::CreateTimeStamp() { |
Event EventGenerator::CreateEvent(int32_t FragmentPos) { |
74 |
#if defined(__i386__) || defined(__x86_64__) |
return Event(this, FragmentPos); |
|
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 |
|
75 |
} |
} |
76 |
|
|
77 |
/** |
/** |
78 |
* Will be called by an EventGenerator to create a new Event. |
* Will be called by an EventGenerator to create a new Event. |
79 |
|
* This Constructor expects a time stamp. The actual sample point |
80 |
|
* position to which this event belongs to will be calculated later |
81 |
|
* when FragmentPos() was called the first time. |
82 |
|
* |
83 |
|
* @param pGenerator - creator of this event |
84 |
|
* @param Time - time stamp on which this event occured |
85 |
*/ |
*/ |
86 |
Event::Event(EventGenerator* pGenerator, time_stamp_t Time) { |
Event::Event(EventGenerator* pGenerator, time_stamp_t Time) { |
87 |
pEventGenerator = pGenerator; |
pEventGenerator = pGenerator; |
89 |
iFragmentPos = -1; |
iFragmentPos = -1; |
90 |
} |
} |
91 |
|
|
92 |
|
/** |
93 |
|
* Will be called by an EventGenerator to create a new Event. |
94 |
|
* This constructor expects the final sample point position to which |
95 |
|
* this event belongs to. |
96 |
|
* |
97 |
|
* @param pGenerator - creator of this event |
98 |
|
* @param FragmentPos - actual sample point position in the current |
99 |
|
* audio fragment to which this event belongs to |
100 |
|
*/ |
101 |
|
Event::Event(EventGenerator* pGenerator, int32_t FragmentPos) { |
102 |
|
pEventGenerator = pGenerator; |
103 |
|
iFragmentPos = FragmentPos; |
104 |
|
} |
105 |
|
|
106 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |