我正在尝试处理从采样的 sourcedataline(Java Sound API)获得的字节数组。如果我将字节数组与分数相乘,播放流时会出现噪音。
在我播放声音之前,我将立体声 wav 文件分成左右声道。这工作正常。但是,如果我想使用取决于延迟因子的增益控制来处理通道,我会得到噪音。
for(int i=0; i<bufferSize; i++) { array[i] = (byte) (array[i] * gain); }
有谁知道如何解决这个问题?
//编辑:
我试图通过位移将这两个字节转换为短(2字节),例如:
short leftMask = 0xff00;
short rightMask = 0x00ff;
short sValue = (array[i] + array[i+1] <<8) * gain;
array[i] = (sValue & leftMask) >> 8;
array[i+1] = (sValue & rightMask);
但是当我将单个字节乘以增益值时,我得到了相同的结果。
//编辑
或者我应该将两个数组值添加到这样的短片中吗?
short shortValue = array[i] + array[i+1];
shortValue *= gain;
array[i] = ???
但是如何在不丢失声音的情况下将这个短字节转换为 2 个单字节呢?
//编辑分离方法中的一些代码:
public static void channelManipulation(byte[] arrayComplete) {
int i=2;
char channel='L';
int j=0;
/**
* The stereo stream will be divided into his channels - the Left and the Right channel.
* Every 2 bytes the channel switches.
* While data is collected for the left channel the right channel will be set by 0. Vice versa.
*/
while(j<arrayComplete.length) {
//while we are in the left channel we are collecting 2 bytes into the arrayLeft
while(channel=='L') {
if(i==0) {
channel='R'; //switching to the right channel
i=2;
break;
}
arrayLeft[j] = (byte)(arrayComplete[j]);
arrayRight[j] = 0;
i--; j++;
}
//while we are in the right channel we are collecting 2 bytes into the arrayRight
while(channel=='R') {
if(i==0) {
channel='L'; //switching to the left channel
i=2;
break;
}
arrayRight[j] = (byte) (arrayComplete[j]);
arrayLeft[j] = 0;
i--; j++;
}
}
}