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?
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.