Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean #9

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
619c16a
new
Gabmeister Apr 6, 2022
621ab1b
Update README.md
Gabmeister Apr 6, 2022
3e3d5ef
Update README.md
Gabmeister Apr 6, 2022
65f5521
new
Gabmeister Apr 7, 2022
1b3c166
Merge branch 'master' of https://github.com/Gabmeister/MusicVisuals
Gabmeister Apr 7, 2022
25499c1
added sound and cube visual for case 2
Gabmeister Apr 12, 2022
16741e4
added some comments
Gabmeister Apr 12, 2022
2b435f3
test commit
Apr 12, 2022
7e2adc2
bruh
SeanL00000000000 Apr 19, 2022
c2b0f25
Merge https://github.com/Gabmeister/MusicVisuals
SeanL00000000000 Apr 19, 2022
b4cbf5e
added circle and rectangle
SeanL00000000000 Apr 20, 2022
41e22be
test
SeanL00000000000 Apr 25, 2022
bc22507
test
Gabmeister Apr 29, 2022
f7ddd97
added square pattern
SeanL00000000000 May 1, 2022
3aa1493
synced up circle and 3d square to rotate to the beat of the music
SeanL00000000000 May 3, 2022
7946dbd
Merge pull request #1 from SeanL00000000000/master
Gabmeister May 4, 2022
421ad17
almost finished
May 4, 2022
e8b4b96
Update README.md
Gabmeister May 4, 2022
a21775a
Update README.md
Gabmeister May 4, 2022
f07d73e
Merge pull request #2 from Gabmeister/clean
Gabmeister May 4, 2022
e42b615
..
Gabmeister May 4, 2022
5700932
Merge branch 'master' of https://github.com/Gabmeister/MusicVisuals
Gabmeister May 4, 2022
28b4f85
commit
Gabmeister May 4, 2022
8e2ffb7
commit
Gabmeister May 4, 2022
e9ecdaa
Merge branch 'master' into clean
Gabmeister May 4, 2022
2b2b518
so close!
Gabmeister May 4, 2022
98a849e
almost there
Gabmeister May 4, 2022
97c4093
clean this first
Gabmeister May 4, 2022
de2cf9e
ratio
Gabmeister May 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Music Visualiser Project

Name:

Student Number:
Names: Gabriel Plaza and Sean Lawless
Student Numbers: (Gabriel)C20474596, (Sean)C20447296

## Instructions
- Fork this repository and use it a starter project for your assignment
Expand All @@ -12,6 +12,7 @@ Student Number:
- Check out the WaveForm and AudioBandsVisual for examples of how to call the Processing functions from other classes that are not subclasses of PApplet

# Description of the assignment
Object Oriented Programming group assignment to create an audio visualiser using java processing libraries.

# Instructions

Expand Down
Binary file added java/data/light.mp3
Binary file not shown.
Binary file added java/data/rain.mp3
Binary file not shown.
Binary file added java/data/tevvez.mp3
Binary file not shown.
Empty file removed java/src/c123456/BryansVisual.java
Empty file.
15 changes: 15 additions & 0 deletions java/src/c20474596/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package c20474596;

public class Main{

public static void Start(){
String[] a = {"MAIN"};
processing.core.PApplet.runSketch( a, new Runner());
}

public static void main(String[] args){
Start();
}

}

194 changes: 194 additions & 0 deletions java/src/c20474596/Runner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
package c20474596;
import ddf.minim.AudioBuffer;
import ddf.minim.AudioInput;
import ddf.minim.AudioPlayer;
import ddf.minim.Minim;
import ddf.minim.analysis.FFT;

public class Runner extends Visual{
Minim minim;
AudioPlayer ap;
AudioInput ai;
AudioBuffer ab;
Star[] stars = new Star[900];
float px;
float py;
int mode = 0;
float smoothedBoxSize = 0;
float angle = 0;
//sean edits
int c = 16;
float t = 1;
int nprime = 1;
float hue;
FFT fft; // Object that performs Fast Fourier Transform (FFT)
int OFF_MAX= 300;
drop d;
drop[] drops= new drop[500];
float radius = 200;
float rot = 0;

public void setup(){
for(int i = 0; i < stars.length; i++){
stars[i] = new Star();
}
minim=new Minim(this);
startMinim();
getFFT();
loadAudio("light.mp3");
colorMode(HSB,255);
hue = random(255);
//sean edits
noStroke();
for(int i =0;i<drops.length; i++){
drops[i]= new drop();
}
}

public void keyPressed(){
if (key >= '0' && key <= '9') {
mode = key - '0';
}
if (key == ' ')
{
getAudioPlayer().cue(0);
getAudioPlayer().play();
}
}

public void settings(){
size(800,800,P3D);
fullScreen(P3D, SPAN);
}

public void draw(){
background(0);
if(key == '1' || key == '2' || key == ' '){ //ensure everything is centered in visual 1 and 2
translate(width/2, height/2);
}
switch(mode){
case 1: //stars on screen visual
{
for(int i = 0; i<stars.length;i++){ //Displays star(s) on screen
fill(255);
strokeWeight(1);

float sx = map(stars[i].x/stars[i].z,0,1,0,width);
float sy = map(stars[i].y/stars[i].z,0,1,0,height);
float r = map(stars[i].z,0,width,16,0);
ellipse(sx,sy,r,r);

float px = map(stars[i].x/stars[i].pz,0,1,0,width);
float py = map(stars[i].y/stars[i].pz,0,1,0,height);

stroke(255);
line(px,py,sx,sy);
}

for(int i = 0;i<stars.length;i++){ //updates star(s) position on screen once they disappear
stars[i].z = stars[i].z-25; //z - 25, 25 = speed of stars
if(stars[i].z < 1){
stars[i].z = width;
stars[i].x = random(-width,width);
stars[i].y = random(-height,height);
stars[i].pz = stars[i].z;
}
}

}

case 2:

{
getFFT();
calculateFrequencyBands();
calculateAverageAmplitude();
getAmplitude();
float boxSize = 200 + (700 * getSmoothedAmplitude());
stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255);
fill(10,10,10);
box(boxSize);
}

case 3:
{
if (key == '3') //if statement to make sure this visual is exclusive
{

t = (float) (pow(t,(float) 1.00001) + .1);
calculateAverageAmplitude();
stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255);
nprime++;
translate(width/2,height/2);
rotate(PI*sin(t/50));
fill(255,30,50,30);
rect(-width/2,-height/2,width,height);
circles();
}
}

case 4:
{
if (key == '4') //if statement to make sure this visual is exclusive
{

getFFT();
getMinim();
calculateFrequencyBands();
calculateAverageAmplitude();
stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255);
rot += getAmplitude() / 8.0f;

translate(width / 2, height / 2, OFF_MAX);
rotateX((float) (frameCount * .01));
rotateY((float) (frameCount * .01));
rotateZ((float) (frameCount * .01));

for (int xo = -OFF_MAX; xo <= OFF_MAX; xo += 50) {
for (int yo = -OFF_MAX; yo <= OFF_MAX; yo += 50) {
for (int zo = -OFF_MAX; zo <= OFF_MAX; zo += 50) {
pushMatrix();
translate(xo, yo, zo);
rotateX((float) (frameCount * .02));
rotateY((float) (frameCount * .02));
rotateZ((float) (frameCount * .02));
rotate(rot);
fill(colorFromOffset(xo), colorFromOffset(yo),
colorFromOffset(zo));
box((float) (20 + (Math.sin(frameCount / 20.0)) * 15));
popMatrix();
}
}
}
}
}
}

}

