在提示的第 1 部分中,我希望将一个方程集成到 Java 中以获得一个周期 (T) 的值。等式如下:T = FS / (440 * (2 ^(h/12))
笔记:
FS = 采样率,即 44100 / 1。
h = 半步,由用户提供。
这个等式的一个例子是:44100 / (440 * (2 ^(2/12)) = 89.3
我写的代码如下:
public static double getPeriod(int halfstep) {
double T = 100; // TODO: Update this based on note
double FS = 44100 / 1;
double power = Math.pow(2, (halfstep / 12));
double denominator = 440 * (power);
double result = (FS) / (denominator);
T = Math.round(result);
return T;
}
// Equation test.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("halfstep is: ");
int halfstep = in.nextInt();
double period = getPeriod(halfstep);
System.out.print("Period: " + period + " ");
}
但是当我使用 h = 2, T = 100.0 而不是预期的 89.3 运行这段代码时,我不确定问题是什么。有什么想法吗?