1

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?

  • 44000 Hz is a highly nonstandard sample rate. I suppose you intended to use 44100? – leftaroundabout Sep 20 '14 at 9:02
  • Also... with all those 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? – leftaroundabout Sep 20 '14 at 9:09
  • No, naturally not :) They are for checking whether I was actually making something that would resemble a sine wave, and whether there was a mistake in the conversion from int to byte - But it creates the byte array (during which the print methods run), and then add them to the buffer, so that is not the problem :) – Halcyon Sep 20 '14 at 9:45
  • @leftaroundabout Didn't know that :) Doesn't fix it though, and besides I don't see why a different sampling rate should give a different signal, unless you don't keep in mind the Nyquist Theorem? – Halcyon Sep 20 '14 at 9:48
2

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 – Tobias Schmidt Sep 21 '14 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.