private void circles() {
calculateAverageAmplitude();
getFFT();
calculateFrequencyBands();//SEAN
for (int n = 1; n < nprime*3; n++) {
pushMatrix();
rot += getAmplitude() / 10.0f;
rotate(rot);
float r = c*sqrt(n);
float radius = 50;
float theta = n*PI*(3-sqrt(10));
stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255);
fill(255,map(r/2,1,width,0,500),28,40);
float pulse = pow(sin(t*PI/3-n*PI/(t%100)),(float) 1.5);

ellipse(r*cos(theta)/2,r*sin(theta)/2,pulse*radius+10,pulse*radius+6);
popMatrix();
pulse= 50 + (200 * getSmoothedAmplitude());
}

}

int colorFromOffset(int offset) {
return (int) ((offset + OFF_MAX) / (2.0 * OFF_MAX) * 255);}
}

18 changes: 18 additions & 0 deletions java/src/c20474596/Star.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package c20474596;

import processing.core.PApplet;

public class Star extends PApplet {

float x;
float y;
float z;
float pz;
public Star(){
x = random(-width,width);
y = random(-height,height);
z = random(width);
pz = z;
}

}
134 changes: 134 additions & 0 deletions java/src/c20474596/Visual.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package c20474596;


import processing.core.PApplet;
import ddf.minim.*;
import ddf.minim.analysis.FFT;

public abstract class Visual extends PApplet
{
private int frameSize = 512;
private int sampleRate = 44100;

protected float[] bands;
private float[] smoothedBands;

private Minim minim;
private AudioInput ai;
private AudioPlayer ap;
private AudioBuffer ab;
protected FFT fft;

private float amplitude = 0;
private float smothedAmplitude = 0;



public void startMinim()
{
minim = new Minim(this);

fft = new FFT(frameSize, sampleRate);

bands = new float[(int) log2(frameSize)];
smoothedBands = new float[bands.length];

}
float log2(float f) {
return log(f) / log(2.0f);
}



public void calculateAverageAmplitude()
{
float total = 0;
for(int i = 0 ; i < ab.size() ; i ++)
{
total += abs(ab.get(i));
}
amplitude = total / ab.size();
smothedAmplitude = PApplet.lerp(smothedAmplitude, amplitude, 0.1f);
}


protected void calculateFrequencyBands() {
for (int i = 0; i < bands.length; i++) {
int start = (int) pow(2, i) - 1;
int w = (int) pow(2, i);
int end = start + w;
float average = 0;
for (int j = start; j < end; j++) {
average += fft.getBand(j) * (j + 1);
}
average /= (float) w;
bands[i] = average * 5.0f;
smoothedBands[i] = lerp(smoothedBands[i], bands[i], 0.05f);
}
}

public void startListening()
{
ai = minim.getLineIn(Minim.MONO, frameSize, 44100, 16);
ab = ai.left;
}

public void loadAudio(String filename)
{
ap = minim.loadFile(filename, frameSize);
ab = ap.mix;
}

public int getFrameSize() {
return frameSize;
}

public void setFrameSize(int frameSize) {
this.frameSize = frameSize;
}

public int getSampleRate() {
return sampleRate;
}

public void setSampleRate(int sampleRate) {
this.sampleRate = sampleRate;
}

public float[] getBands() {
return bands;
}

public float[] getSmoothedBands() {
return smoothedBands;
}

public Minim getMinim() {
return minim;
}

public AudioInput getAudioInput() {
return ai;
}


public AudioBuffer getAudioBuffer() {
return ab;
}

public float getAmplitude() {
return amplitude;
}

public float getSmoothedAmplitude() {
return smothedAmplitude;
}

public AudioPlayer getAudioPlayer() {
return ap;
}

public FFT getFFT() {
return fft;
}
}
Loading