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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 56 by schoenebeck, Tue Apr 27 09:21:58 2004 UTC revision 799 by persson, Sat Nov 5 10:59:37 2005 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   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  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 22  Line 23 
23    
24  #include "RTMath.h"  #include "RTMath.h"
25    
26  float  RTMath::CentsToFreqTable[MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave  float  RTMathBase::CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; // +-1200 cents per octave
27  float* RTMath::pCentsToFreqTable(InitCentsToFreqTable());  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   * Will automatically be called once to initialize the 'Cents to frequency
81   * ratio' table.   * ratio' table.
82   */   */
83  float* RTMath::InitCentsToFreqTable() {  float* RTMathBase::InitCentsToFreqTable() {
84      float* pMiddleOfTable = &CentsToFreqTable[MAX_PITCH * 1200];      float* pMiddleOfTable = &CentsToFreqTable[CONFIG_MAX_PITCH * 1200];
85      for (int i = -1200; i <= 1200; i++) {      for (int i = -CONFIG_MAX_PITCH * 1200; i <= CONFIG_MAX_PITCH * 1200; i++) {
86          pMiddleOfTable[i] = pow(TWELVEHUNDREDTH_ROOT_OF_TWO, i);          pMiddleOfTable[i] = pow(TWELVEHUNDREDTH_ROOT_OF_TWO, i);
87      }      }
88      return pMiddleOfTable;      return pMiddleOfTable;

Legend:
Removed from v.56  
changed lines
  Added in v.799

  ViewVC Help
Powered by ViewVC