/[svn]/linuxsampler/trunk/src/common/RTMath.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/common/RTMath.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1212 - (show annotations) (download)
Tue May 29 23:59:36 2007 UTC (16 years, 11 months ago) by schoenebeck
File size: 3844 byte(s)
* added highly experimental support for on-the-fly instrument editing
  within the sampler's process (by using instrument editor plugins),
  you'll notice the new "Registered instrument editors:" message on
  startup, the plugin path can be overridden at compile time with
  ./configure --enable-plugin-dir=/some/dir
* added a new LSCP command "EDIT INSTRUMENT <sampler-channel>" to spawn
  a matching instrument editor for the instrument on the given sampler
  channel (LSCP command syntax might be subject to change soon)
* config.h is not going to be installed along with liblinuxsampler's
  API header files anymore (not necessary anymore)
* take care of $(DESTDIR) when creating the instruments DB on 'make
  install' rule (needed for packaging and cross compilation)
* bumped version to 0.4.0.5cvs

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 * *
8 * 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 *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #include "RTMath.h"
25
26 static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave
27
28 float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable());
29
30 #if defined(__APPLE__)
31 #include <mach/mach_time.h>
32 typedef uint64_t time_stamp_t;
33 static inline time_stamp_t GetMachTime() {
34 return (time_stamp_t) mach_absolute_time();
35 }
36 #endif
37
38 /*
39 * Creates a real time stamp for the current moment. Out of efficiency this
40 * is implemented in inline assembly for each CPU independently; we currently
41 * don't use a generic solution for CPUs that are not yet covered by the
42 * assembly code, instead an error message is prompted on compile time, forcing
43 * the user to contact us.
44 */
45 RTMathBase::time_stamp_t RTMathBase::CreateTimeStamp() {
46 #if defined(__i386__) || defined(__x86_64__)
47 uint64_t t;
48 __asm__ __volatile__ ("rdtsc" : "=A" (t));
49 return t >> 8;
50 #elif defined(__ia64__)
51 time_stamp_t t;
52 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(t));
53 return t;
54 #elif defined(__powerpc__)
55 time_stamp_t t;
56 __asm__ __volatile__ (
57 "98: mftb %0\n"
58 "99:\n"
59 ".section __ftr_fixup,\"a\"\n"
60 " .long %1\n"
61 " .long 0\n"
62 " .long 98b\n"
63 " .long 99b\n"
64 ".previous"
65 : "=r" (t) : "i" (0x00000100)
66 );
67 return t;
68 #elif defined(__alpha__)
69 time_stamp_t t;
70 __asm__ __volatile__ ("rpcc %0" : "=r"(t));
71 return t;
72 #elif defined(__APPLE__)
73 return GetMachTime();
74 #else // we don't want to use a slow generic solution
75 # error "Sorry, LinuxSampler lacks time stamp code for your system."
76 # error "Please report this error and the CPU you are using to the LinuxSampler developers mailing list!"
77 #endif
78 }
79
80 /**
81 * Will automatically be called once to initialize the 'Cents to frequency
82 * ratio' table.
83 */
84 float* RTMathBase::InitCentsToFreqTable() {
85 float* pMiddleOfTable = &CentsToFreqTable[CONFIG_MAX_PITCH * 1200];
86 for (int i = -CONFIG_MAX_PITCH * 1200; i <= CONFIG_MAX_PITCH * 1200; i++) {
87 pMiddleOfTable[i] = pow(TWELVEHUNDREDTH_ROOT_OF_TWO, i);
88 }
89 return pMiddleOfTable;
90 }

  ViewVC Help
Powered by ViewVC