NeighborBlaster, die Waffe gegen den Nachbarsfeind!
Habt ihr auch so liebe Nachbarn, die einen stundenlang mit übelsten Bässen aus überdimensionierten Subwoofern den letzten Nerv / Schlaf rauben? Und das obwohl sie schon x mal vom Vermieter angesprochen, abgemahnt, etc. wurden?
Aus lauter Wut entstand gestern abend folgender einfacher -aber effektiver
– Tongenerator.
Der Tongenerator spielt einen Dauerton ab (im Beispielcode ekelhafte 3500Hz). Der Dauerton ändert auch ständig seine Lautstärke um den Nachbar-NervFaktor (N-NF) zu verdoppeln
import java.util.logging.Level;
-
import java.util.logging.Logger;
-
import javax.sound.sampled.AudioFormat;
-
import javax.sound.sampled.AudioSystem;
-
import javax.sound.sampled.LineUnavailableException;
-
import javax.sound.sampled.SourceDataLine;
-
-
/**
-
*
-
* @author Michael Kabdebo
-
*/
-
public class NeighborBlaster {
-
-
/** Bandbreite in Hz*/
-
private static final float FREQUENCY = 44100;
-
/** Tonlage in Hz*/
-
private static final int HERTZ = 3500;
-
private AudioFormat af;
-
private SourceDataLine sdl;
-
private Thread thread;
-
private boolean isAlive;
-
private int volume;
-
-
public NeighborBlaster() {
-
volume = 80;
-
af = new AudioFormat(FREQUENCY, 8, 1, true, false);
-
try {
-
sdl = AudioSystem.getSourceDataLine(af);
-
sdl.open(af);
-
sdl.start();
-
-
} catch (LineUnavailableException ex) {
-
Logger.getLogger(NeighborBlaster.class.getName()).log(Level.SEVERE, null, ex);
-
System.exit(-1);
-
}
-
}
-
-
private void initThread() {
-
thread = new Thread(new Runnable() {
-
-
public void run() {
-
isAlive = true;
-
byte[] buf = new byte[1];
-
-
while (isAlive) {
-
for (int i = 0; i < 1000 * FREQUENCY / 1000; i++) {
-
double angle = i / (FREQUENCY / HERTZ) * 2.0 * Math.PI;
-
buf[0] = (byte) (Math.sin(angle) * (volume * 1.28));
-
sdl.write(buf, 0, 1);
-
}
-
-
}
-
sdl.drain();
-
sdl.stop();
-
sdl.close();
-
}
-
});
-
}
-
-
private void stop() {
-
isAlive = false;
-
}
-
-
public void start() throws LineUnavailableException {
-
initThread();
-
thread.start();
-
}
-
-
public void setVolume(int volume) {
-
this.volume = volume;
-
}
-
-
public int getVolume() {
-
return volume;
-
}
-
-
public static void main(String[] args) throws LineUnavailableException, InterruptedException {
-
NeighborBlaster nb = new NeighborBlaster();
-
nb.start();
-
int direction = 1;
-
while (true) {
-
-
// schwankende Lautstärke
-
if (nb.getVolume() <= 20) {
-
direction = 1;
-
}
-
if (nb.getVolume() >= 100) {
-
direction = -1;
-
}
-
nb.setVolume(nb.getVolume() + direction);
-
Thread.sleep(100);
-
}
-
}
-
}
Sub-Pages
Kategorien
- Allgemein (31)
- Amateurfunk (5)
- Lustiges (9)
- THW (3)
Letzte Kommentare
- gurke bei FDP Saarland und der Datenschutz