Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package script;
- import javazoom.jl.decoder.BitstreamException;
- import javazoom.jl.decoder.Decoder;
- import javazoom.jl.decoder.DecoderException;
- import javazoom.jl.decoder.Header;
- import javazoom.jl.decoder.JavaLayerException;
- import javazoom.jl.decoder.Obuffer;
- import javazoom.jl.decoder.SampleBuffer;
- import javazoom.jl.decoder.Bitstream;
- import javazoom.jl.player.Player;
- import java.text.NumberFormat;
- import java.util.Arrays;
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.awt.event.KeyEvent;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Map;
- import javax.sound.sampled.AudioFileFormat;
- import javax.sound.sampled.AudioSystem;
- import javax.sound.sampled.UnsupportedAudioFileException;
- import org.tritonus.share.sampled.file.TAudioFileFormat;
- import edu.emory.mathcs.jtransforms.fft.DoubleFFT_1D;
- public class MusicPlayer {
- static double getDurationWithMp3Spi(File file)
- throws UnsupportedAudioFileException, IOException {
- AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file);
- if (fileFormat instanceof TAudioFileFormat) {
- Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties();
- String key = "duration";
- Long microseconds = (Long) properties.get(key);
- int mili = (int) (microseconds / 1000);
- int sec = (mili / 1000);
- int min = (mili / 1000) / 60;
- return microseconds / 1000000.0;
- } else {
- throw new UnsupportedAudioFileException();}
- }
- public static void main(String[] args) throws IOException,
- JavaLayerException, InterruptedException, UnsupportedAudioFileException, AWTException {
- // TODO Auto-generated method stub
- //E:\\Program Files (x86)\\Steam\\SteamApps\\common\\team fortress 2\\tf\\cfg\\script.cfg
- FileInputStream mp3 = new FileInputStream("30hz.mp3");
- FileInputStream mp3player = new FileInputStream("30hz.mp3");
- File song = new File("30hz.mp3");
- Decoder decoder = new Decoder();
- Bitstream bitstream = new Bitstream(mp3);
- Bitstream playerBitstream = new Bitstream(mp3player);
- SampleBuffer currentBuffer = (SampleBuffer) decoder.decodeFrame(
- bitstream.readFrame(), bitstream);
- Player player = new Player(mp3player);
- int bufferLength = currentBuffer.getBufferLength();
- DoubleFFT_1D transform = new DoubleFFT_1D(bufferLength);
- double duration = getDurationWithMp3Spi(song);
- bitstream.unreadFrame();
- bitstream.closeFrame();
- String fov;
- int x =0;
- int placeholder=0;
- double currentMaximum=Double.MIN_VALUE;
- double maximum=50000;
- int freq=0;
- Robot robot = new Robot();
- String text=" ";
- String[] textAmp = new String[200];
- for(int i=0;i<200;i++){
- textAmp[i]="O";
- for(int j=0;j<i;j++){
- textAmp[i]=textAmp[i]+"O";
- }
- }
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- player.play(1);
- double intensity=0;
- while (((x <= (int) (((44100 * (duration - 1)) / 1152.0))))) {
- player.play(1);
- currentBuffer = (SampleBuffer) decoder.decodeFrame(bitstream.readFrame(), bitstream);
- short[] originalBufferArray = new short[bufferLength];
- originalBufferArray = currentBuffer.getBuffer();
- double[] doubleBufferArray = new double[bufferLength*2];
- for(int i =0; i<bufferLength;i+=2){
- doubleBufferArray[i]=(double)originalBufferArray[i];
- doubleBufferArray[i+1]=0;
- //System.out.println(doubleBufferArray[i]);
- //System.out.println(doubleBufferArray[i+1]);
- }
- double temp=0;
- //BEGIN ARRAYLIST
- // double[] organizedArray = new double[2304];
- // for(int i=0;i<1152;i++){
- // organizedArray[i*2]=doubleBufferArray[i];
- // }
- // for(int i=1152;i<2304;i++){
- // organizedArray[((i-1152)*2)+1]=doubleBufferArray[i];
- // }
- //END ARRAYLIST
- transform.complexForward(doubleBufferArray);
- double[] finalArray = new double[bufferLength];
- for(int i =0;i<10;i+=2){
- finalArray[i/2]= Math.sqrt(Math.pow(doubleBufferArray[i],2)+(Math.pow(doubleBufferArray[i+1], 2)));
- finalArray[i/2]= finalArray[i/2]/(double)(bufferLength/2.0);
- if(finalArray[i/2]>currentMaximum){
- currentMaximum=finalArray[i/2];
- freq=i/2;
- }
- }
- //System.out.println(currentMaximum);
- // if (freq==4){
- // currentMaximum/=4;
- // intensity=currentMaximum/maximum;
- //
- // }
- // else if (freq==3){
- // currentMaximum/=3;
- // intensity=currentMaximum/maximum;
- // }
- // else if (freq==2){
- // currentMaximum/=2;
- // intensity=currentMaximum/maximum;
- // }
- // else{
- intensity=currentMaximum/maximum;
- System.out.println(textAmp[(int) (intensity*100*2)]);
- int fovInt=(int)(90-(intensity*25));
- // }
- // text=String.valueOf(intensity);
- // text=text.substring(2,4);
- // placeholder = (int)Double.parseDouble(text);
- try{
- File script = new File("E:\\Program Files (x86)\\Steam\\SteamApps\\common\\team fortress 2\\tf\\cfg\\script.cfg");
- BufferedWriter writer = new BufferedWriter(new FileWriter(script));
- fov = "fov_desired " + fovInt +"\necho \"working\"";
- writer.write(fov, 0 ,fov.length());
- writer.flush();
- writer.close();
- robot.keyPress(KeyEvent.VK_NUM_LOCK );
- robot.keyRelease(KeyEvent.VK_NUM_LOCK );
- } finally{}
- currentMaximum=Double.MIN_VALUE;
- bitstream.unreadFrame();
- bitstream.closeFrame();
- x++;
- }
- /*
- * 0~0hz
- * 1~19.140625hz
- * 2~38.28125hz
- * 3~57.422145hz
- * 4~76.56277
- * 5~ 95.703395
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement