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, 2006 Christian Schoenebeck * |
* Copyright (C) 2005 - 2007 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 * |
26 |
|
|
27 |
#include <math.h> |
#include <math.h> |
28 |
#include <stdint.h> |
#include <stdint.h> |
29 |
#include "global.h" |
#include "global_private.h" |
30 |
|
|
31 |
/// Needed for calculating frequency ratio used to pitch a sample |
/// Needed for calculating frequency ratio used to pitch a sample |
32 |
#define TWELVEHUNDREDTH_ROOT_OF_TWO 1.000577789506555 |
#define TWELVEHUNDREDTH_ROOT_OF_TWO 1.000577789506555 |
76 |
} |
} |
77 |
|
|
78 |
/** |
/** |
79 |
|
* Slower version of CentsToFreqRatio, for big values. |
80 |
|
* |
81 |
|
* @param cents - pitch value in cents (+1200 cents means +1 octave) |
82 |
|
* @returns frequency ratio (e.g. +2.0 for +1 octave) |
83 |
|
*/ |
84 |
|
static double CentsToFreqRatioUnlimited(double Cents) { |
85 |
|
int octaves = int(Cents / 1200); |
86 |
|
double x = CentsToFreqRatio(Cents - octaves * 1200); |
87 |
|
return octaves < 0 ? x / (1 << -octaves) : x * (1 << octaves); |
88 |
|
} |
89 |
|
|
90 |
|
/** |
91 |
* Inverse function to CentsToFreqRatio(). This function is a bit |
* Inverse function to CentsToFreqRatio(). This function is a bit |
92 |
* slow, so it should not be called too frequently. |
* slow, so it should not be called too frequently. |
93 |
*/ |
*/ |
96 |
} |
} |
97 |
|
|
98 |
private: |
private: |
|
static float CentsToFreqTable[CONFIG_MAX_PITCH * 1200 * 2 + 1]; |
|
99 |
static float* pCentsToFreqTable; |
static float* pCentsToFreqTable; |
100 |
|
|
101 |
static float* InitCentsToFreqTable(); |
static float* InitCentsToFreqTable(); |