| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 
 | 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 quactuellement
//calmer Z en fonction de i : gros i -> plus petites valeurs de z quactuellement
//pour lensemble 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 lensemble 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);
}
}
}
} |