Is there a Java library to emit a particular frequency frequently?

Right, good. The first time I actually use Java to solve the problem. I bought a new set of headphones called Sennheiser 120 HD; but there's a problem. If there is no constant emission of sound, then the headphone base will eventually turn off and on. The spam earphones are static, which is terrible on the ears. The solution for me is currently playing music 24/7 to prevent static death. Maybe I'm weird, but I don't want to listen to music 24/7.

I believe that a suitable solution for this would be to constantly emit sound that the base can detect, but I canโ€™t hear. The application must be effective, as it works 24/7.

I do some research, but I'm not so good at Java. I cannot find a library for emitting a specific frequency. Does anyone know anything?

Itโ€™s best to get a solution for this within 4 days before my store return policy expires. If that doesn't work.

Email from Sennheiser

+5
source share
1 answer

I think you will find that listening to sound at a constant frequency is painful in the ears. However, you can do it something like this simply by using the standard Java libraries:

AudioFormat format = new AudioFormat(44000f, 16, 1, true, false);
SourceDataLine line = (SourceDataLine)AudioSystem.getLine(new DataLine.Info(SourceDataLine.class, format));

line.open(format);
line.start();

double f = 440; // Hz
double t = 3; // seconds

byte[] buffer = new byte[(int)(format.getSampleRate() * t * 2 + .5)];

f *= Math.PI / format.getSampleRate();

for(int i = 0; i < buffer.length; i += 2) {
    int value = (int)(32767 * Math.sin(i * f));
    buffer[i + 1] = (byte)((value >> 8) & 0xFF);
    buffer[i] = (byte)(value & 0xFF);
}

line.write(buffer, 0, buffer.length);

line.drain();
+1
source

All Articles