Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+7 votes

We are playing both the static and the dits/dahs as AudioFormat files using SourceDataLines, but as far as I can tell, you can only have one line open on Java at once. I am unsure about trying to combine our sounds into one line because then I don't think we would be able to adjust the volume of the static and the dit/dahs separately.

asked in CSC 305 Fall 2024 by (2.9k points)

2 Answers

+4 votes
 
Best answer

I believe all you have to do is just put them in different threads and it'll work. With our project, whenever we want to play a sound, we call a method that creates a new thread, and inside that thread we have all of the stuff needed to create the sound that we want, including calling the SourceDataLine object to play the sound, which is .write(byte[], int, int).

We start a new thread by doing:

new Thread(() -> {

 //Actual Code goes here

}).start();

I hope this helps!

answered by (1.5k points)
selected by
+5 votes

Hmmm... my hunch is that it might be better to just use one SourceDataLine, and create the white noise by manipulating the code that generates the audio that you want to play. Try adding small random numbers to the waveform being generated?

answered by (3.5k points)
...