Morse Code : Sound Looping and Click Time

I want to make a little Morse Code Simulator
Morse Code uses dots and dashes
dots are one unit of time
dashes are three units of time.

I am trying to figure out two things
-One is how to play a tone while the user is holding down a button.
My first attempt was to play a small dot.ogg looping why the button was down, but the sound does not stay constant it fades in and out so instead of a tone it goes waan waa waa kind of like dub step :slight_smile:

-Two what is the best way to keep track of how long they held down the button.
I currently am just adding tpf from the update method to the current total but not sure if that is the best way.

Thanks for any suggestions

Use a sine instead of some siren or sound that changes over time. The typical morse receivers also used simple tones to play the code.

@gbluntzer said: I want to make a little Morse Code Simulator Morse Code uses dots and dashes dots are one unit of time dashes are three units of time.

I am trying to figure out two things
-One is how to play a tone while the user is holding down a button.
My first attempt was to play a small dot.ogg looping why the button was down, but the sound does not stay constant it fades in and out so instead of a tone it goes waan waa waa kind of like dub step :slight_smile:

-Two what is the best way to keep track of how long they held down the button.
I currently am just adding tpf from the update method to the current total but not sure if that is the best way.

Thanks for any suggestions

I think .ogg always streams unless you force it to streamCache when creating the audio node. Though I think that’s the only case that looping works so maybe you are already doing that.

As normen alludes to, make sure that your looping sound is actually loopable… then you might want to use a .wav file since it won’t have to redecode it every time it starts playing again.

Regarding the last, I’m not sure why you’d want to keep track of the time. Turn on the sound when they press the key down and turn it off when they lift it up again.

If you want to keep track of the time then track it yourself. System.nanoTime() when the key is pressed and System.nanoTime() again when it was released and then take the difference.