Skip to content
Snippets Groups Projects
Commit ac16982f authored by James Carty's avatar James Carty
Browse files
parents 5c524a6a 4a60f049
Branches
Tags
No related merge requests found
......@@ -22,16 +22,17 @@ float beatDetection::returnBeat() {
}
float beatDetection::returnSnare() {
float beatDetection::returnHiHat() {
float selectedBand = beat.getBand(100);
return selectedBand;
float selectedBand = beat.getBand(100); //returns band 100 as a float, gives a volume for that channel(sometimes works well, may have to use other return)
//float selectedBand = beat.hihat(); //returns a 1 or 0 , is decided whether its 1 or 0 in the fft by averaging a range of the subbands and if they're over a threshold
return selectedBand;
}
void beatDetection::audioReceived(float* input, int bufferSize, int nChannels) {
void beatDetection::audioReceived(float* input, int bufferSize, int nChannels) { //needed for ofxbeatmaster
beat.audioReceived(input, bufferSize, nChannels);
}
......
......@@ -15,7 +15,7 @@ public:
float returnBeat();
float returnSnare();
float returnHiHat();
ofxBeat beat;
ofSoundPlayer song;
......
#include "ofMain.h"
#include "ofApp.h"
#include <stdlib.h>
#include <iostream>
//========================================================================
......
......@@ -15,6 +15,14 @@ void ofApp::setup() {
newBeat.setup(); //initialise FFT / Beat detection
technoVisual.setup();
ofSoundStreamListDevices();
ofEnableSmoothing();
ofSetFrameRate(60); //speed up frame rate
serial.setup("COM6", 57600);
}
//--------------------------------------------------------------
......@@ -30,17 +38,53 @@ void ofApp::draw() {
technoVisual.update(newBeat.returnBeat(),newBeat.returnSnare());
technoVisual.update(newBeat.returnBeat(),newBeat.returnHiHat()); //returned values from functions in beatDetection
//technoVisual.update(x, y); //DEBBUG MODE
ledControl();
}
void ofApp::ledControl() //pointless making another class as most of the calculation is in the
{
//send a byte over a volume threshold to create a 'pulse' in the LEDS, second byte turns them back off
if (newBeat.returnBeat()>16) {
serial.writeByte(1);
}
//if (newBeat.returnHiHat()>5) {
// serial.writeByte(1);
//}
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
if (key == 'a'){
x = 20;
}
else if (key == 's') {
x = 0;
}
else if (key == 'z') {
y = 20;
}
else if (key == 'x') {
y = 0;
}
}
//--------------------------------------------------------------
......@@ -78,6 +122,8 @@ void ofApp::gotMessage(ofMessage msg) {
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo) {
......
......@@ -3,9 +3,11 @@
#include "ofxBeat.h"
#include "beatDetection.h"
#include "techno.h"
#include <stdio.h>
#include <time.h>
#include <dos.h>
#include <windows.h>
#include <stdlib.h>
class ofApp : public ofBaseApp {
......@@ -25,9 +27,26 @@ public:
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void ledControl();
//VISUALS
float x = 0;
float y = 0;
techno technoVisual;
beatDetection newBeat;
//LEDS
bool bSendSerialMessage; // a flag for sending serial
char bytesRead[3]; // data from serial, we will be trying to read 3
char bytesReadString[4]; // a string needs a null terminator, so we need 3 + 1 bytes
int nBytesRead; // how much did we read?
int nTimesRead; // how many times did we read?
float readTime; // when did we last read?
//int greenIncrease = 10;
ofSerial serial;
unsigned char array[4] = { 0,0,0,0 };
};
\ No newline at end of file
......@@ -8,7 +8,7 @@ techno::techno() {
barWidth = ofGetScreenWidth();
barHeight = ofGetScreenHeight()/64;
barHeight = ofGetScreenHeight()/128;
}
......@@ -16,81 +16,182 @@ techno::techno() {
//--------------------------------------------------------------
void techno::setup() {
for (int i = 0; i < 17; i++) {
bars.push_back(i);
}
}
//--------------------------------------------------------------
void techno::update(float value, float snare_value) {
void techno::update(float value, float hihat_value) {
ofBackgroundGradient(0, 15, OF_GRADIENT_CIRCULAR);
ofBackgroundGradient(0, 30, OF_GRADIENT_CIRCULAR);
float snareValue = snare_value;
float flooredValue = value;
if (counter < 16) {
ofSetColor(155);
}
if (flooredValue > 2.5 && prevBeat < 2.2) {
float hiHatValue = hihat_value;
float beatValue = value;
if (beatValue > 16&&prevBeat<15.8) {
counter += g;
if (counter < 32 && counter> 16) {
ofSetColor(ofRandom(0, 255));
}
}
if (value > 5) {
controlVolume = value * 2;
}
else {
controlVolume = value;
}
float z = 5;
//following code creates loops with a counter and loop variable, adjust the value to increase time for each visual
if (counter > 32) {
ofSetColor(155);
counter = 32;
g = g*-1;
loops++;
}
if (counter < 0) {
if (counter < 0) { //sometimes goes beneath 0, not sure why
counter = 0;
g = g*-1;
loops++;
if (loops == 3) {
loops = 0;
}
std::cout << loops << endl;
}
if (loops == 3) { //increase this to add new animation
loops = 0; //resets loop animation so it runs over everything again
}
if (loops == 2) {
//LINE VISUAL
for (int i = 0; i < counter&&i < 16; i++) {
if ((i < 8 && counter>16) || (i < 8 && g == -1)) {
z = 17;
}
else if ((i >= 8 && counter > 16) || (i >= 8 && g == -1)) {
z = 3;
}
ofDrawRectangle(barWidth / z, 50 + (i * 64), barWidth / 1.6, barHeight);
if (loops == 0) { //decide the order of animations with this
for (int i = 0; i<counter&&i < 32; i++) {
ofSetColor(200);
ofDrawRectangle(barWidth / 5, 50 + (i * 32), barWidth / 1.6, barHeight);
}
}
else if (loops == 1) {
for (int i = 0; i < 32; i++) {
ofSetColor(200);
ofDrawRectangle(barWidth / 5, 50 + (i * 32), barWidth / 1.6, barHeight);
}
for (int i = 32; i > 0 && i > counter; i--) {
cam.begin();
glLineWidth(7.);
glRotatef(sin(ofGetElapsedTimeMillis() / 10) * 20, 1.0, 0, 0);
//glRotatef(sin(ofGetElapsedTimeMillis() / 4) * 20, 0, 1.0, 0);
//glRotatef(sin(ofGetElapsedTimeMillis() / 7) * 20, 0, 0, 1.0);
if (beatValue > 16) {
glScalef(1.2, 1.3, 1.4);
}
if (i == 31) {
glLineWidth(7.);
glScalef(0.74, 0.74, 0.74);
glBegin(GL_LINE_LOOP);
glColor3f(.8, .8, .8);
glVertex3f(-250.0f, 250.0f, -250.0f);
glVertex3f(-250.0f, -250.0f, -250.0f);
glVertex3f(-250.0f, -250.0f, 250.0f);
glVertex3f(-250.0f, 250.0f, 250.0f);
glEnd();
}
if (i == 30) {
glLineWidth(7.);
glScalef(0.74, 0.74, 0.74);
glBegin(GL_LINE_LOOP);
glColor3f(.8, .8, .8);
glVertex3f(250.0f, 250.0f, -250.0f);
glVertex3f(250.0f, -250.0f, -250.0f);
glVertex3f(250.0f, -250.0f, 250.0f);
glVertex3f(250.0f, 250.0f, 250.0f);
glEnd();
}
if (i == 29) {
glLineWidth(7.);
glScalef(0.74, 0.74, 0.74);
glBegin(GL_LINES);
glColor3f(.8, .8, .8);
glVertex3f(-250.0f, -250.0f, -250.0f);
glVertex3f(250.0f, -250.0f, -250.0f);
glVertex3f(-250.0f, 250.0f, -250.0f);
glVertex3f(250.0f, 250.0f, -250.0f);
glEnd();
}
if (i == 28) {
glLineWidth(7.);
glScalef(0.74, 0.74, 0.74);
glBegin(GL_LINES);
glVertex3f(-250.0f, 250.0f, 250.0f);
glVertex3f(250.0f, 250.0f, 250.0f);
glEnd();
}
if (i == 27) {
glLineWidth(7.);
glScalef(0.74, 0.74, 0.74);
glBegin(GL_LINES);
glVertex3f(-250.0f, -250.0f, 250.0f);
glVertex3f(250.0f, -250.0f, 250.0f);
glEnd();
}
cam.end();
}
else if (loops == 1) {
cam.begin();
}
if (flooredValue > 2.5) {
//OFFSET TRIANGLE VISUAL
//uses simple opengl geometry to create two triangles, the smaller triangle reacts to hihats, the larger to low end frequencies
else if (loops == 2) {
glLineWidth(3.);
if (hiHatValue >4 ) { //when using beat.getBand(100);
//if (hiHatValue >= 1) { //when using beat.snare();
cam.begin();
glBegin(GL_LINE_LOOP);
glColor3f(0.8f, 0.8f, 0.8f);
glVertex3f(0, 150, 0);
glVertex3f(-100, -50, 0);
glVertex3f(100, -50, 0);
glEnd();
cam.end();
}
if (beatValue > 16) {
cam.begin();
glBegin(GL_LINE_LOOP);
glColor3f(0.8f, 0.8f, 0.8f);
......@@ -100,13 +201,23 @@ void techno::update(float value, float snare_value) {
glVertex3f(-100, -100, 50);
glEnd();
cam.end();
}
cam.end();
}
else if (loops == 0) {
//DEFORMED PLANE VISUAL
//creates two square geometries, and moves them on a hihate
else if (loops == 3) {
glLineWidth(3.);
cam.begin();
if (snareValue > 1) {
if (hiHatValue > 4) { //when using beat.getBand(100);
//if (hiHatValue >= 1) { //when using beat.snare();
//if (beatValue > 2.5) { //on lows/kick instead of hihate
glBegin(GL_LINE_LOOP);
scale = 50;
}
......@@ -144,12 +255,14 @@ void techno::update(float value, float snare_value) {
cam.end();
}
prevBeat = value;
}
//--------------------------------------------------------------
void techno::draw() {
......
......@@ -15,20 +15,20 @@ public:
void setup();
void update(float,float);
void draw();
float controlVolume;
int counter = 0;
private:
int barWidth;
int barHeight;
vector<float> bars;
vector<float> beats;
int counter = 0;
float prevBeat = 0;
ofEasyCam cam;
int i =0;
float scale = 0;
float g = 1;
float loops = 0;
......
......@@ -3,5 +3,15 @@ William Fish, James Carty
OCBOX: A visual and audio experience 2018
The FFT works from sound input, via line/mic in. The effectiveness of the fft
is worsened when music is picked up by a mic. Please try to use Line in via
sound card.
REQUIRED ADDONS;
OFXBEAT MASTER (supplied in repo)
Arduino (code is marked where to remove for function without arduino/LED)
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment