/[svn]/linuxsampler/trunk/src/modulationsystem.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/modulationsystem.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Feb 3 13:21:19 2004 UTC (20 years, 2 months ago) by schoenebeck
File size: 5195 byte(s)
* introduced time stamped events
* implemented jitter correction
* added pitchbend wheel support
* src/audiothread.cpp: using voice pool instead of a voice array, makes
  voice allocation more efficient and code more readable
* src/rtelmemorypool: redesigned, added some new methods and pool is now
  derived from list

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003 by Benno Senoner and Christian Schoenebeck *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20 * MA 02111-1307 USA *
21 ***************************************************************************/
22
23 #include "modulationsystem.h"
24
25 float** ModulationSystem::pDestinationParameter = NULL;
26 uint ModulationSystem::uiSampleRate;
27 uint ModulationSystem::uiMaxSamplesPerCycle;
28 ModulationSystem::__FragmentTime__ ModulationSystem::FragmentTime;
29
30 void ModulationSystem::Initialize(uint SampleRate, uint MaxSamplesPerCycle) {
31 ModulationSystem::uiMaxSamplesPerCycle = MaxSamplesPerCycle;
32 ModulationSystem::uiSampleRate = SampleRate;
33 if (!pDestinationParameter) {
34 pDestinationParameter = new float*[destination_count];
35 pDestinationParameter[0] = new float[destination_count * MaxSamplesPerCycle];
36 for (int i = 1; i < destination_count; i++) {
37 pDestinationParameter[i] = pDestinationParameter[i - 1] + MaxSamplesPerCycle;
38 }
39 }
40 ModulationSystem::FragmentTime.end = ModulationSystem::CreateTimeStamp();
41 }
42
43 void ModulationSystem::Close() {
44 if (pDestinationParameter) {
45 delete[] ModulationSystem::pDestinationParameter[0];
46 delete[] ModulationSystem::pDestinationParameter;
47 }
48 }
49
50 /**
51 * Initialize the parameter sequence for the modulation destination given by
52 * by 'dst' with the constant value given by val.
53 */
54 void ModulationSystem::ResetDestinationParameter(ModulationSystem::destination_t dst, float val) {
55 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 }

  ViewVC Help
Powered by ViewVC