gpt4 book ai didi

java类问题

转载 作者:行者123 更新时间:2023-11-28 08:14:52 25 4
gpt4 key购买 nike

在这个论坛一些非常好的人的帮助下,我已经能够将一些 c++ 翻译成 java 语言,但我不确定如何调用这些类。基本上他们应该做的是返回“gen4 样式”曲线。如果有人知道如何运行它,请告诉我!

/*
Derived from gen4 from the UCSD Carl package, described in F.R. Moore,
"Elements of Computer Music." It works like setline, but there's an
additional argument for each time,value pair (except the last). This
arg determines the curvature of the segment, and is called "alpha" in
the comments to trans() below. -JGG, 12/2/01

http://www.music.columbia.edu/cmc/rtcmix/docs/docs.html (maketable/gen4)



trans(a, alpha, b, n, output) makes a transition from <a> to <b> in
<n> steps, according to transition parameter <alpha>. It stores the
resulting <n> values starting at location <output>.
alpha = 0 yields a straight line,
alpha < 0 yields an exponential transition, and
alpha > 0 yields a logarithmic transition.
All of this in accord with the formula:
output[i] = a + (b - a) * (1 - exp(i * alpha / (n-1))) / (1 - exp(alpha))
for 0 <= i < n
*/





import java.lang.Math;
private static final int MAX_POINTS =1024;

public class gen{
int size; /* size of array to load up */
int nargs; /* number of arguments passed in p array */
float []pvals; /* address of array of p values */
double []array; /* address of array to be loaded up */
int slot; /* slot number, for fnscl test */
}

public static void fnscl(gen g) {
}

static void trans(double a, double alpha, double b, int n, double[] output) {
double delta = b - a;

if (output.length <= 1) {
output[0] = a;
return;
}
double interval = 1.0 / (output.length - 1);
if (alpha != 0) {
double denom = 1 / (1 - Math.exp(alpha));
for (int i = 0; i < output.length; i++)
output[i] = a + (1 - Math.exp(i * alpha * interval)) * delta * denom;
} else {
for (int i = 0; i < output.length; i++)
output[i] = a + i * delta * interval;
}
}

public static double gen4(gen g) {

int i;
int points = 0;
int seglen = 0;

double factor;
double time [] = new double[MAX_POINTS];
double value [] = new double[MAX_POINTS];
double alpha [] = new double[MAX_POINTS];
double ptr [];

if (g.nargs < 5 || (g.nargs % 3) != 2) /* check number of args */
System.out.println("gen4 usage: t1 v1 a1 ... tn vn");

if ((g.nargs / 3) + 1 > MAX_POINTS)
System.out.println("gen4 too many arguments");

for (i = points = 0; i < g.nargs; points++) {
time[points] = g.pvals[i++];

if (points > 0 && time[points] < time[points - 1])
System.out.println("gen4 non-increasing time values");

value[points] = g.pvals[i++];
if (i < g.nargs)
alpha[points] = g.pvals[i++];
}

factor = (g.size - 1) / time[points - 1];

for (i = 0; i < points; i++)
time[i] *= factor;

ptr = g.array;

for (i = 0; i < points - 1; i++) {
seglen = (int) (Math.floor(time[i + 1] + 0.5)
- Math.floor(time[i] + 0.5) + 1);
trans(value[i], alpha[i], value[i + 1], seglen, ptr);
ptr[i] += seglen - 1;
}

fnscl(g);
return 0.0;
}

最佳答案

如果我正确理解你的问题并且你想执行你的程序,你需要对你的代码进行一些调整。

你需要上课。要执行它,您需要一个特殊的 main 方法。

/** 
*Derived from...
*/
import java.lang.Math;

class Gen4Func {
class Gen {
// insert from question
}

public static void main(String[] args) {
// prepare parameters
// ...

// call your function
trans( ... );

// do more stuff
// ...
}

public static void fnscl(gen g) {
}

static void trans(double a, double alpha, double b, int n, double[] output) {
// insert from above
}
}

将其保存到 Gen4Func.java(必须匹配类名)。然后从via执行

> java Gen4Func

正如我所说:如果我正确理解您的问题。

HTH,
迈克

关于java类问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7994533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com