Hello. I've just started learning about how to use sound in
java. I thought I would start with the simplest way of doing things first by using the Applet.newAudioClip() method.
I've been making a beat calculator, which the user can tap in a tempo and it tells the user what tempo that is. I am now adding a metronome (click track) to it as well. The metronome was working fine before I added sound. But there seems to be a delay in playing the sounds sometimes, which makes it sound like the click is speeding up and slowing down. The proglem is with the sound because the visual part of the metronome - a JButton which counts the beats in a bar - is still working fine and is in time. I'm using the Swing Timer to keep time.
Does anyone know why the sound sometimes plays straight away, yet sometimes there is a delay? Is there anything I can do to make it run more smoothly? I know there are more complex ways of using sound in Java but I want to sort this way out before I move on.
Here is part of my Click class below. I've only kept in methods I thought were relevant.