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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 799 - (hide annotations) (download)
Sat Nov 5 10:59:37 2005 UTC (18 years, 6 months ago) by persson
File size: 3849 byte(s)
* Bug-fixes: pitch changes larger than one octave didn't work. Looped
  samples small enough to fit in RAM didn't work.

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 554 * Copyright (C) 2005 Christian Schoenebeck *
7 schoenebeck 53 * *
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 schoenebeck 554 float RTMathBase::CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave
27 schoenebeck 319 float* RTMathBase::pCentsToFreqTable(InitCentsToFreqTable());
28 schoenebeck 53
29 schoenebeck 361 #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 schoenebeck 328 /*
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 schoenebeck 361 #elif defined(__APPLE__)
72     return GetMachTime();
73 schoenebeck 328 #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 schoenebeck 53 /**
80     * Will automatically be called once to initialize the 'Cents to frequency
81     * ratio' table.
82     */
83 schoenebeck 319 float* RTMathBase::InitCentsToFreqTable() {
84 schoenebeck 554 float* pMiddleOfTable = &CentsToFreqTable[CONFIG_MAX_PITCH * 1200];
85 persson 799 for (int i = -CONFIG_MAX_PITCH * 1200; i <= CONFIG_MAX_PITCH * 1200; i++) {
86 schoenebeck 53 pMiddleOfTable[i] = pow(TWELVEHUNDREDTH_ROOT_OF_TWO, i);
87     }
88     return pMiddleOfTable;
89     }

  ViewVC Help
Powered by ViewVC