Okay, so I'm trying to make a sine wave in an audio file, however it doesn't work (the sound is really weird), even though the values generated resemble a sine function. I've been trying to figure out the problem and noticed that when I change the sample rate, the sound changes too. Why does the sample rate impact how my generated audio file sounds?
1 Answer
Most likely aliasing is to blame. What you get from discreet samples doesn't always make an ideal representation of the audio you are trying to create due to the stepping nature of the samples. You could try applying an anti-aliasing filter to the samples to make it better reproduce a sine wave.
There may also be problems in the code itself, but debugging programming code is probably off-topic here.
-
yeah aliasing is very noticeable on pure sine waves +1 for this. This book will help you to understand aliasing and gives strategies how to prevent it: dspguide.com/ch3/3.htm Commented Sep 21, 2014 at 7:24
System.out.print
statements, you don't really expect the performance good enough for real time audio playback, do you? Perhaps this weird sound is because it's all chopped up when the playback waits for new data, but the program is busy printing'I'
s?