5

Right, well. First time I'm actually using Java to fix a problem. I bought a new headphone set called Sennheiser 120 HD; but there's an issue. If there isn't a constant emission of audio then the base for the headphones will eventually time out and turn off. The headphones are spammed with static, which is horrible on the ears. The solution to this for me currently is playing music 24/7 to prevent the static of death. Maybe I'm weird, but I don't want to listen to music 24/7.

I believe a workable solution for this would be to constantly emit a sound that the base can detect but I can't hear. The application would need to be efficient since it's running 24/7.

I've been doing some research, but I'm not that experienced with Java. I'm unable to find any library for emitting a certain frequency. Does anyone know of any?

It would be best to get the solution for this within 4 days, before my return policy at the store is no longer valid. Incase if this doesn't work.

Email from Sennheiser

dead beef
  • 673
  • 2
  • 6
  • 20
  • 1
    Wouldn't it be easier to return the headphones for store credit as they're clearly not fit for purpose? Or failing that, just switching them off when you don't need them? – biziclop Jul 04 '12 at 15:03
  • 1
    By the way, I guess playing a constant zero signal would work. You can set your media player to loop John Cage's best known piece. – biziclop Jul 04 '12 at 15:04
  • These activate again when you turn on your audio source. So, you just want to wear these without listening to any music? – opyate Jul 04 '12 at 15:43
  • Not what you asked for but here is some cross-platform C code using the PortAudio library that can easily be adjusted to do what you want. https://subversion.assembla.com/svn/portaudio/portaudio/trunk/examples/paex_sine.c – Bjorn Roche Jul 04 '12 at 16:43
  • 1
    A little off topic, but the response from Sennheiser makes minimal sense. They shut down the transmitter to preserve battery life, but the headset (which is what is running on batteries) doesn't shut down? Who is the engineer who came up with that plan?! – Eric B. Jul 04 '12 at 17:37
  • @EricB. It's my brillian idea.. Grrr and it's getting squashed in SO! Wait till I get my hands on you.... – Thihara Jul 05 '12 at 03:39
  • @EricB. Haha I never thought about it like that. It was a pretty unwise design. However the headphone sound quality is great. – dead beef Jul 05 '12 at 05:02

1 Answers1

3

I think you'll find that listening to a constant-frequency sound is painful on the ears. However, you could do it something like this, just using 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();
Russell Zahniser
  • 16,188
  • 39
  • 30
  • I was thinking of a frequency which isn't audible, a little bit higher pitched than the mosquito tone that student's use to get away with using their cellphone in class. EDIT: Finished looking through the source code. Hardly anything makes sense in the for statement. Maybe one day I'll be to that point; however this does look easy to modify. Thank you, I will be trying it shortly. – dead beef Jul 04 '12 at 15:20
  • In that case I suspect biziclop's zero signal solution ought to work. If it doesn't, I might suggest a subaudible frequency, say 4 Hz. The high frequency might be doing things to your ears even if you can't hear it. – Russell Zahniser Jul 04 '12 at 15:25
  • Hm, 4Hz is barely audible. Since the time between shutoffs is consistent maybe it would work to play it for about one second every forty seconds? (1000) for (40,000) – dead beef Jul 04 '12 at 15:37
  • @russellzahniser Sub audible sounds are more likely to do damage iirc. Btw I think I went to high school with you. – Adam Gent Jul 04 '12 at 15:41
  • I finished the application, thank you. Now to find which frequency does less harm. – dead beef Jul 04 '12 at 16:38
  • 1
    There are a few problems with this code. Off the top of my head: 1. 44000 is not a standard sample rate. 44100 is. I can't recall what happens in Java when you use a nonstandard s/r, but best to stick with something that will work. 2. This code cannot easily be extended to run for long periods because of the buffer, the sin function, which may become less accurate at large values, and so on. 3. There's no guarantee that it won't "click" at the end of each run, which is especially a problem for low-frequencies (maybe explains why Alec was able to hear the 4Hz signal). – Bjorn Roche Jul 04 '12 at 16:41
  • 1
    It would make more sense to use a low level broadband noise (white noise or pink noise) than a pure tone. Less irritating, only needs to be barely audible - something like the "comfort noise" that they use during silent periods on cell phone codecs. – Paul R Jul 04 '12 at 16:48
  • I timed the amount of time it takes for the base to shut off to a little over three minutes. So since the lines of code Russel provided play for about 2-3 seconds, I made them play once every 3 minutes. This should make it less noticable. – dead beef Jul 04 '12 at 16:59
  • @Thihara Sorta. I can't find any frequencies that work well. Too low and it makes a pop noise; too high and I can hear it. If it's beyond the frequency point of the headphones (22 - 19,500 Hz) it also makes the similar pop. – dead beef Jul 05 '12 at 04:56
  • Rather late update but I got this working. I used a 100Hz frequency and turned the volume down on windows to 1%. Sure it's a rather naughty way of doing things but it works for me, which is all that matters considering I'm not planning on shipping this out to anyone. – dead beef Jul 12 '12 at 22:49