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

+13 votes

In memo 3A, we are supposed to allow more distortion and noise for advanced users. Is there another way in which we can create distortion in static without closing the audio line. I would like to multiple audio lines but it slows the app down alot

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

1 Answer

+6 votes
 
Best answer

You can modify the sound directly. One way is to mix in some random noise, like a static sound, by adding small, random variations to the audio data (without multiple audio lines). Another option is to change the way the sound waves behave, such as making them louder or softer suddenly, which creates a crackling or distorted effect. You can also lower the quality of the sound by reducing its precision, making it sound rougher, like a weak radio signal. Here is a code that chatGPT gave me for an example of modifying a single SourceDataLine with noise:

byte[] buffer = new byte[1024];
while (line.isOpen()) {
for (int i = 0; i < buffer.length; i++) {
    buffer[i] += (byte)(Math.random() * 10 - 5); // Adding noise
}
line.write(buffer, 0, buffer.length); // Write modified data\
answered by (4.4k points)
selected by
+2

thank you zeki, this helps alot!

...