diff --git a/.DS_Store b/.DS_Store index 55c1fcbeb..96276dea7 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.vscode/launch.json b/.vscode/launch.json index 5f0c7af3b..4f5e89f6d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,5 +1,12 @@ { "configurations": [ + { + "type": "java", + "name": "test2", + "request": "launch", + "mainClass": "ie.tudublin.test2", + "projectName": "java" + }, { "type": "java", "name": "CodeLens (Launch) - Main", diff --git a/README.md b/README.md index 19ba88c75..5679dc54f 100644 --- a/README.md +++ b/README.md @@ -1,89 +1,99 @@ # Music Visualiser Project -Name: +Name: Fajar Albalushi, +Bayan Alwardi -Student Number: +Student Number: D20125707, +D20125581 + +# Youtube Video + +[![YouTube](https://user-images.githubusercontent.com/123570704/235653303-596fd465-284e-43c2-a2e4-f6dcb338d83a.jpg)](https://www.youtube.com/watch?v=5zI0J1447Vs) -## Instructions -- Fork this repository and use it a starter project for your assignment -- Create a new package named your student number and put all your code in this package. -- You should start by creating a subclass of ie.tudublin.Visual -- There is an example visualiser called MyVisual in the example package -- 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 +This assignment showcases a visually captivating and funky representation of a song. The provided code employs various visualization techniques to create an immersive and engaging visual experience that complements the music. The code incorporates different modes of visualization, each offering its unique visual effects. These effects are carefully crafted to capture the energy and vibe of the music, resulting in a cool and vibrant visual representation. As the song plays, the visuals come to life, dynamically responding to the rhythm, tempo, and other elements of the music. The code utilizes techniques like amplitude analysis, frequency mapping, and rhythmic patterns to generate visually appealing and synchronized effects. The visual representation generated by the code is meant to enhance the listening experience, adding an extra layer of excitement and enjoyment. It creates a multisensory encounter where the audience can not only hear but also see the music come alive in a funky and visually stimulating manner. Overall, this assignment combines the power of sound and visuals to create a funky and visually mesmerizing representation of a song, resulting in an immersive and dynamic experience for the audience. # Instructions +Run the code: +Open the Processing sketch and click the "Run" button or press "Ctrl+R" (or "Cmd+R" on Mac) to start the visualizations. -# How it works +Explore visualization modes: +Press the number keys (1, 2, 3, 4) to switch between different visualization modes. +Each mode offers a unique visual effect, so feel free to try them out and see which one you like best. -# What I am most proud of in the assignment +Control the audio: +Press the spacebar to pause/play the audio. +This allows you to pause the music and focus solely on the visualizations, or resume the audio playback. -# Markdown Tutorial +Observe and enjoy: +As the song plays, watch how the visuals respond to the music. +Notice how the colors, shapes, and movements change in sync with the audio input. -This is *emphasis* +# How it works +The visuals created by the provided code can be related to the song "Mantra" by interpreting the visuals in a way that captures the essence and mood of the song. Here's a possible interpretation: + +Bayan: -This is a bulleted list +Sphere (Mode 1): +The dynamic lines and vibrant colors of the sphere visualization can represent the energetic and pulsating nature of the song "Mantra." +The changing positions and lengths of the lines can mirror the rhythmic patterns and melodic movements in the music. +The size and color variations of the dots can symbolize the different layers and frequencies present in the song, adding depth and complexity to the visual representation. -- Item -- Item +-The sphere visualization represents the audio by drawing lines that vary in length and color based on the amplitude of the audio. +-As the song plays, the lines change their positions and lengths, creating a dynamic and immersive visual experience. +-The size of the dots also changes based on the amplitude, with different colors representing different frequencies. +-The visual elements respond to the audio, resulting in an abstract and vibrant representation of the song. -This is a numbered list +https://user-images.githubusercontent.com/123604689/235656017-cc7cb52c-ae20-4dcc-975e-f09605cbae56.mov -1. Item -1. Item +Spiral Nodes (Mode 3): +The spiral pattern and fluid movements of the nodes can represent the continuous and cyclical nature of the song "Mantra." +The nodes' interactions and bouncing movements can convey a sense of harmony and synchronization with the music. +The changing thickness and color of the lines connecting the nodes can symbolize the intricate layers and textures in the song's composition, adding a sense of complexity and depth to the visual representation. -This is a [hyperlink](http://bryanduggan.org) +-This visualization consists of nodes arranged in a spiral pattern that react to the audio input. +-The nodes move and bounce around the screen, with their speed and direction influenced by the frequency of the audio. +-The lines connecting the nodes are drawn with varying thickness and color, reflecting the audio's intensity and frequency. +-As the song progresses, the spiral nodes create a visually intricate and evolving pattern. -# Headings -## Headings -#### Headings -##### Headings +https://user-images.githubusercontent.com/123604689/235656790-142de04e-0c49-49ae-aea1-3fb6aa91ad2f.mov -This is code: +Fajar: -```Java -public void render() -{ - ui.noFill(); - ui.stroke(255); - ui.rect(x, y, width, height); - ui.textAlign(PApplet.CENTER, PApplet.CENTER); - ui.text(text, x + width * 0.5f, y + height * 0.5f); -} -``` +Sound Particles (Mode 2): +The moving particles in this visualization can symbolize the repetitive and trance-like nature of the song "Mantra." +The particles' movements and sizes can follow the pulsating beats and subtle variations in the music, creating a mesmerizing and hypnotic visual effect. +The changing colors of the particles can correspond to the shifting tones and emotions in the song, reflecting its introspective and evocative qualities. -So is this without specifying the language: +-This visualization displays moving particles that respond to the audio input. +-The particles' positions and sizes are influenced by the amplitude of the audio, creating a visual effect that corresponds to the intensity of the sound. +-The colors of the particles also change based on the audio input, further enhancing the visual representation of the song. -``` -public void render() -{ - ui.noFill(); - ui.stroke(255); - ui.rect(x, y, width, height); - ui.textAlign(PApplet.CENTER, PApplet.CENTER); - ui.text(text, x + width * 0.5f, y + height * 0.5f); -} -``` +https://user-images.githubusercontent.com/123604689/235655738-f9708e1e-cc01-45cf-9286-2e05bf5a20db.mov -This is an image using a relative URL: +CDWaves (Mode 4): +The circular waves in this visualization can signify the expansive and transformative qualities of the song "Mantra." +The size and color variations of the waves can capture the ebb and flow of intensity and emotion throughout the song. +The central circle representing the audio source can symbolize the core mantra or recurring motif in the music, while the surrounding waves reflect the subtle variations and harmonies that build upon it. +By relating the visuals to the song's characteristics, such as its energy, repetition, cyclical nature, and transformative qualities, the visualizations can enhance the listener's experience and provide a synchronized and immersive representation of the song "Mantra." -![An image](images/p8.png) +-In this visualization, circular waves are created based on the audio input. +-The size and color of the waves change dynamically with the amplitude of the audio. +-The visualization includes a central circle that represents the audio source, with its size and color responding to the average amplitude of the audio. +-The circular waves around the central circle are drawn with different colors and widths, representing different frequency bands in the audio. -This is an image using an absolute URL: +https://user-images.githubusercontent.com/123604689/235656205-7f4b17ef-9335-4daf-9d47-6a98f95477a6.mov -![A different image](https://bryanduggandotorg.files.wordpress.com/2019/02/infinite-forms-00045.png?w=595&h=&zoom=2) +# What I am most proud of in the assignment +Fajar: +I am proud of the code's responsiveness to the audio input. The visualizations dynamically adjust based on the amplitude, frequency, and rhythm of the music. This synchronization between the visuals and the music creates a seamless and coherent experience, where the visuals and music complement each other perfectly. Furthermore, this project helped me to gain better understanding of git. Throughout the project, we faced various challenges that tested our problem-solving abilities and teamwork. Aligning the audio and visual components was a critical aspect of the project. Achieving synchronization between the music and visuals required meticulous attention to detail and thorough testing. -This is a youtube video: +Bayan: +I am most proud of the visuals I created for the project. Despite facing difficulties and restrictions on my Mac OS which didn't allow me to use P3D for 3D visuals, I adapted and used my knowledge of shapes, dimensions, and colors to create visuals that gave a 3D feel to the project. I spent a lot of time experimenting with different shapes and colors to make sure the visuals were dynamic and interesting to look at while still synchronizing with the audio. I'm happy with the way the visuals turned out and I think they are a great complement to the audio. It was a challenging but rewarding experience and I'm proud of what I was able to achieve. + +# Markdown Tutorial -[![YouTube](http://img.youtube.com/vi/J2kHSSFA4NU/0.jpg)](https://www.youtube.com/watch?v=J2kHSSFA4NU) -This is a table: -| Heading 1 | Heading 2 | -|-----------|-----------| -|Some stuff | Some more stuff in this column | -|Some stuff | Some more stuff in this column | -|Some stuff | Some more stuff in this column | -|Some stuff | Some more stuff in this column | diff --git a/java/.DS_Store b/java/.DS_Store index 629e3335c..e0ed830c1 100644 Binary files a/java/.DS_Store and b/java/.DS_Store differ diff --git a/java/.project b/java/.project index 0d5afed93..ba04f8088 100644 --- a/java/.project +++ b/java/.project @@ -16,12 +16,12 @@ - 1616413840733 + 1679327021618 30 org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ diff --git a/java/bin/.DS_Store b/java/bin/.DS_Store new file mode 100644 index 000000000..da524b131 Binary files /dev/null and b/java/bin/.DS_Store differ diff --git a/java/bin/ie/.DS_Store b/java/bin/ie/.DS_Store new file mode 100644 index 000000000..8d5519595 Binary files /dev/null and b/java/bin/ie/.DS_Store differ diff --git a/java/data/.DS_Store b/java/data/.DS_Store new file mode 100644 index 000000000..5008ddfcf Binary files /dev/null and b/java/data/.DS_Store differ diff --git a/java/data/Parasite.mp3 b/java/data/Parasite.mp3 new file mode 100644 index 000000000..9d1d8c9bd Binary files /dev/null and b/java/data/Parasite.mp3 differ diff --git a/java/data/horizon.mp3 b/java/data/horizon.mp3 new file mode 100644 index 000000000..18096ceaa Binary files /dev/null and b/java/data/horizon.mp3 differ diff --git a/java/data/surething.mp3 b/java/data/surething.mp3 new file mode 100644 index 000000000..ba243ab08 Binary files /dev/null and b/java/data/surething.mp3 differ diff --git a/java/src/.DS_Store b/java/src/.DS_Store new file mode 100644 index 000000000..da524b131 Binary files /dev/null and b/java/src/.DS_Store differ diff --git a/java/src/D20125581/sphere.java b/java/src/D20125581/sphere.java new file mode 100644 index 000000000..7d3745b49 --- /dev/null +++ b/java/src/D20125581/sphere.java @@ -0,0 +1,122 @@ +package D20125581; + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; + +public class sphere extends PApplet { + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + + int mode = 0; + float y = 0; + float smoothedY = 0; + float smoothedAmplitude = 0; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + public void settings() { + size(1024, 1000); + // fullScreen(P3D, SPAN); + } + + public void setup() { + + minim = new Minim(this); + ap = minim.loadFile("java/data/horizon.mp3", 1024); + ap.play(); + ab = ap.mix; + colorMode(HSB); + y = height / 2; + smoothedY = y; + + } + + float off = 0; + float lerpedBuffer[] = new float[1024]; + + public void draw() { + float average = 0; + float sum = 0; + off += 1; + + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + background(0); + noFill(); + translate(width / 2, height / 2); + + // Draw the sphere + float sphereRadius = 300; + int sphereDetail = 30; + for (float i = 0; i < PI; i += PI / sphereDetail) { + float r1 = sin(i) * sphereRadius; + float r2 = sin(i + PI / sphereDetail) * sphereRadius; + for (float j = 0; j < TWO_PI; j += TWO_PI / sphereDetail) { + float theta = random(0, PI); + float x1 = cos(j) * r1; + float y1 = sin(j) * r1; + float x2 = cos(j) * r2; + float y2 = sin(j) * r2; + float c = (int) ((theta / PI) * 255); + stroke(c, 255, 255); + line(x1, y1, -cos(i) * sphereRadius, x2, y2, -cos(i + PI / sphereDetail) * sphereRadius); + } + } + + // Draw the dots + int numDots = 700; + for (int i = 0; i < numDots; i++) { + float theta1 = random(0, PI); + float theta2 = random(0, TWO_PI); + float x = sin(theta1) * cos(theta2) * sphereRadius; + float y = sin(theta1) * sin(theta2) * sphereRadius; + float z = -cos(theta1) * sphereRadius; + float movement = map(smoothedAmplitude, 0, 1, 0, 100); // map amplitude to movement range + x += random(-movement, movement); + y += random(-movement, movement); + z += random(-movement, movement); + float dotSize = map(smoothedAmplitude, 0, 1, 1, 10); // map amplitude to dot size range + ellipse(x, y, dotSize, dotSize); + int hue = (int) ((theta1 / PI) * 255); + fill(hue, 255, 255); + } + + } +} + + diff --git a/java/src/D20125581/spiralNodes.java b/java/src/D20125581/spiralNodes.java new file mode 100644 index 000000000..4c4dd9166 --- /dev/null +++ b/java/src/D20125581/spiralNodes.java @@ -0,0 +1,96 @@ +package D20125581; + +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import processing.core.PVector; +import ddf.minim.analysis.*; + +public class spiralNodes extends PApplet { + Minim m; + AudioPlayer player; + FFT fft; + + Node[] nodes = new Node[1200]; + + class Node { + PVector loc; + PVector velocity = new PVector(random(-2, 2), random(-2, 2)); + float size = 10; + float angle = random(0, TWO_PI); + + Node(float x, float y) { + this.loc = new PVector(x, y); + } + + void run(float freq) { + this.display(); + this.move(freq); + this.bounce(); + } + + void display() { + point(loc.x, loc.y); + } + + void move(float freq) { + float spiralSpeed = freq * 0.1f; + angle += spiralSpeed; + float radius = freq * 0.5f; + loc.x += cos(angle) * radius; + loc.y += sin(angle) * radius; + } + + void bounce() { + if ((this.loc.x > width) || (this.loc.x < 0)) { + velocity.x = velocity.x * -1; + } + if ((this.loc.y > height) || (this.loc.y < 0)) { + velocity.y = velocity.y * -1; + } + } + } + + public void settings() { + size(1024, 1000); + } + + public void setup() { + smooth(); + + for (int i = 0; i < nodes.length; i++) { + nodes[i] = new Node(random(width), random(height)); + } + + m = new Minim(this); + player = m.loadFile("java/data/horizon.mp3", 1024); + fft = new FFT(player.bufferSize(), player.sampleRate()); + player.play(); + + } + + public void draw() { + noStroke(); + noCursor(); + background(40, 40, 80); + fft.forward(player.mix); + + for (int i = 0; i < nodes.length; i++) { + float freq = fft.getFreq((float) (dist(nodes[i].loc.x, nodes[i].loc.y, width / 2, height / 2) * 2.2)); + + strokeWeight(freq / 10); + stroke((1 - nodes[i].loc.y / 800) * 255, (nodes[i].loc.x / 800) * 255, (nodes[i].loc.y / 800) * 255); + for (int j = i + 1; j < nodes.length; j++) { + Node other = nodes[j]; + float dist = nodes[i].loc.dist(other.loc); + if (dist > 0 && dist < 60) { + line(nodes[i].loc.x, nodes[i].loc.y, other.loc.x, other.loc.y); + } + } + stroke(255); + nodes[i].run(freq); + } + } +} + + diff --git a/java/src/D20125707/CDWaves.java b/java/src/D20125707/CDWaves.java new file mode 100644 index 000000000..c6aa03a6b --- /dev/null +++ b/java/src/D20125707/CDWaves.java @@ -0,0 +1,84 @@ +package D20125707; + +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import processing.core.PVector; +import ddf.minim.analysis.*; + +public class CDWaves extends PApplet { + + Minim m; + AudioPlayer player; + FFT fft; + + int x; + int radius = 200; + float hue = 0; + + public void settings() { + size(1024, 1000); + } + + public void setup() { + m = new Minim(this); + + player = m.loadFile("java/data/horizon.mp3", 1024); + player.play(); + + fft = new FFT(player.bufferSize(), player.sampleRate()); + + x = 0; + } + + public void draw() { + translate(width / 2, height / 2); + background(0); + + colorMode(HSB, 255); + + float avgAmplitude = player.mix.level() * 255; + fill(avgAmplitude, 0, 0); + circle(0, 0, 120); + fill(255); + circle(cos(radians(x)) * 5, sin(radians(x)) * 5, 110); + fill(0); + circle(0, 0, 10); + + if (player.isPlaying()) x += 2; + + fft.forward(player.mix); + float bands = fft.specSize(); + + for (int i = 0; i < bands * 2; i++) { + float start_x = radius * cos(PI * (i + x) / bands); + float start_y = radius * sin(PI * (i + x) / bands); + + float bandAmplitude; + if (i < bands) { + bandAmplitude = fft.getBand(i); + } else { + bandAmplitude = fft.getFreq(i); + } + hue += 0.5; + if (hue > 255) { + hue = 0; + } + int currentColor = color(hue, 255, 255, 100); + int nextColor = color(hue + 1, 255, 255, 100); + int blendedColor = lerpColor(currentColor, nextColor, bandAmplitude / 2); + fill(blendedColor); + noStroke(); + + float angle = PI * (i + x) / bands; + float arcWidth = 20 + bandAmplitude * 2; + float arcHeight = 20 + bandAmplitude * 2; + + pushMatrix(); + translate(start_x, start_y); + rotate(angle); + arc(0, 0, arcWidth, arcHeight, 0, PI); + popMatrix(); + } + } +} diff --git a/java/src/D20125707/SoundParticles.java b/java/src/D20125707/SoundParticles.java new file mode 100644 index 000000000..c7063b2fe --- /dev/null +++ b/java/src/D20125707/SoundParticles.java @@ -0,0 +1,94 @@ +package D20125707; +//MUSIC +import ddf.minim.*; +import ddf.minim.signals.*; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import processing.core.PVector; +import ddf.minim.analysis.*; + + +public class SoundParticles extends PApplet { + Minim minim; + AudioPlayer mySound; + + + // pause/play key + int mode = 0; + + //if space key is pressed pause/play + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (mySound.isPlaying()) { + mySound.pause(); + } else { + mySound.rewind(); + mySound.play(); + } + } +} + +public void settings() + { + size(1024, 1000); + //noStroke(); + } +//MAIN SETUP +public void setup () { + //fullScreen(P3D); + //noCursor(); + smooth(); + background (0); + frameRate(24); + + //MUSIC | Add mp3 to file and change name of "Murph.mp3" to your song name + minim = new Minim(this); + mySound = minim.loadFile("java/data/horizon.mp3", 1024); + mySound.play(); +} + + +public void draw () { + + fill(0,50); + noStroke(); + rect(0, 0, width, height); + translate(width/2, height/2); + + float n4 = (float) 0.4; + float n6 = (float) 0.6; + +for (int i = 0; i < mySound.bufferSize() - 1; i++) { + + float angle = sin(i+n4)* 10; + float angle2 = sin(i+n6)* 300; + + float x = sin(radians(i))*(angle2+30); + float y = cos(radians(i))*(angle2+30); + + float x3 = sin(radians(i))*(500/angle); + float y3 = cos(radians(i))*(500/angle); + + fill (255, 255, 0); //yellow + ellipse(x, y, mySound.left.get(i)*10, mySound.left.get(i)*10); + + fill ( 255); //wt + rect(x3, y3, mySound.left.get(i)*20, mySound.left.get(i)*10); + + fill ( 255, 165, 0); //orange + rect(x, y, mySound.right.get(i)*10, mySound.left.get(i)*10); + + + fill( 255); //wt + rect(x3, y3, mySound.right.get(i)*10, mySound.right.get(i)*20); + } + + n4 += 0.008; + n6 += 0.04; + +} +} \ No newline at end of file diff --git a/java/src/example/CubeVisual.java b/java/src/example/CubeVisual.java deleted file mode 100644 index ff8e58798..000000000 --- a/java/src/example/CubeVisual.java +++ /dev/null @@ -1,90 +0,0 @@ -package example; - -import ie.tudublin.Visual; - -public class CubeVisual extends Visual -{ - boolean twocubes = false; - - public void settings() - { - size(800, 800, P3D); - println("CWD: " + System.getProperty("user.dir")); - //fullScreen(P3D, SPAN); - } - - public void keyPressed() - { - if (key == ' ') - { - getAudioPlayer().cue(0); - getAudioPlayer().play(); - - } - if (key == '1') - { - twocubes = ! twocubes; - - } - } - - public void setup() - { - colorMode(HSB); - noCursor(); - - setFrameSize(256); - - startMinim(); - loadAudio("heroplanet.mp3"); - //getAp().play(); - //startListening(); - - } - - float smoothedBoxSize = 0; - - public void draw() - { - calculateAverageAmplitude(); - background(0); - noFill(); - lights(); - stroke(map(getSmoothedAmplitude(), 0, 1, 0, 255), 255, 255); - camera(0, 0, 0, 0, 0, -1, 0, 1, 0); - translate(0, 0, -250); - - float boxSize = 50 + (getAmplitude() * 300);//map(average, 0, 1, 100, 400); - smoothedBoxSize = lerp(smoothedBoxSize, boxSize, 0.2f); - if (twocubes) - { - pushMatrix(); - translate(-100, 0, 0); - rotateY(angle); - rotateX(angle); - box(smoothedBoxSize); - //strokeWeight(1); - //sphere(smoothedBoxSize); - popMatrix(); - pushMatrix(); - translate(100, 0, 0); - rotateY(angle); - rotateX(angle); - strokeWeight(5); - box(smoothedBoxSize); - popMatrix(); - } - else - { - rotateY(angle); - rotateX(angle); - //strokeWeight(1); - //sphere(smoothedBoxSize/ 2); - strokeWeight(5); - - box(smoothedBoxSize); - } - angle += 0.01f; - } - float angle = 0; -} \ No newline at end of file diff --git a/java/src/example/MyVisual.java b/java/src/example/MyVisual.java index 849e71bc2..2603e9b86 100644 --- a/java/src/example/MyVisual.java +++ b/java/src/example/MyVisual.java @@ -23,7 +23,7 @@ public void setup() startMinim(); // Call loadAudio to load an audio file to process - //loadAudio("heroplanet.mp3"); + loadAudio("java/data/heroplanet.mp3"); // Call this instead to read audio from the microphone diff --git a/java/src/ie/.DS_Store b/java/src/ie/.DS_Store new file mode 100644 index 000000000..8d5519595 Binary files /dev/null and b/java/src/ie/.DS_Store differ diff --git a/java/src/ie/tudublin/Assignment.java b/java/src/ie/tudublin/Assignment.java new file mode 100644 index 000000000..9e03cd0e0 --- /dev/null +++ b/java/src/ie/tudublin/Assignment.java @@ -0,0 +1,325 @@ +package ie.tudublin; + +//test +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; + +import ddf.minim.*; +import ddf.minim.signals.*; +import processing.core.PVector; +import ddf.minim.analysis.*; + + +public class Assignment extends PApplet { + + // sphere + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + int mode = 0; + float y = 0; + float smoothedY = 0; + float smoothedAmplitude = 0; + float off = 0; + float lerpedBuffer[] = new float[1024]; + + //CDWaves + int x; + int radius = 200; + float hue = 0; + + // spiralNodes + FFT fft; + + Node[] nodes = new Node[1200]; + + class Node { + PVector loc; + PVector velocity = new PVector(random(-2, 2), random(-2, 2)); + float size = 10; + float angle = random(0, TWO_PI); + + Node(float x, float y) { + this.loc = new PVector(x, y); + } + + void run(float freq) { + this.display(); + this.move(freq); + this.bounce(); + } + + void display() { + point(loc.x, loc.y); + } + + void move(float freq) { + float spiralSpeed = freq * 0.1f; + angle += spiralSpeed; + float radius = freq * 0.5f; + loc.x += cos(angle) * radius; + loc.y += sin(angle) * radius; + } + + void bounce() { + if ((this.loc.x > width) || (this.loc.x < 0)) { + velocity.x = velocity.x * -1; + } + if ((this.loc.y > height) || (this.loc.y < 0)) { + velocity.y = velocity.y * -1; + } + } + } + + + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + public void settings() { + size(1024, 1000); + // fullScreen(P3D, SPAN); + } + + public void setup() { + + // sphere + minim = new Minim(this); + ap = minim.loadFile("java/data/horizon.mp3", 1024); + ap.play(); + ab = ap.mix; + y = height / 2; + smoothedY = y; + + // sound particles + smooth(); + background(0); + frameRate(24); + + // spiralNodes + smooth(); + for (int i = 0; i < nodes.length; i++) { + nodes[i] = new Node(random(width), random(height)); + } + + minim = new Minim(this); + fft = new FFT(ap.bufferSize(), ap.sampleRate()); + ap.play(); + + for (int i = 0; i < nodes.length; i++) { + nodes[i] = new Node(random(width), random(height)); + } + + x = 0; + + } + + public void draw() { + float average = 0; + float sum = 0; + off += 1; + + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for (int i = 0; i < ab.size(); i++) { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + } + average = sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + switch (mode) { + // sphere code + case 1: + + background(0); + noFill(); + colorMode(HSB); + translate(width / 2, height / 2); + + // Draw the sphere + float sphereRadius = 300; + int sphereDetail = 30; + for (float i = 0; i < PI; i += PI / sphereDetail) { + float r1 = sin(i) * sphereRadius; + float r2 = sin(i + PI / sphereDetail) * sphereRadius; + for (float j = 0; j < TWO_PI; j += TWO_PI / sphereDetail) { + float theta = random(0, PI); + float x1 = cos(j) * r1; + float y1 = sin(j) * r1; + float x2 = cos(j) * r2; + float y2 = sin(j) * r2; + float c = (int) ((theta / PI) * 255); + stroke(c, 255, 255); + line(x1, y1, -cos(i) * sphereRadius, x2, y2, -cos(i + PI / sphereDetail) * sphereRadius); + } + } + + // Draw the dots + int numDots = 700; + for (int i = 0; i < numDots; i++) { + float theta1 = random(0, PI); + float theta2 = random(0, TWO_PI); + float x = sin(theta1) * cos(theta2) * sphereRadius; + float y = sin(theta1) * sin(theta2) * sphereRadius; + float z = -cos(theta1) * sphereRadius; + float movement = map(smoothedAmplitude, 0, 1, 0, 100); // map amplitude to movement range + x += random(-movement, movement); + y += random(-movement, movement); + z += random(-movement, movement); + float dotSize = map(smoothedAmplitude, 0, 1, 1, 10); // map amplitude to dot size range + ellipse(x, y, dotSize, dotSize); + int hue = (int) ((theta1 / PI) * 255); + fill(hue, 255, 255); + } + break; + + case 2: + // sound particles + colorMode(RGB); + fill(0, 50); + noStroke(); + rect(0, 0, width, height); + translate(width / 2, height / 2); + + float n4 = (float) 0.4; + float n6 = (float) 0.6; + + for (int i = 0; i < ap.bufferSize() - 1; i++) { + + float angle = sin(i + n4) * 10; + float angle2 = sin(i + n6) * 300; + + float x = sin(radians(i)) * (angle2 + 30); + float y = cos(radians(i)) * (angle2 + 30); + + float x3 = sin(radians(i)) * (500 / angle); + float y3 = cos(radians(i)) * (500 / angle); + + fill(255, 255, 0); // yellow + ellipse(x, y, ap.left.get(i) * 10, ap.left.get(i) * 10); + + fill(255); // wt + rect(x3, y3, ap.left.get(i) * 20, ap.left.get(i) * 10); + + fill(255, 165, 0); // orange + rect(x, y, ap.right.get(i) * 10, ap.left.get(i) * 10); + + fill(255); // wt + rect(x3, y3, ap.right.get(i) * 10, ap.right.get(i) * 20); + } + + n4 += 0.008; + n6 += 0.04; + + break; + + case 3: + //spiralNNodes + noStroke(); + noCursor(); + colorMode(RGB); + background(0); + fft.forward(ap.mix); + + for (int i = 0; i < nodes.length; i++) { + float freq = fft + .getFreq((float) (dist(nodes[i].loc.x, nodes[i].loc.y, width / 2, height / 2) * 2.2)); + + strokeWeight(freq / 10); + stroke((1 - nodes[i].loc.y / 800) * 255, (nodes[i].loc.x / 800) * 255, + (nodes[i].loc.y / 800) * 255); + for (int j = i + 1; j < nodes.length; j++) { + Node other = nodes[j]; + float dist = nodes[i].loc.dist(other.loc); + if (dist > 0 && dist < 60) { + line(nodes[i].loc.x, nodes[i].loc.y, other.loc.x, other.loc.y); + } + } + stroke(255); + nodes[i].run(freq); + } + break; + + case 4: + //CDWaives + translate(width / 2, height / 2); + background(0); + + colorMode(HSB, 255); + + float avgAmplitude = ap.mix.level() * 255; + fill(avgAmplitude, 0, 0); + circle(0, 0, 120); + fill(255); + circle(cos(radians(x)) * 5, sin(radians(x)) * 5, 110); + fill(0); + circle(0, 0, 10); + + if (ap.isPlaying()) x += 2; + + fft.forward(ap.mix); + float bands = fft.specSize(); + + for (int i = 0; i < bands * 2; i++) { + float start_x = radius * cos(PI * (i + x) / bands); + float start_y = radius * sin(PI * (i + x) / bands); + + float bandAmplitude; + if (i < bands) { + bandAmplitude = fft.getBand(i); + } else { + bandAmplitude = fft.getFreq(i); + } + hue += 0.5; + if (hue > 255) { + hue = 0; + } + int currentColor = color(hue, 255, 255, 100); + int nextColor = color(hue + 1, 255, 255, 100); + int blendedColor = lerpColor(currentColor, nextColor, bandAmplitude / 2); + fill(blendedColor); + noStroke(); + + float angle = PI * (i + x) / bands; + float arcWidth = 20 + bandAmplitude * 2; + float arcHeight = 20 + bandAmplitude * 2; + + pushMatrix(); + translate(start_x, start_y); + rotate(angle); + arc(0, 0, arcWidth, arcHeight, 0, PI); + popMatrix(); + } + break; + } + + } + +} diff --git a/java/src/ie/tudublin/Audio1.java b/java/src/ie/tudublin/Audio1.java new file mode 100644 index 000000000..80dd24a62 --- /dev/null +++ b/java/src/ie/tudublin/Audio1.java @@ -0,0 +1,270 @@ +/*package ie.tudublin; + + + +import ddf.minim.AudioBuffer; +import ddf.minim.AudioInput; +import ddf.minim.AudioPlayer; +import ddf.minim.Minim; +import processing.core.PApplet; +import ddf.minim.analysis.*; +//import ddf.minim.*; +//import ddf.minim.signals.*; + + +public class Audio1 extends PApplet +{ + Minim minim; + AudioPlayer ap; + AudioInput ai; + AudioBuffer ab; + FFT fft; + Minim m; + + float n4; + float n6; + + float radius1 = 150; + float radius2 = 75; + + + int mode = 0; + + float y = 0; + float smoothedY = 0; + float smoothedAmplitude = 0; + float[] spectrum = new float[512]; + Planet[] planets = new Planet[4]; + + public void keyPressed() { + if (key >= '0' && key <= '9') { + mode = key - '0'; + } + if (keyCode == ' ') { + if (ap.isPlaying()) { + ap.pause(); + } else { + ap.rewind(); + ap.play(); + } + } + } + + public void settings() + { + size(1024, 1000); + //fullScreen(P3D, SPAN); + noStroke(); + } + + public void setup() + { + minim = new Minim(this); + //Uncomment this to use the microphone + //ai = minim.getLineIn(Minim.MONO, width, 44100, 16); + //ab = ai.mix; + + // And comment the next two lines out + ap = minim.loadFile("java/data/horizon.mp3", 1024); + ap.play(); + ab = ap.mix; + colorMode(HSB); + noCursor(); + smooth(); + frameRate(24); + + y = height / 2; + smoothedY = y; + + /* for (int i = 0; i < planets.length; i++ ) { + planets[i] = new Plane(); + } + } + + float off = 0; + + float lerpedBuffer[] = new float[1024];*/ + + /*public void draw() + { + } + /* //background(0); + float halfH = height / 2; + float average = 0; + float sum = 0; + off += 1; + + + // Calculate sum and average of the samples + // Also lerp each element of buffer; + for(int i = 0 ; i < ab.size() ; i ++) + { + sum += abs(ab.get(i)); + lerpedBuffer[i] = lerp(lerpedBuffer[i], ab.get(i), 0.1f); + } + average= sum / (float) ab.size(); + + smoothedAmplitude = lerp(smoothedAmplitude, average, 0.1f); + + //float cx = width / 2; + //float cy = height / 2; + + + switch (mode) { + case 0: + background(0); + for(int i = 0 ; i < ab.size() ; i ++) + { + //float c = map(ab.get(i), -1, 1, 0, 255); + float c = map(i, 0, ab.size(), 0, 255); + stroke(c, 255, 255); + float f = lerpedBuffer[i] * halfH * 4.0f; + line(i, halfH + f, i, halfH - f); + } + break; + case 1: + background(0); + int from = color(255, 0, 0); + int to = color(0, 255); + int c1 = lerpColor(from, to, (float) 0.33); + int c2 = lerpColor(from, to, (float) 0.66); + for (int i = 0; i < 15; i++) { + fill(from); + quad( + random(-40, 220), random(height), + random(-40, 220), random(height), + random(-40, 220), random(height), + random(-40, 220), random(height) + ); + fill(c1); + quad( + random(140, 380), random(height), + random(140, 380), random(height), + random(140, 380), random(height), + random(140, 380), random(height) + ); + fill(c2); + quad( + random(320, 580), random(height), + random(320, 580), random(height), + random(320, 580), random(height), + random(320, 580), random(height) + ); + fill(to); + quad( + random(500, 760), random(height), + random(500, 760), random(height), + random(500, 760), random(height), + random(500, 760), random(height) + ); + frameRate(5); + } + + break; + case 2: + background(0); + for(int i = 0 ; i < ab.size() ; i ++) + { + float c = map(i, 0, ab.size(), mouseX /2, mouseY/ 2); + stroke(c, 255, 255); + float f = lerpedBuffer[i] * halfH * 4.0f; + line(0, i, f, i); + line(width, i, width - f, i); + line(i, 0, i, f); + line(i, height, i, height - f); + } + break; + + case 3: + background(0); + fill(0,50); + noStroke(); + rect(0, 0, width, height); + translate(width/2, height/2); + + for (int i = 0; i < ap.bufferSize() - 1; i++) { + + float angle = sin(i+n4)* 10; + float angle2 = sin(i+n6)* 300; + + float x = sin(radians(i))*(angle2+30); + float y = cos(radians(i))*(angle2+30); + + float x3 = sin(radians(i))*(500/angle); + float y3 = cos(radians(i))*(500/angle); + + fill (0, 0, 0, 90); //yellow + ellipse(x, y, ap.left.get(i)*10, ap.left.get(i)*10); + + fill ( 255, 255, 255, 60); //wt + rect(x3, y3, ap.left.get(i)*20, ap.left.get(i)*10); + + fill ( 255, 152, 0, 90); //orange + rect(x, y, ap.right.get(i)*10, ap.left.get(i)*10); + + fill( 255, 255, 255, 70); //wt + rect(x3, y3, ap.right.get(i)*10, ap.right.get(i)*20); + } + + n4 += 0.008; + n6 += 0.04; + break; + + case 4: + noStroke(); + noCursor(); + + fill(0, 100); + rect(0, 0, width, height); + fill(255); + translate(width / 2, height / 2); + for(int ang1 = 0; ang1 < 360; ang1 +=5) + { + float radian1 = radians(ang1); + pushMatrix(); + translate(radius1 * cos(radian1), radius1 * sin(radian1)); + for(float ang2 = 0; ang2 < 90; ang2 += 10){ + float radian2 = (float) (radians(ang2) - frameCount * 0.02 + radian1); + ellipse(radius2 * cos(radian2), radius2 * sin(radian2), 2, 2); + } + + popMatrix(); + saveFrame("line-######.png"); + break; + }*/ + + + /*case 4: + background(0); + int n=0; + translate (width/2,height/2); + for (int i = 0; i < ap. bufferSize () - 2; i++) { + rotate(n*-PI/200*0.1); + fill (255,0,0) ; + ellipse(i,i,ap. left.get (i) *50,ap. left.get (i) *50) ; + } n++; + break; + + }*/ + + + // Other examples we made in the class + /* + stroke(255); + fill(100, 255, 255); + + circle(width / 2, halfH, lerpedA * 100); + + circle(100, y, 50); + y += random(-10, 10); + smoothedY = lerp(smoothedY, y, 0.1f); + circle(200, smoothedY, 50); + + + } + } + + + + +*/ \ No newline at end of file diff --git a/java/src/ie/tudublin/Main.java b/java/src/ie/tudublin/Main.java index 27489f824..c95031c3e 100644 --- a/java/src/ie/tudublin/Main.java +++ b/java/src/ie/tudublin/Main.java @@ -1,21 +1,17 @@ package ie.tudublin; -import example.CubeVisual; -import example.MyVisual; -import example.RotatingAudioBands; - public class Main -{ +{ + + - public void startUI() + public static void Assignment() { String[] a = {"MAIN"}; - processing.core.PApplet.runSketch( a, new MyVisual()); - } - + processing.core.PApplet.runSketch( a, new Assignment()); + } public static void main(String[] args) { - Main main = new Main(); - main.startUI(); + Assignment(); } } \ No newline at end of file diff --git a/java/tomp3.cc - Miguel Sure Thing sped up_256kbps.mp3 b/java/tomp3.cc - Miguel Sure Thing sped up_256kbps.mp3 new file mode 100644 index 000000000..ba243ab08 Binary files /dev/null and b/java/tomp3.cc - Miguel Sure Thing sped up_256kbps.mp3 differ diff --git a/surething.mp3 b/surething.mp3 new file mode 100644 index 000000000..05e4bb13e Binary files /dev/null and b/surething.mp3 differ