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

Contents of /linuxsampler/branches/release2_0_0/src/common/RTMath.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2789 - (show annotations) (download)
Wed Jul 15 20:34:18 2015 UTC (8 years, 10 months ago) by schoenebeck
File size: 3844 byte(s)
Created linuxsampler branch 'release2_0_0'.

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