chris282 id steam/psn : chris282_fr | en gros la version de départ buguée était ici : http://gracefulspoon.com/blog/2009 [...] ment-64576
et voici ma version bien améliorée :
Hello every body i used this sample to improve it significally. I have far better performance, better code in terms of best practices and severals bugs are fixed.
you can find my version here (4 classes) :
Code :
- package minimsoundapp;
- import ddf.minim.analysis.*;
- import ddf.minim.*;
- import java.awt.Color;
- import processing.core.*;
- import processing.core.PApplet;
- import static processing.core.PApplet.map;
- import static processing.core.PConstants.TRIANGLE_STRIP;
- public class ThreeDimensionSpectrum extends PApplet {
- FFT fftLog;
- Minim minim;
- AudioPlayer audioplayer;
- final int TOTAL_TRACE_LENGTH=300;
- final int X_AXIS_SCALE=40;
- final int Y_AXIS_SCALE=8;
- final int Z_AXIS_SCALE=7;
- float x,y,z;
- PVector[] tempMatrix;
- PVector[] fullMatrix;
- @Override
- public void settings() {
- //size(1280, 720, P3D);
- size(480, 360, P3D);
- //size(500, 300, P3D);
- }
- @Override
- public void setup(){
- noStroke();
- minim = new Minim(this);
- audioplayer = minim.loadFile(RunSpectrum.activeFile, 1024);
- audioplayer.play();
- background(255);
- fftLog = new FFT(audioplayer.bufferSize(),audioplayer.sampleRate());
- fftLog.logAverages(22,6); //adjust numbers to adjust spacing
- tempMatrix = new PVector[fftLog.avgSize()];
- fullMatrix = new PVector[TOTAL_TRACE_LENGTH*fftLog.avgSize()];
- //longueur * largeur
- //TOTAL_TRACE_LENGTH : longueur
- //fftLog.avgSize() : largeur
- for(int i=0;i<fullMatrix.length;i++){
- fullMatrix[i]=new PVector(0, 0, 0);
- }
- }
- public void beforeDraw(){
- background(0);
- directionalLight(500,500,500,-100,-100,50);
- //directionalLight(150,150,1,sin(radians(frameCount)),cos(radians(frameCount)),1);
- ambientLight(80,80,80);
- camera((x+1000),(y+0)-(TOTAL_TRACE_LENGTH*4),-1000-200,0,y-(TOTAL_TRACE_LENGTH*4),0,0,0,1);
- //play the song
- fftLog.forward(audioplayer.mix);
- fillTempMatrix();
- updateFullMatrix();
- }
- @Override
- public void draw(){
- beforeDraw();
- int fftLogSpectrumTotalLength = fftLog.avgSize();
- float saturation = 1.0f; //saturation
- float brightness = 1f; //brightness
- for(int i=0; i<(fullMatrix.length-1); i++){
- //stroke(255,0,0);
- //locator(trace[i].x, trace[i].y, trace[i].z, 1);
- // float value = (trace[i].z*100);
- float color_input = (fullMatrix[i].x);
- float color_rescale = map(color_input, 0,fftLogSpectrumTotalLength*X_AXIS_SCALE, 0, 1);
- Color myRGBColor = Color.getHSBColor(color_rescale, saturation, brightness);
- //fill(myRGBColor.getRed(),myRGBColor.getGreen(), myRGBColor.getBlue());
- //point(trace[i].x, trace[i].y, trace[i].z);
- if( (i+1)%fftLogSpectrumTotalLength != 0 ){
- line(fullMatrix[i].x, fullMatrix[i].y, fullMatrix[i].z, fullMatrix[i+1].x, fullMatrix[i+1].y, fullMatrix[i+1].z);
- }
- stroke(myRGBColor.getRed(),myRGBColor.getGreen(), myRGBColor.getBlue());
- }
- }
- @Override
- public void stop() {
- // always close Minim audio classes when you finish with them
- audioplayer.close();
- // always stop Minim before exiting
- minim.stop();
- super.stop();
- }
- void fillTempMatrix(){
- for(int i = 0; i plus grosses valeurs de z qu’actuellement
- //calmer Z en fonction de i : gros i -> plus petites valeurs de z qu’actuellement
- //pour l’ensemble du spectre rempli la valeur
- //always get the next to last
- tempMatrix[i]= new PVector(x, y, z);
- }
- }
- void updateFullMatrix(){
- //la matrice totale fait n*fftLog.avgSize() en taille
- //car elle contient l’ensemble des frequences de 0 à fftLog.avgSize() pour chaque mesure dessinée a l’écran
- //créer un tableau total (nommé FULL) de taille 100*fftLog.avgSize();
- //une fois que le tableau TEMP est rempli avec les nouvelles mesures :
- //décaler toutes les valeurs du tableau FULL de telle manière que FULL [0] = FULL[fftLog.avgSize()] et FULL[i]=FULL[i+fftLog.avgSize()]
- for(int index=0;index<(TOTAL_TRACE_LENGTH-1)*fftLog.avgSize();index++){
- fullMatrix[index]=fullMatrix[index+fftLog.avgSize()];
- }
- //remplir le tableau FULL avec TEMP : FULL[99*fftLog.avgSize()]=TEMP[0] ; FULL[
- for(int i = 0; i<fftLog.avgSize();i++){
- //System.out.println("99*fftLog.avgSize()+i = "+99*fftLog.avgSize()+i+" ; i="+i);
- fullMatrix[(TOTAL_TRACE_LENGTH-1)*fftLog.avgSize()+i]=tempMatrix[i];
- }
- }
- }
- package minimsoundapp;
- /**
- *
- * @author formation
- */
- public class RunSpectrum {
- public static final String mp3file1="C:\\Users\\Chris\\Documents\\JavaPerso\\SoundSpectrumProjectMinimAndJavaFX\\resources\\DeorroFtElvisCrespoBailar.mp3";
- public static final String mp3file2="C:\\Users\\Chris\\Documents\\JavaPerso\\SoundSpectrumProjectMinimAndJavaFX\\resources\\BeFaithfulByFatmanScoop.mp3";
- public static final String mp3file3="C:\\Users\\Chris\\Documents\\JavaPerso\\SoundSpectrumProjectMinimAndJavaFX\\resources\\KSHMRWildcard.mp3";
- public static final String mp3file4="C:\\Users\\Chris\\Documents\\JavaPerso\\SoundSpectrumProjectMinimAndJavaFX\\resources\\NeverComeDownPRESIDENTIALREMASTER.mp3";
- public static final String activeFile=mp3file4;
- public static void main(String args[]){
- ThreeDimensionSpectrum tds = new ThreeDimensionSpectrum();
- tds.main(new String[] { "minimsoundapp.ThreeDimensionSpectrum" });
- ThreeDimensionSpectrumCloudPoints tds2 = new ThreeDimensionSpectrumCloudPoints();
- tds2.main(new String[] { "minimsoundapp.ThreeDimensionSpectrumCloudPoints" });
- //todo faire une classe mère dont deux autres héritent, de manière a avoir un Override de draw() dans chacune et un nom de classe différent pour chaque
- //de cette manière je pourrai en lancer plusieurs a la fois
- ThreeDimensionSpectrumTriangles tds3 = new ThreeDimensionSpectrumTriangles();
- tds3.main(new String[] { "minimsoundapp.ThreeDimensionSpectrumTriangles" });
- }
- }
- package minimsoundapp;
- import java.awt.Color;
- import static processing.core.PApplet.map;
- /**
- *
- * @author Chris
- */
- public class ThreeDimensionSpectrumCloudPoints extends ThreeDimensionSpectrum {
- @Override
- public void draw(){
- super.beforeDraw();
- int fftLogSpectrumTotalLength = fftLog.avgSize();
- float saturation = 1.0f; //saturation
- float brightness = 1f; //brightness
- for(int i=0; i<fullMatrix.length; i++){
- float color_input = (fullMatrix[i].x);
- float color_rescale = map(color_input, 0,fftLogSpectrumTotalLength*X_AXIS_SCALE, 0, 1);
- Color myRGBColor = Color.getHSBColor(color_rescale, saturation, brightness);
- point(fullMatrix[i].x, fullMatrix[i].y, fullMatrix[i].z);
- stroke(myRGBColor.getRed(),myRGBColor.getGreen(), myRGBColor.getBlue());
- }
- }
- }
- package minimsoundapp;
- import java.awt.Color;
- import static processing.core.PApplet.map;
- import static processing.core.PConstants.CLOSE;
- import static processing.core.PConstants.TRIANGLE_STRIP;
- /**
- *
- * @author Chris
- */
- public class ThreeDimensionSpectrumTriangles extends ThreeDimensionSpectrum{
- @Override
- public void draw(){
- super.beforeDraw();
- int fftLogSpectrumTotalLength = fftLog.avgSize();
- float saturation = 1.0f; //saturation
- float brightness = 1f; //brightness
- for(int i=1; i<fullMatrix.length-fftLogSpectrumTotalLength; i++){
- float color_input = (fullMatrix[i].x);
- float color_rescale = map(color_input, 0,fftLogSpectrumTotalLength*X_AXIS_SCALE, 0, 1);
- Color myRGBColor = Color.getHSBColor(color_rescale, saturation, brightness);
- if((i+1)%fftLogSpectrumTotalLength != 0){
- beginShape(TRIANGLE_STRIP);
- fill(myRGBColor.getRed(),myRGBColor.getGreen(), myRGBColor.getBlue());
- vertex(fullMatrix[i+1].x, fullMatrix[i+1].y, fullMatrix[i+1].z);
- vertex(fullMatrix[i].x, fullMatrix[i].y, fullMatrix[i].z);
- vertex(fullMatrix[i+1+fftLogSpectrumTotalLength].x, fullMatrix[i+1+fftLogSpectrumTotalLength].y, fullMatrix[i+1+fftLogSpectrumTotalLength].z);
- vertex(fullMatrix[i+fftLogSpectrumTotalLength].x, fullMatrix[i+fftLogSpectrumTotalLength].y, fullMatrix[i+fftLogSpectrumTotalLength].z);
- endShape(CLOSE);
- }
- }
- }
- }
|
All you need is to create a Java project (in netbeans 8.1 it is nice) and import libraries of 'processing' and 'minim', you will have many jars in your project, these are required.
11/07/2016 11:48 998 602 core.jar
11/07/2016 11:48 4 149 gluegen-rt-natives-linux-amd64.jar
11/07/2016 11:48 3 050 gluegen-rt-natives-linux-armv6hf.jar
11/07/2016 11:48 4 130 gluegen-rt-natives-linux-i586.jar
11/07/2016 11:48 5 076 gluegen-rt-natives-macosx-universal.jar
11/07/2016 11:48 8 159 gluegen-rt-natives-windows-amd64.jar
11/07/2016 11:48 7 577 gluegen-rt-natives-windows-i586.jar
11/07/2016 11:48 345 605 gluegen-rt.jar
11/07/2016 11:44 105 446 jl1.0.jar
11/07/2016 11:48 224 010 jogl-all-natives-linux-amd64.jar
11/07/2016 11:48 164 852 jogl-all-natives-linux-armv6hf.jar
11/07/2016 11:48 217 274 jogl-all-natives-linux-i586.jar
11/07/2016 11:48 443 876 jogl-all-natives-macosx-universal.jar
11/07/2016 11:48 240 721 jogl-all-natives-windows-amd64.jar
11/07/2016 11:48 209 445 jogl-all-natives-windows-i586.jar
11/07/2016 11:48 3 402 029 jogl-all.jar
11/07/2016 11:44 46 786 jsminim.jar
11/07/2016 11:44 100 497 minim.jar
11/07/2016 11:44 24 538 mp3spi1.9.4.jar
11/07/2016 11:44 10 401 tritonus_aos.jar
11/07/2016 11:44 102 673 tritonus_share.jar Message édité par chris282 le 10-12-2016 à 23:50:54
|