/[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 554 - (show annotations) (download)
Thu May 19 19:25:14 2005 UTC (18 years, 11 months ago) by schoenebeck
File size: 3811 byte(s)
* All compile time options are now centrally alterable as arguments to the
  ./configure script. All options are C Macros beginning with CONFIG_
  prefix and will be placed into auto generated config.h file.

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 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 float RTMathBase::CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave
27 float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable());
28
29 #if defined(__APPLE__)
30 #include <mach/mach_time.h>
31 typedef uint64_t time_stamp_t;
32 static inline time_stamp_t GetMachTime() {
33 return (time_stamp_t) mach_absolute_time();
34 }
35 #endif
36
37 /*
38 * Creates a real time stamp for the current moment. Out of efficiency this
39 * is implemented in inline assembly for each CPU independently; we currently
40 * don't use a generic solution for CPUs that are not yet covered by the
41 * assembly code, instead an error message is prompted on compile time, forcing
42 * the user to contact us.
43 */
44 RTMathBase::time_stamp_t RTMathBase::CreateTimeStamp() {
45 #if defined(__i386__) || defined(__x86_64__)
46 uint64_t t;
47 __asm__ __volatile__ ("rdtsc" : "=A" (t));
48 return t >> 8;
49 #elif defined(__ia64__)
50 time_stamp_t t;
51 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(t));
52 return t;
53 #elif defined(__powerpc__)
54 time_stamp_t t;
55 __asm__ __volatile__ (
56 "98: mftb %0\n"
57 "99:\n"
58 ".section __ftr_fixup,\"a\"\n"
59 " .long %1\n"
60 " .long 0\n"
61 " .long 98b\n"
62 " .long 99b\n"
63 ".previous"
64 : "=r" (t) : "i" (0x00000100)
65 );
66 return t;
67 #elif defined(__alpha__)
68 time_stamp_t t;
69 __asm__ __volatile__ ("rpcc %0" : "=r"(t));
70 return t;
71 #elif defined(__APPLE__)
72 return GetMachTime();
73 #else // we don't want to use a slow generic solution
74 # error "Sorry, LinuxSampler lacks time stamp code for your system."
75 # error "Please report this error and the CPU you are using to the LinuxSampler developers mailing list!"
76 #endif
77 }
78
79 /**
80 * Will automatically be called once to initialize the 'Cents to frequency
81 * ratio' table.
82 */
83 float* RTMathBase::InitCentsToFreqTable() {
84 float* pMiddleOfTable = &CentsToFreqTable[CONFIG_MAX_PITCH * 1200];
85 for (int i = -1200; i <= 1200; i++) {
86 pMiddleOfTable[i] = pow(TWELVEHUNDREDTH_ROOT_OF_TWO, i);
87 }
88 return pMiddleOfTable;
89 }

  ViewVC Help
Powered by ViewVC