我正在尝试生成正弦波并将其添加到字节数组中。我搜索并找到了相关资料,但是我总是得到像附件上这样的畸变波形。
请告诉我为什么会出现这种情况。谢谢。
我的代码在这里
private byte[] getData(int freq) { // taking pitch data
double pha = Math.PI/2; // defining phase
final int LENGTH = 44100 * 10; // defining length of sine wave, byte array
final byte[] arr = new byte[LENGTH];
for(int i = 0; i < arr.length; i++) {
double angle = (2.0 * Math.PI * i*freq+pha) / (44100);
arr[i] = (byte) (Math.cos(angle) *127* 0.3); // 0.3 is amplitude scale
}
return arr;
}