我将一个Java .jar转换为一个带有IKVM的C#.dll库,除了一件事以外,一切运行良好:当我创建一个Java类的实例时,它的所有属性都是0或null(至少是调试视图)如此说,除了首先初始化的那个。我使用包含AudioInputStream的init()方法,我认为这是问题,但在尝试引用Objects属性之前我没有得到任何异常。 我是这么认为的,因为之前初始化了一个非null的属性,并且在使用流之后不再有控制台输出(应该有一些,你可以在方法中看到)。
我不是c#或IKVM的专家,我现在不知道该怎么办......
这是init()方法的代码:
public void init(String s) {
System.out.println("Loading file "+s);
try {
File f = new File(s);
file = f;
AudioInputStream dais =
AudioSystem.getAudioInputStream(new BufferedInputStream(new FileInputStream(f)));
AudioFormat baseFormat = dais.getFormat();
AudioFormat decodeFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,//Encoding
baseFormat.getSampleRate(), //Samplerate
16, //SampleSizeinBits (not compatible with 32bit on Windows)
baseFormat.getChannels(), // Channels
baseFormat.getChannels() * 2, // FrameSize
baseFormat.getSampleRate(), // FramRate
false
);
AudioInputStream ais = AudioSystem.getAudioInputStream(decodeFormat, dais);
System.out.println("Successfully loaded "+s);
numChannels = baseFormat.getChannels();
System.out.println(" Numchannels "+numChannels+" The number of channels");
frameLength = (int) ais.getFrameLength();
System.out.println(" Framelength "+frameLength+" The number frames for the whole file");
frameSize = (int) baseFormat.getFrameSize();
System.out.println(" Framesize "+frameSize+" The number of bYtes per Frame");
frameRate = (int) baseFormat.getFrameRate();
System.out.println(" Framerate "+frameRate+" The number of frames per second in hz");
sampleRate = (int) baseFormat.getSampleRate();
System.out.println(" Samplerate "+sampleRate+" The number of samples per second in hz");
sampleSize = (int) baseFormat.getSampleSizeInBits();
System.out.println(" Samplesize(bit) "+sampleSize+" The number of bits per sample");
System.out.println(" Samplesize(byte) "+sampleSize/8+" The number of bytes per sample");
byte[] bytes = new byte[frameLength*frameSize];
try {
ais.read(bytes);
} catch (Exception e) {
e.printStackTrace();
}
int[][] toReturn = new int[numChannels][frameLength];
int sampleIndex = 0;//like framepos
for (int t = 0; t < bytes.length;) {
for (int channel = 0; channel < numChannels; channel++) {
if(sampleSize == 16){
int low = (int) bytes[t];
t++;
int high = (int) bytes[t];
t++;
int sample = getSixteenBitSample(high, low);
toReturn[channel][sampleIndex] = sample;
}else if(sampleSize == 32){
int low = (int) bytes[t];
t++;
int lower = (int) bytes[t];
t++;
int higher = (int) bytes[t];
t++;
int high = (int) bytes[t];
t++;
int sample = getThirtyTwoBitSample(high,higher,lower, low);
toReturn[channel][sampleIndex] = sample;
}
}
sampleIndex++;
}
channels = new Channel[numChannels];
for(int i = 0; i < channels.length; i++){
channels[i] = new Channel(toReturn[i]);
}
samples = toReturn;
}catch(Exception e) {
e.printStackTrace();
}
return;
}