46 changed files with 6592 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,42 @@ |
|||||
|
|
||||
|
#include <SPI.h> |
||||
|
#include <nRF24L01.h> |
||||
|
#include <RF24.h> |
||||
|
|
||||
|
RF24 radio(8, 9); |
||||
|
|
||||
|
const uint64_t rAddress[] = {0x7878787878LL, 0xB3B4B5B6F1LL}; |
||||
|
|
||||
|
void setup(){ |
||||
|
|
||||
|
Serial.begin(9600); |
||||
|
radio.begin(); |
||||
|
|
||||
|
radio.setPALevel(RF24_PA_LOW); |
||||
|
radio.setChannel(108); |
||||
|
|
||||
|
radio.openReadingPipe(0,rAddress[0]); |
||||
|
radio.openReadingPipe(1,rAddress[1]); |
||||
|
radio.startListening(); |
||||
|
} |
||||
|
|
||||
|
void loop(){ |
||||
|
|
||||
|
int pipes = 2; |
||||
|
int16_t data[] = {0,0,0,0,0,0}; |
||||
|
|
||||
|
for(byte p=0; p<pipes; p++){ |
||||
|
if(radio.available(p)){ |
||||
|
|
||||
|
radio.read( &data, sizeof(data) ); |
||||
|
for(byte i=0; i<6; i++){ |
||||
|
Serial.print(data[i]); |
||||
|
Serial.print("\t"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Serial.println(); |
||||
|
delay(200); |
||||
|
} |
||||
|
|
@ -0,0 +1,52 @@ |
|||||
|
|
||||
|
#include <SPI.h> |
||||
|
#include <nRF24L01.h> |
||||
|
#include <RF24.h> |
||||
|
|
||||
|
#define WHICH_NODE 2 |
||||
|
|
||||
|
RF24 radio(8, 9); |
||||
|
const uint64_t wAddress[] = {0x7878787878LL, 0xB3B4B5B6F1LL}; //, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL};
|
||||
|
const uint64_t PTXpipe = wAddress[ WHICH_NODE - 1 ]; |
||||
|
byte counter = 1; |
||||
|
bool done = false; |
||||
|
|
||||
|
void setup(){ |
||||
|
|
||||
|
Serial.begin(9600); |
||||
|
radio.begin(); |
||||
|
radio.setPALevel(RF24_PA_LOW); |
||||
|
radio.setChannel(108); |
||||
|
radio.openReadingPipe(0,PTXpipe); |
||||
|
radio.stopListening(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void loop(){ |
||||
|
|
||||
|
if(!done){ |
||||
|
byte randNumber = 222; |
||||
|
int16_t data[] = {7,8,9,10,11,12}; |
||||
|
|
||||
|
radio.openWritingPipe(PTXpipe); |
||||
|
|
||||
|
if(!radio.write( &data, sizeof(data) )){ |
||||
|
|
||||
|
Serial.println("Guess delivery failed"); |
||||
|
|
||||
|
}else{ |
||||
|
|
||||
|
for(int i=0; i<sizeof(data); i++){ |
||||
|
Serial.print(data[i]); |
||||
|
Serial.print("\t"); |
||||
|
} |
||||
|
|
||||
|
Serial.println(); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
delay(200); |
||||
|
|
||||
|
} |
@ -0,0 +1,85 @@ |
|||||
|
// An example demonstrating the multiceiver capability of the NRF24L01+
|
||||
|
// in a star network with one PRX hub and up to six PTX nodes
|
||||
|
//This sketch is a modification from a video on the ForceTronics YouTube Channel,
|
||||
|
//which code was leveraged from http://maniacbug.github.io/RF24/starping_8pde-example.html
|
||||
|
//This sketch is free to the public to use and modify at your own risk
|
||||
|
|
||||
|
#include <SPI.h> //Call SPI library so you can communicate with the nRF24L01+ |
||||
|
#include <nRF24L01.h> //nRF2401 libarary found at https://github.com/tmrh20/RF24/ |
||||
|
#include <RF24.h> //nRF2401 libarary found at https://github.com/tmrh20/RF24/ |
||||
|
|
||||
|
#define WHICH_NODE 2 // must be a number from 1 - 6 identifying the PTX node
|
||||
|
|
||||
|
RF24 radio(8, 9); // Create your nRF24 object or wireless SPI connection
|
||||
|
|
||||
|
const uint64_t wAddress[] = {0x7878787878LL, 0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL}; |
||||
|
const uint64_t PTXpipe = wAddress[ WHICH_NODE - 1 ]; // Pulls the address from the above array for this node's pipe
|
||||
|
byte counter = 1; //used to count the packets sent
|
||||
|
bool done = false; //used to know when to stop sending packets
|
||||
|
|
||||
|
void setup(){ |
||||
|
|
||||
|
Serial.begin(9600); //start serial to communicate process
|
||||
|
randomSeed(analogRead(0)); //create unique seed value for random number generation
|
||||
|
radio.begin(); //Start the nRF24 module
|
||||
|
radio.setPALevel(RF24_PA_LOW); // "short range setting" - increase if you want more range AND have a good power supply
|
||||
|
radio.setChannel(108); // the higher channels tend to be more "open"
|
||||
|
radio.openReadingPipe(0,PTXpipe); //open reading or receive pipe
|
||||
|
radio.stopListening(); //go into transmit mode
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
void loop(){ |
||||
|
|
||||
|
if(!done){ //true once you guess the right number
|
||||
|
byte randNumber = 222;//(byte)random(11); //generate random guess between 0 and 10
|
||||
|
radio.openWritingPipe(PTXpipe); //open writing or transmit pipe
|
||||
|
|
||||
|
if(!radio.write( &randNumber, 1 )){ //if the write fails let the user know over serial monitor
|
||||
|
|
||||
|
Serial.println("Guess delivery failed"); |
||||
|
|
||||
|
}else{ //if the write was successful
|
||||
|
|
||||
|
Serial.print("Success sending guess: "); |
||||
|
Serial.println(randNumber); |
||||
|
|
||||
|
radio.startListening(); //switch to receive mode to see if the guess was right
|
||||
|
unsigned long startTimer = millis(); //start timer, we will wait 200ms
|
||||
|
bool timeout = false; |
||||
|
|
||||
|
while(!radio.available() && !timeout){ //run while no receive data and not timed out
|
||||
|
|
||||
|
if(millis() - startTimer > 200) timeout = true; //timed out
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
if(timeout){ |
||||
|
|
||||
|
Serial.println("Last guess was wrong, try again"); //no data to receive guess must have been wrong
|
||||
|
|
||||
|
}else{ //we received something so guess must have been right
|
||||
|
|
||||
|
byte daNumber; //variable to store received value
|
||||
|
radio.read( &daNumber,1); //read value
|
||||
|
|
||||
|
if(daNumber == randNumber) { //make sure it equals value we just sent, if so we are done
|
||||
|
|
||||
|
Serial.println("You guessed right so you are done"); |
||||
|
done = true; //signal to loop that we are done guessing
|
||||
|
|
||||
|
}else{ |
||||
|
Serial.println("Something went wrong, keep guessing"); //this should never be true, but just in case
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
radio.stopListening(); //go back to transmit mode
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
delay(200); |
||||
|
|
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
|
||||
|
|
||||
|
#include <SPI.h> |
||||
|
#include <nRF24L01.h> |
||||
|
#include <RF24.h> |
||||
|
|
||||
|
RF24 radio(8, 9); // CE, CSN
|
||||
|
|
||||
|
const byte addressL[6] = "00001"; |
||||
|
const byte addressR[6] = "00002"; |
||||
|
|
||||
|
int16_t dataL[6], dataR[6]; |
||||
|
|
||||
|
void setup() { |
||||
|
Serial.begin(9600); |
||||
|
radio.begin(); |
||||
|
radio.openReadingPipe(1, addressL); |
||||
|
radio.openReadingPipe(2, addressR); |
||||
|
radio.setPALevel(RF24_250KBPS); |
||||
|
radio.startListening(); |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
if (radio.available()) { |
||||
|
|
||||
|
radio.read(&dataL, sizeof(dataL)); |
||||
|
|
||||
|
for(int i=0; i<6; i++){ |
||||
|
Serial.print(dataL[i]); |
||||
|
Serial.print("\t"); |
||||
|
} |
||||
|
|
||||
|
delay(50); |
||||
|
radio.read(&dataR, sizeof(dataR)); |
||||
|
|
||||
|
for(int i=0; i<6; i++){ |
||||
|
Serial.print(dataR[i]); |
||||
|
Serial.print("\t"); |
||||
|
} |
||||
|
|
||||
|
Serial.println(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
|
||||
|
#include "I2Cdev.h" |
||||
|
#include "MPU6050.h" |
||||
|
|
||||
|
#include <SPI.h> |
||||
|
#include <nRF24L01.h> |
||||
|
#include <RF24.h> |
||||
|
|
||||
|
RF24 radio(8, 9); // CE, CSN
|
||||
|
|
||||
|
const byte address[6] = "00001"; |
||||
|
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE |
||||
|
#include "Wire.h" |
||||
|
#endif |
||||
|
|
||||
|
MPU6050 accelgyro; |
||||
|
//MPU6050 accelgyro(0x69); // <-- use for AD0 high
|
||||
|
|
||||
|
int16_t ax, ay, az; |
||||
|
int16_t gx, gy, gz; |
||||
|
|
||||
|
#define OUTPUT_READABLE_ACCELGYRO |
||||
|
|
||||
|
void setup() { |
||||
|
radio.begin(); |
||||
|
radio.openWritingPipe(address); |
||||
|
radio.setPALevel(RF24_250KBPS); |
||||
|
radio.stopListening(); |
||||
|
|
||||
|
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE |
||||
|
Wire.begin(); |
||||
|
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE |
||||
|
Fastwire::setup(400, true); |
||||
|
#endif |
||||
|
|
||||
|
Serial.begin(9600); |
||||
|
|
||||
|
// initialize device
|
||||
|
Serial.println("Initializing I2C devices..."); |
||||
|
accelgyro.initialize(); |
||||
|
|
||||
|
// verify connection
|
||||
|
Serial.println("Testing device connections..."); |
||||
|
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); |
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
|
||||
|
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); |
||||
|
|
||||
|
#ifdef OUTPUT_READABLE_ACCELGYRO |
||||
|
Serial.print("a/g:\t"); |
||||
|
Serial.print(ax); Serial.print("\t"); |
||||
|
Serial.print(ay); Serial.print("\t"); |
||||
|
Serial.print(az); Serial.print("\t"); |
||||
|
Serial.print(gx); Serial.print("\t"); |
||||
|
Serial.print(gy); Serial.print("\t"); |
||||
|
Serial.println(gz); |
||||
|
#endif |
||||
|
|
||||
|
int16_t dataL[] = {ax, |
||||
|
ay, |
||||
|
az, |
||||
|
gx, |
||||
|
gy, |
||||
|
gz}; |
||||
|
|
||||
|
radio.write(&dataL, sizeof(dataL)); |
||||
|
delay(100); |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
|
||||
|
#include <SPI.h> |
||||
|
#include <nRF24L01.h> |
||||
|
#include <RF24.h> |
||||
|
|
||||
|
RF24 radio(8, 9); // CE, CSN
|
||||
|
|
||||
|
const byte address[6] = "00002"; |
||||
|
|
||||
|
void setup() { |
||||
|
radio.begin(); |
||||
|
radio.openWritingPipe(address); |
||||
|
radio.setPALevel(RF24_250KBPS); |
||||
|
radio.stopListening(); |
||||
|
|
||||
|
Serial.begin(9600); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void loop() { |
||||
|
|
||||
|
|
||||
|
int16_t dataR[] = {1,2,3,4,5,6}; |
||||
|
|
||||
|
for(int i=0; i<6; i++){ |
||||
|
Serial.print(dataR[i]); |
||||
|
Serial.print("\t"); |
||||
|
} |
||||
|
Serial.println(); |
||||
|
|
||||
|
radio.write(&dataR, sizeof(dataR)); |
||||
|
delay(100); |
||||
|
} |
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
After Width: | Height: | Size: 94 KiB |
Binary file not shown.
@ -0,0 +1,35 @@ |
|||||
|
|
||||
|
import arb.soundcipher.*; |
||||
|
import oscP5.*; |
||||
|
import netP5.*; |
||||
|
|
||||
|
OscP5 oscP5; |
||||
|
SoundCipher sc = new SoundCipher(this); |
||||
|
|
||||
|
int tempo = 10000; |
||||
|
int inst[] = {0,4,32,98,113,116,126}; |
||||
|
int selInst = 0; |
||||
|
int selTempo = 0; |
||||
|
|
||||
|
int tempos[] = {2,4,8,16}; |
||||
|
int beatsCount[] = {1,1,1,1}; |
||||
|
float freqs[] = {0,0,0,0}; |
||||
|
int instruments[] = {0,0,0,0}; |
||||
|
|
||||
|
void setup() { |
||||
|
size(900, 300); |
||||
|
|
||||
|
oscP5 = new OscP5(this,7000); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
|
||||
|
background(125); |
||||
|
//sc.instrument(selInst); |
||||
|
//sc.pan(mouseX); |
||||
|
//sc.playNote( mouseY, 50,1); |
||||
|
|
||||
|
displayTempo(); |
||||
|
delay(tempo/16); |
||||
|
} |
@ -0,0 +1,69 @@ |
|||||
|
int OSCleftButton = 0; |
||||
|
int OSCrightButton = 0; |
||||
|
int tmpButton = 0; |
||||
|
float OSCleftX = 0; |
||||
|
float OSCleftY = 0; |
||||
|
float OSCrightX = 0; |
||||
|
float OSCrightY = 0; |
||||
|
float OSCvalue = 0; |
||||
|
|
||||
|
void oscEvent(OscMessage theOscMessage) { |
||||
|
|
||||
|
if(theOscMessage.checkTypetag("s")){ |
||||
|
OSCvalue = parseFloat(theOscMessage.get(0).toString().replaceAll(",",".")); |
||||
|
} |
||||
|
|
||||
|
switch(theOscMessage.addrPattern()) { |
||||
|
case "lb": |
||||
|
tmpButton = theOscMessage.get(0).intValue(); |
||||
|
if(OSCleftButton != tmpButton) { |
||||
|
OSCleftButton = tmpButton; |
||||
|
} |
||||
|
|
||||
|
break; |
||||
|
case "/lx": |
||||
|
OSCleftX = OSCvalue; |
||||
|
freqs[OSCleftButton-1] = OSCvalue; |
||||
|
break; |
||||
|
case "/ly": |
||||
|
OSCleftY = OSCvalue; |
||||
|
instruments[OSCleftButton-1] = parseInt(OSCleftX)/2; |
||||
|
break; |
||||
|
|
||||
|
case "rb": |
||||
|
OSCrightButton = theOscMessage.get(0).intValue(); |
||||
|
break; |
||||
|
case "/rx": |
||||
|
OSCrightX = OSCvalue; |
||||
|
break; |
||||
|
case "/ry": |
||||
|
OSCrightY = OSCvalue; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
printOSC(false, theOscMessage); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void printOSC(boolean show, OscMessage theOscMessage) { |
||||
|
|
||||
|
if(show) { |
||||
|
print("### Pattern: "+theOscMessage.addrPattern()); |
||||
|
print(" TypeTag:"+theOscMessage.typetag()); |
||||
|
if(theOscMessage.checkTypetag("i")){ |
||||
|
print(" Value: "+theOscMessage.get(0).intValue()); |
||||
|
} |
||||
|
if(theOscMessage.checkTypetag("s")){ |
||||
|
OSCvalue = parseFloat(theOscMessage.get(0).toString().replaceAll(",",".")); |
||||
|
print(" Value: "+OSCvalue); |
||||
|
} |
||||
|
println(); |
||||
|
} |
||||
|
|
||||
|
print(OSCleftButton+"\t"); |
||||
|
print(OSCrightButton+"\t"); |
||||
|
print(OSCleftX+"\t"); |
||||
|
print(OSCleftY+"\t"); |
||||
|
print(OSCrightX+"\t"); |
||||
|
println(OSCrightY+"\t"); |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
void displayTempo(){ |
||||
|
|
||||
|
for(int x = 0; x < tempos.length; x++){ |
||||
|
|
||||
|
if(beatsCount[x] < tempos[x]){ |
||||
|
beatsCount[x]++; |
||||
|
}else{ |
||||
|
beatsCount[x] = 1; |
||||
|
sc.instrument(instruments[x]); |
||||
|
sc.playNote(freqs[x], 50, 2); |
||||
|
} |
||||
|
|
||||
|
for( int i = 1; i <= tempos[x]; i++) { |
||||
|
if(i==beatsCount[x]){ |
||||
|
fill(200); |
||||
|
} else { |
||||
|
fill(100); |
||||
|
} |
||||
|
ellipse(50*i, (x+1)*50, 40, 40); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
void keyPressed() { |
||||
|
|
||||
|
int k = key - 48; |
||||
|
|
||||
|
switch(key){ |
||||
|
case '+': |
||||
|
tempo = tempo + 100; |
||||
|
break; |
||||
|
case '-': |
||||
|
tempo = tempo - 100; |
||||
|
break; |
||||
|
|
||||
|
/* |
||||
|
case 'z': |
||||
|
freqSet = 0; |
||||
|
break; |
||||
|
case 'x': |
||||
|
freqSet = 1; |
||||
|
break; |
||||
|
case 'c': |
||||
|
freqSet = 2; |
||||
|
break; |
||||
|
case 'v': |
||||
|
freqSet = 3; |
||||
|
break; |
||||
|
*/ |
||||
|
|
||||
|
default: |
||||
|
if(k<7){ |
||||
|
selInst = inst[k]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
System.out.println(key); |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
/** |
||||
|
* In this example, a WhiteNoise generator (equal amount of noise at all frequencies) is |
||||
|
* passed through a BandPass filter. You can control both the central frequency |
||||
|
* (left/right) as well as the bandwidth of the filter (up/down) with the mouse. The |
||||
|
* position and size of the circle indicates how much of the noise's spectrum passes |
||||
|
* through the filter, and at what frequency range. |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
WhiteNoise noise; |
||||
|
BandPass filter; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
|
||||
|
// Create the noise generator + Filter |
||||
|
noise = new WhiteNoise(this); |
||||
|
filter = new BandPass(this); |
||||
|
|
||||
|
noise.play(0.5); |
||||
|
filter.process(noise); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Map the left/right mouse position to a cutoff frequency between 20 and 10000 Hz |
||||
|
float frequency = map(mouseX, 0, width, 20, 10000); |
||||
|
// And the vertical mouse position to the width of the band to be passed through |
||||
|
float bandwidth = map(mouseY, 0, height, 1000, 100); |
||||
|
|
||||
|
filter.freq(frequency); |
||||
|
filter.bw(bandwidth); |
||||
|
|
||||
|
// Draw a circle indicating the position + width of the frequency window |
||||
|
// that is allowed to pass through |
||||
|
background(125, 255, 125); |
||||
|
noStroke(); |
||||
|
fill(255, 0, 150); |
||||
|
ellipse(mouseX, height, 2*(height - mouseY), 2*(height - mouseY)); |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
|
||||
|
import arb.soundcipher.*; |
||||
|
|
||||
|
SoundCipher sc = new SoundCipher(this); |
||||
|
int tempo = 1; |
||||
|
int inst[] = {0,0,14,44}; |
||||
|
int selInst = 0; |
||||
|
|
||||
|
void setup() { |
||||
|
//frameRate(5); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
|
||||
|
background(125); |
||||
|
//line(random(width), random(height), mouseX, mouseY); |
||||
|
sc.instrument(selInst); |
||||
|
//sc.pan(mouseX); |
||||
|
sc.playNote( mouseY, 50,1); |
||||
|
delay(tempo); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void mousePressed() { |
||||
|
tempo = mouseY * 10; |
||||
|
System.out.println(mouseX); |
||||
|
//frameRate(fr); |
||||
|
} |
||||
|
|
||||
|
void keyPressed() { |
||||
|
|
||||
|
int k = key - 48; |
||||
|
|
||||
|
if(key == '+') { |
||||
|
selInst = selInst + 1; |
||||
|
} else if(key == '-') { |
||||
|
selInst = selInst - 1; |
||||
|
} else { |
||||
|
selInst = inst[k]; |
||||
|
} |
||||
|
|
||||
|
System.out.println(k); |
||||
|
} |
Binary file not shown.
@ -0,0 +1,67 @@ |
|||||
|
/** |
||||
|
* A drum pattern generator that creates a 4 beat pattern, |
||||
|
* playtes it then generates another 4 beat pattern, and so on. |
||||
|
* SoundCipher's callback facility is used to provide the loop |
||||
|
* regeneration notification at the end of the pattern. |
||||
|
* Simple drawing in time with the music is triggered by callbacks also. |
||||
|
* |
||||
|
* A SoundCipher example by Andrew R. Brown |
||||
|
*/ |
||||
|
|
||||
|
import arb.soundcipher.*; |
||||
|
|
||||
|
SCScore score = new SCScore(); |
||||
|
float[] r = new float[4]; |
||||
|
|
||||
|
void setup() { |
||||
|
noLoop(); |
||||
|
score.tempo(112); |
||||
|
score.addCallbackListener(this); |
||||
|
makeMusic(); |
||||
|
} |
||||
|
|
||||
|
void makeMusic() { |
||||
|
score.empty(); |
||||
|
for (float i=0; i<16; i++) { |
||||
|
if (i%8 == 0 || i%16 == 14) { |
||||
|
score.addNote(i/4, 9, 0, 36, 100, 0.25, 0.8, 64); |
||||
|
score.addCallback(i/4, 1); |
||||
|
} else if (random(10) < 1) score.addNote(i/4, 9, 0, 36, 70, 0.25, 0.8, 64); |
||||
|
if (i%8 == 4) { |
||||
|
score.addNote(i/4, 9, 0, 38, 100, 0.25, 0.8, 64); |
||||
|
score.addCallback(i/4, 2); |
||||
|
} else if (random(10) < 2) score.addNote(i/4, 9, 0, 38, 60, 0.25, 0.8, 64); |
||||
|
if(random(10) < 8) { |
||||
|
score.addNote(i/4, 9, 0, 42, random(40) + 70, 0.25, 0.8, 64); |
||||
|
} else score.addNote(i/4, 9, 0, 46, 80, 0.25, 0.8, 64); |
||||
|
} |
||||
|
score.addCallback(4, 0); |
||||
|
score.play(); |
||||
|
} |
||||
|
|
||||
|
void handleCallbacks(int callbackID) { |
||||
|
switch (callbackID) { |
||||
|
case 0: |
||||
|
score.stop(); |
||||
|
makeMusic(); |
||||
|
break; |
||||
|
case 1: |
||||
|
float w = random(20); |
||||
|
r = new float[] {50-w, 50-w, w*2, w*2}; |
||||
|
redraw(); |
||||
|
break; |
||||
|
case 2: |
||||
|
r = new float[] {20, 20, 60, 60}; |
||||
|
redraw(); |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
background(120); |
||||
|
rect(r[0], r[1], r[2], r[3]); |
||||
|
} |
||||
|
|
||||
|
void stop() { |
||||
|
score.stop(); |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
class Blip { |
||||
|
// color |
||||
|
color shade; |
||||
|
// vertical position on screen |
||||
|
float position; |
||||
|
// width |
||||
|
float size; |
||||
|
|
||||
|
Blip( color c, float p, float s ) { |
||||
|
shade = c; |
||||
|
position = p; |
||||
|
size = s; |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
fill( shade ); |
||||
|
rect( width/2, position, size, 10 ); |
||||
|
} |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
class MidiReceiver implements Receiver { |
||||
|
void close() {} |
||||
|
|
||||
|
void send( MidiMessage msg, long timeStamp ) { |
||||
|
// we only care about NoteOn midi messages. |
||||
|
// here's how you check for that |
||||
|
if ( msg instanceof ShortMessage ) { |
||||
|
ShortMessage sm = (ShortMessage)msg; |
||||
|
// if you want to handle messages other than NOTE_ON, you can refer to the constants defined in |
||||
|
// ShortMessage: http://docs.oracle.com/javase/6/docs/api/javax/sound/midi/ShortMessage.html |
||||
|
// And figure out what Data1 and Data2 will be, refer to the midi spec: http://www.midi.org/techspecs/midimessages.php |
||||
|
if ( sm.getCommand() == ShortMessage.NOTE_ON ) { |
||||
|
// note number, between 1 and 127 |
||||
|
int note = sm.getData1(); |
||||
|
// velocity, between 1 and 127 |
||||
|
int vel = sm.getData2(); |
||||
|
// we could also use sm.getChannel() to do something different depending on the channel of the message |
||||
|
|
||||
|
// see below the draw method for the definition of this sound generating Instrument |
||||
|
|
||||
|
System.out.println(note); |
||||
|
out.playNote( 0, 0.1f, new Synth( note, vel ) ); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,76 @@ |
|||||
|
|
||||
|
import ddf.minim.*; |
||||
|
import ddf.minim.ugens.*; |
||||
|
import javax.sound.midi.*; |
||||
|
|
||||
|
Minim minim; |
||||
|
AudioOutput out; |
||||
|
|
||||
|
Sequencer sequencer; |
||||
|
Sequence sequence; |
||||
|
|
||||
|
ArrayList<Blip> blips; |
||||
|
|
||||
|
|
||||
|
void setup() { |
||||
|
size( 640, 480 ); |
||||
|
|
||||
|
minim = new Minim(this); |
||||
|
out = minim.getLineOut(); |
||||
|
|
||||
|
try { |
||||
|
|
||||
|
sequencer = MidiSystem.getSequencer( false ); |
||||
|
|
||||
|
// have to open it |
||||
|
sequencer.open(); |
||||
|
|
||||
|
// load our sequence |
||||
|
sequence = MidiSystem.getSequence( createInput( "bassline.MID" ) ); |
||||
|
|
||||
|
// put it in the sequencer |
||||
|
sequencer.setSequence( sequence ); |
||||
|
|
||||
|
// set the tempo |
||||
|
sequencer.setTempoInBPM( 128 ); |
||||
|
|
||||
|
// hook up an instance of our Receiver to the Sequencer's Transmitter |
||||
|
sequencer.getTransmitter().setReceiver( new MidiReceiver() ); |
||||
|
|
||||
|
// just keep looping |
||||
|
sequencer.setLoopCount( Sequencer.LOOP_CONTINUOUSLY ); |
||||
|
|
||||
|
// and away we go |
||||
|
sequencer.start(); |
||||
|
} |
||||
|
catch( MidiUnavailableException ex ) // getSequencer can throw this |
||||
|
{ |
||||
|
// oops there wasn't one. |
||||
|
println( "No default sequencer, sorry bud." ); |
||||
|
} |
||||
|
catch( InvalidMidiDataException ex ) // getSequence can throw this |
||||
|
{ |
||||
|
// oops, the file was bad |
||||
|
println( "The midi file was hosed or not a midi file, sorry bud." ); |
||||
|
} |
||||
|
catch( IOException ex ) // getSequence can throw this |
||||
|
{ |
||||
|
println( "Had a problem accessing the midi file, sorry bud." ); |
||||
|
} |
||||
|
|
||||
|
// and we need to make our Blip list |
||||
|
blips = new ArrayList<Blip>(); |
||||
|
// and set our drawing preferences |
||||
|
rectMode( CENTER ); |
||||
|
} |
||||
|
|
||||
|
void draw() |
||||
|
{ |
||||
|
background( 20 ); |
||||
|
|
||||
|
// just draw all the Blips! |
||||
|
for( int i = 0; i < blips.size(); ++i ) |
||||
|
{ |
||||
|
blips.get(i).draw(); |
||||
|
} |
||||
|
} |
@ -0,0 +1,33 @@ |
|||||
|
class Synth implements ddf.minim.ugens.Instrument { |
||||
|
Oscil wave; |
||||
|
Damp env; |
||||
|
int noteNumber; |
||||
|
Blip blip; |
||||
|
|
||||
|
Synth( int note, int velocity ) { |
||||
|
noteNumber = note; |
||||
|
float freq = Frequency.ofMidiNote( noteNumber ).asHz(); |
||||
|
float amp = (float)(velocity-1) / 126.0f; |
||||
|
|
||||
|
wave = new Oscil( freq, amp, Waves.SQUARE ); |
||||
|
env = new Damp( 0.001f, 0.1f, 1.0f ); |
||||
|
|
||||
|
wave.patch( env ); |
||||
|
} |
||||
|
|
||||
|
void noteOn( float dur ) { |
||||
|
// make visual |
||||
|
color c = color( 0, 200, 64, 255*(wave.amplitude.getLastValue()) ); |
||||
|
blip = new Blip( c, map(noteNumber, 30, 55, height, 0), 200 ); |
||||
|
blips.add( blip ); |
||||
|
|
||||
|
// make sound |
||||
|
env.activate(); |
||||
|
env.patch( out ); |
||||
|
} |
||||
|
|
||||
|
void noteOff() { |
||||
|
env.unpatchAfterDamp( out ); |
||||
|
blips.remove( blip ); |
||||
|
} |
||||
|
} |
Binary file not shown.
@ -0,0 +1,35 @@ |
|||||
|
/** |
||||
|
* This is a simple white noise generator. White noise has equal power at all |
||||
|
* frequencies. The high frequencies can make it very grating to the ear. |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
WhiteNoise noise; |
||||
|
PinkNoise pnoise; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
background(255); |
||||
|
|
||||
|
// Create and start the noise generator |
||||
|
noise = new WhiteNoise(this); |
||||
|
noise.play(); |
||||
|
pnoise = new PinkNoise(this); |
||||
|
pnoise.play(); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Map mouseX from -1.0 to 1.0 for left to right |
||||
|
noise.pan(map(mouseX, 0, width, -1.0, 1.0)); |
||||
|
noise.amp(map(mouseY, 0, height, 0, 1.0)); |
||||
|
|
||||
|
// Map mouseY from 0.0 to 0.3 for amplitude |
||||
|
// (the higher the mouse position, the louder the sound) |
||||
|
noise.pan(map(mouseX, 0, width, -1.0, 1.0)); |
||||
|
noise.amp(map(mouseY, 0, height, 0, 1.0)); |
||||
|
|
||||
|
|
||||
|
pnoise.pan(map(mouseX, 0, width, -1.0, 1.0)); |
||||
|
pnoise.amp(map(mouseY, 0, height, 0.5, 0.0)); |
||||
|
} |
@ -0,0 +1,26 @@ |
|||||
|
/** |
||||
|
* This is a simple pink noise generator. The energy of pink noise falls off at 3 dB |
||||
|
* per octave, which puts it somewhere between White and Brownian noise. |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
PinkNoise noise; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
background(255); |
||||
|
|
||||
|
// Create and start noise generator |
||||
|
noise = new PinkNoise(this); |
||||
|
noise.play(); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Map mouseX from -1.0 to 1.0 for left to right |
||||
|
noise.pan(map(mouseX, 0, width, -1.0, 1.0)); |
||||
|
|
||||
|
// Map mouseY from 0.0 to 0.5 for amplitude |
||||
|
// (the higher the mouse position, the louder the sound) |
||||
|
noise.amp(map(mouseY, 0, height, 0.5, 0.0)); |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
import processing.sound.*; |
||||
|
|
||||
|
Pulse pulse; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
background(255); |
||||
|
|
||||
|
// Create and start the pulse wave oscillator |
||||
|
pulse = new Pulse(this); |
||||
|
// pulse waves can appear very loud to the human ear, so make it a bit more quiet |
||||
|
pulse.amp(0.3); |
||||
|
pulse.play(); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Map mouseX from 20Hz to 500Hz for frequency |
||||
|
float frequency = map(mouseX, 0, width, 1.0, 100.0); |
||||
|
pulse.freq(frequency); |
||||
|
// Map mouseY from 0.0 to 1.0 for the relative width of the pulse. |
||||
|
float pulseWidth = map(mouseY, 0, height, 0.0, 1.0); |
||||
|
pulse.width(pulseWidth); |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
/** |
||||
|
* Play a sound sample and apply a reverb filter to it, changing the effect |
||||
|
* parameters based on the mouse position. |
||||
|
* |
||||
|
* With the mouse pointer at the top of the sketch you'll only hear the "dry" |
||||
|
* (unprocessed) signal, move the mouse downwards to add more of the "wet" |
||||
|
* reverb signal to the mix. The left-right position of the mouse controls the |
||||
|
* "room size" and damping of the effect, with a smaller room (and more refraction) |
||||
|
* at the left, and a bigger (but more dampened) room towards the right. |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
SoundFile soundfile; |
||||
|
Reverb reverb; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
background(255); |
||||
|
|
||||
|
// Load a soundfile |
||||
|
soundfile = new SoundFile(this, "vibraphon.aiff"); |
||||
|
|
||||
|
// Create the effect object |
||||
|
reverb = new Reverb(this); |
||||
|
|
||||
|
// Play the file in a loop |
||||
|
soundfile.loop(); |
||||
|
|
||||
|
// Set soundfile as input to the reverb |
||||
|
reverb.process(soundfile); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Change the roomsize of the reverb |
||||
|
float roomSize = map(mouseX, 0, width, 0, 1.0); |
||||
|
reverb.room(roomSize); |
||||
|
|
||||
|
// Change the high frequency dampening parameter |
||||
|
float damping = map(mouseX, 0, width, 0, 1.0); |
||||
|
reverb.damp(damping); |
||||
|
|
||||
|
// Change the wet/dry relation of the effect |
||||
|
float effectStrength = map(mouseY, 0, height, 0, 1.0); |
||||
|
reverb.wet(effectStrength); |
||||
|
} |
Binary file not shown.
@ -0,0 +1,55 @@ |
|||||
|
/** |
||||
|
* This example shows how to create a cluster of sine oscillators, change the frequency |
||||
|
* and detune them relative to each other depending on the position of the mouse in the |
||||
|
* renderer window. The Y position determines the basic frequency of the oscillators, |
||||
|
* the X position their detuning. The basic frequncy ranges between 150 and 1150 Hz. |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
SinOsc[] sineWaves; |
||||
|
|
||||
|
// The number of oscillators |
||||
|
int numSines = 5; |
||||
|
|
||||
|
// A float for calculating the amplitudes |
||||
|
float[] sineVolume; |
||||
|
|
||||
|
void setup() { |
||||
|
size(500, 500); |
||||
|
background(255); |
||||
|
|
||||
|
// Create the oscillators and amplitudes |
||||
|
sineWaves = new SinOsc[numSines]; |
||||
|
sineVolume = new float[numSines]; |
||||
|
|
||||
|
for (int i = 0; i < numSines; i++) { |
||||
|
|
||||
|
// The overall amplitude shouldn't exceed 1.0 which is prevented by 1.0/numSines. |
||||
|
// The ascending waves will get lower in volume the higher the frequency. |
||||
|
sineVolume[i] = (1.0 / numSines) / (i + 1); |
||||
|
|
||||
|
// Create the Sine Oscillators and start them |
||||
|
sineWaves[i] = new SinOsc(this); |
||||
|
sineWaves[i].play(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
noStroke(); |
||||
|
|
||||
|
// Map mouseY to get values from 0.0 to 1.0 |
||||
|
float yoffset = (height - mouseY) / float(height); |
||||
|
|
||||
|
// Map that value logarithmically to 150 - 1150 Hz |
||||
|
float frequency = pow(1000, yoffset) + 150; |
||||
|
|
||||
|
// Map mouseX from -0.5 to 0.5 to get a multiplier for detuning the oscillators |
||||
|
float detune = float(mouseX) / width - 0.5; |
||||
|
|
||||
|
// Set the frequencies, detuning and volume |
||||
|
for (int i = 0; i < numSines; i++) { |
||||
|
sineWaves[i].freq(frequency * (i + 1 + i * detune)); |
||||
|
sineWaves[i].amp(sineVolume[i]); |
||||
|
} |
||||
|
} |
@ -0,0 +1,100 @@ |
|||||
|
/** |
||||
|
* This sketch demonstrates how to create synthesized sound with Minim |
||||
|
* using an AudioOutput and an Oscil. An Oscil is a UGen object, |
||||
|
* one of many different types included with Minim. By using |
||||
|
* the numbers 1 thru 5, you can change the waveform being used |
||||
|
* by the Oscil to make sound. These basic waveforms are the |
||||
|
* basis of much audio synthesis. |
||||
|
* |
||||
|
* For many more examples of UGens included with Minim, |
||||
|
* have a look in the Synthesis folder of the Minim examples. |
||||
|
* <p> |
||||
|
* For more information about Minim and additional features, |
||||
|
* visit http://code.compartmental.net/minim/ |
||||
|
*/ |
||||
|
|
||||
|
import ddf.minim.*; |
||||
|
import ddf.minim.ugens.*; |
||||
|
|
||||
|
Minim minim; |
||||
|
AudioOutput out; |
||||
|
Oscil wave; |
||||
|
|
||||
|
void setup() |
||||
|
{ |
||||
|
size(512, 200, P3D); |
||||
|
|
||||
|
minim = new Minim(this); |
||||
|
|
||||
|
// use the getLineOut method of the Minim object to get an AudioOutput object |
||||
|
out = minim.getLineOut(); |
||||
|
|
||||
|
// create a sine wave Oscil, set to 440 Hz, at 0.5 amplitude |
||||
|
wave = new Oscil( 440, 0.5f, Waves.SINE ); |
||||
|
// patch the Oscil to the output |
||||
|
wave.patch( out ); |
||||
|
} |
||||
|
|
||||
|
void draw() |
||||
|
{ |
||||
|
background(0); |
||||
|
stroke(255); |
||||
|
strokeWeight(1); |
||||
|
|
||||
|
// draw the waveform of the output |
||||
|
for(int i = 0; i < out.bufferSize() - 1; i++) |
||||
|
{ |
||||
|
line( i, 50 - out.left.get(i)*50, i+1, 50 - out.left.get(i+1)*50 ); |
||||
|
line( i, 150 - out.right.get(i)*50, i+1, 150 - out.right.get(i+1)*50 ); |
||||
|
} |
||||
|
|
||||
|
// draw the waveform we are using in the oscillator |
||||
|
stroke( 128, 0, 0 ); |
||||
|
strokeWeight(4); |
||||
|
for( int i = 0; i < width-1; ++i ) |
||||
|
{ |
||||
|
point( i, height/2 - (height*0.49) * wave.getWaveform().value( (float)i / width ) ); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void mouseMoved() |
||||
|
{ |
||||
|
// usually when setting the amplitude and frequency of an Oscil |
||||
|
// you will want to patch something to the amplitude and frequency inputs |
||||
|
// but this is a quick and easy way to turn the screen into |
||||
|
// an x-y control for them. |
||||
|
|
||||
|
float amp = map( mouseY, 0, height, 1, 0 ); |
||||
|
wave.setAmplitude( amp ); |
||||
|
|
||||
|
float freq = map( mouseX, 0, width, 110, 880 ); |
||||
|
wave.setFrequency( freq ); |
||||
|
} |
||||
|
|
||||
|
void keyPressed() |
||||
|
{ |
||||
|
switch( key ) |
||||
|
{ |
||||
|
case '1': |
||||
|
wave.setWaveform( Waves.SINE ); |
||||
|
break; |
||||
|
|
||||
|
case '2': |
||||
|
wave.setWaveform( Waves.TRIANGLE ); |
||||
|
break; |
||||
|
|
||||
|
case '3': |
||||
|
wave.setWaveform( Waves.SAW ); |
||||
|
break; |
||||
|
|
||||
|
case '4': |
||||
|
wave.setWaveform( Waves.SQUARE ); |
||||
|
break; |
||||
|
|
||||
|
case '5': |
||||
|
wave.setWaveform( Waves.QUARTERPULSE ); |
||||
|
break; |
||||
|
|
||||
|
default: break; |
||||
|
} |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
/** |
||||
|
* Play a sound sample and pass it through a tape delay, changing the delay |
||||
|
* parameters based on the mouse position. |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
SoundFile soundfile; |
||||
|
Delay delay; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
background(255); |
||||
|
|
||||
|
// Load a soundfile |
||||
|
soundfile = new SoundFile(this, "vibraphon.aiff"); |
||||
|
|
||||
|
// Create the delay effect |
||||
|
delay = new Delay(this); |
||||
|
|
||||
|
// Play the file in a loop |
||||
|
soundfile.loop(); |
||||
|
|
||||
|
// Connect the soundfile to the delay unit, which is initiated with a |
||||
|
// five second "tape" |
||||
|
delay.process(soundfile, 5.0); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Map mouseX from -1.0 to 1.0 for left to right panning |
||||
|
float position = map(mouseX, 0, width, -1.0, 1.0); |
||||
|
soundfile.pan(position); |
||||
|
|
||||
|
// Map mouseX from 0 to 0.8 for the amount of delay feedback |
||||
|
float fb = map(mouseX, 0, width, 0.0, 0.8); |
||||
|
delay.feedback(fb); |
||||
|
|
||||
|
// Map mouseY from 0.001 to 2.0 seconds for the length of the delay |
||||
|
float delayTime = map(mouseY, 0, height, 0.001, 2.0); |
||||
|
delay.time(delayTime); |
||||
|
} |
Binary file not shown.
@ -0,0 +1,81 @@ |
|||||
|
/* frequencyModulation |
||||
|
<p> |
||||
|
A simple example for doing FM (frequency modulation) using two Oscils. |
||||
|
<p> |
||||
|
For more information about Minim and additional features, |
||||
|
visit http://code.compartmental.net/minim/ |
||||
|
<p> |
||||
|
Author: Damien Di Fede |
||||
|
*/ |
||||
|
|
||||
|
// import everything necessary to make sound. |
||||
|
import ddf.minim.*; |
||||
|
import ddf.minim.ugens.*; |
||||
|
|
||||
|
// create all of the variables that will need to be accessed in |
||||
|
// more than one methods (setup(), draw(), stop()). |
||||
|
Minim minim; |
||||
|
AudioOutput out; |
||||
|
|
||||
|
// the Oscil we use for modulating frequency. |
||||
|
Oscil fm; |
||||
|
|
||||
|
// setup is run once at the beginning |
||||
|
void setup() |
||||
|
{ |
||||
|
// initialize the drawing window |
||||
|
size( 512, 200, P3D ); |
||||
|
|
||||
|
// initialize the minim and out objects |
||||
|
minim = new Minim( this ); |
||||
|
out = minim.getLineOut(); |
||||
|
|
||||
|
// make the Oscil we will hear. |
||||
|
// arguments are frequency, amplitude, and waveform |
||||
|
Oscil wave = new Oscil( 200, 0.8, Waves.TRIANGLE ); |
||||
|
// make the Oscil we will use to modulate the frequency of wave. |
||||
|
// the frequency of this Oscil will determine how quickly the |
||||
|
// frequency of wave changes and the amplitude determines how much. |
||||
|
// since we are using the output of fm directly to set the frequency |
||||
|
// of wave, you can think of the amplitude as being expressed in Hz. |
||||
|
fm = new Oscil( 10, 2, Waves.SINE ); |
||||
|
// set the offset of fm so that it generates values centered around 200 Hz |
||||
|
fm.offset.setLastValue( 200 ); |
||||
|
// patch it to the frequency of wave so it controls it |
||||
|
fm.patch( wave.frequency ); |
||||
|
// and patch wave to the output |
||||
|
wave.patch( out ); |
||||
|
} |
||||
|
|
||||
|
// draw is run many times |
||||
|
void draw() |
||||
|
{ |
||||
|
// erase the window to black |
||||
|
background( 0 ); |
||||
|
// draw using a white stroke |
||||
|
stroke( 255 ); |
||||
|
// draw the waveforms |
||||
|
for( int i = 0; i < out.bufferSize() - 1; i++ ) |
||||
|
{ |
||||
|
// find the x position of each buffer value |
||||
|
float x1 = map( i, 0, out.bufferSize(), 0, width ); |
||||
|
float x2 = map( i+1, 0, out.bufferSize(), 0, width ); |
||||
|
// draw a line from one buffer position to the next for both channels |
||||
|
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); |
||||
|
line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); |
||||
|
} |
||||
|
|
||||
|
text( "Modulation frequency: " + fm.frequency.getLastValue(), 5, 15 ); |
||||
|
text( "Modulation amplitude: " + fm.amplitude.getLastValue(), 5, 30 ); |
||||
|
} |
||||
|
|
||||
|
// we can change the parameters of the frequency modulation Oscil |
||||
|
// in real-time using the mouse. |
||||
|
void mouseMoved() |
||||
|
{ |
||||
|
float modulateAmount = map( mouseY, 0, height, 220, 1 ); |
||||
|
float modulateFrequency = map( mouseX, 0, width, 0.1, 100 ); |
||||
|
|
||||
|
fm.setFrequency( modulateFrequency ); |
||||
|
fm.setAmplitude( modulateAmount ); |
||||
|
} |
@ -0,0 +1,84 @@ |
|||||
|
/* moogFilterExample<br/> |
||||
|
* is an example of using a MoogFilter to filter white noise.<br/> |
||||
|
* Use the mouse to control the cutoff frequency and resonance of the filter.<br/> |
||||
|
* Press 1 to set it to low pass<br/> |
||||
|
* Press 2 to set it to high pass<br/> |
||||
|
* Press 3 to set it to band pass<br/> |
||||
|
* <p> |
||||
|
* For more information about Minim and additional features, |
||||
|
* visit http://code.compartmental.net/minim/ |
||||
|
* <p> |
||||
|
* author: Damien Di Fede |
||||
|
*/ |
||||
|
|
||||
|
// import everything necessary to make sound. |
||||
|
import ddf.minim.*; |
||||
|
import ddf.minim.ugens.*; |
||||
|
|
||||
|
// create all of the variables that will need to be accessed in |
||||
|
// more than one methods (setup(), draw(), stop()). |
||||
|
Minim minim; |
||||
|
AudioOutput out; |
||||
|
MoogFilter moog; |
||||
|
|
||||
|
// setup is run once at the beginning |
||||
|
void setup() |
||||
|
{ |
||||
|
// initialize the drawing window |
||||
|
size(300, 300); |
||||
|
|
||||
|
// initialize the minim and out objects |
||||
|
minim = new Minim(this); |
||||
|
out = minim.getLineOut(); |
||||
|
// construct a law pass MoogFilter with a |
||||
|
// cutoff frequency of 1200 Hz and a resonance of 0.5 |
||||
|
moog = new MoogFilter( 1200, 0.5 ); |
||||
|
|
||||
|
// we will filter a white noise source, |
||||
|
// which will allow us to hear the result of filtering |
||||
|
Noise noize = new Noise( 0.5f ); |
||||
|
|
||||
|
// send the noise through the filter |
||||
|
noize.patch( moog ).patch( out ); |
||||
|
} |
||||
|
|
||||
|
// we'll control the frequency and resonance of the filter |
||||
|
// using the position of the mouse, in typical x-y controller fashion |
||||
|
void mouseMoved() |
||||
|
{ |
||||
|
float freq = constrain( map( mouseX, 0, width, 200, 12000 ), 200, 12000 ); |
||||
|
float rez = constrain( map( mouseY, height, 0, 0, 1 ), 0, 1 ); |
||||
|
|
||||
|
moog.frequency.setLastValue( freq ); |
||||
|
moog.resonance.setLastValue( rez ); |
||||
|
} |
||||
|
|
||||
|
void keyPressed() |
||||
|
{ |
||||
|
if ( key == '1' ) moog.type = MoogFilter.Type.LP; |
||||
|
if ( key == '2' ) moog.type = MoogFilter.Type.HP; |
||||
|
if ( key == '3' ) moog.type = MoogFilter.Type.BP; |
||||
|
} |
||||
|
|
||||
|
// draw is run many times |
||||
|
void draw() |
||||
|
{ |
||||
|
// erase the window to black |
||||
|
background( 0 ); |
||||
|
// draw using a white stroke |
||||
|
stroke( 255 ); |
||||
|
// draw the waveforms |
||||
|
for( int i = 0; i < out.bufferSize() - 1; i++ ) |
||||
|
{ |
||||
|
// find the x position of each buffer value |
||||
|
float x1 = map( i, 0, out.bufferSize(), 0, width ); |
||||
|
float x2 = map( i+1, 0, out.bufferSize(), 0, width ); |
||||
|
// draw a line from one buffer position to the next for both channels |
||||
|
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); |
||||
|
line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); |
||||
|
} |
||||
|
|
||||
|
text( "Filter type: " + moog.type, 10, 225 ); |
||||
|
text( "Filter cutoff: " + moog.frequency.getLastValue() + " Hz", 10, 245 ); |
||||
|
text( "Filter resonance: " + moog.resonance.getLastValue(), 10, 265 ); |
||||
|
} |
@ -0,0 +1,73 @@ |
|||||
|
/* liveInputExample<br/> |
||||
|
is an example of using a Vocoder UGen on a LiveInput UGen. |
||||
|
This should let you hear the input from your microphone turned into a robot voice. |
||||
|
<p> |
||||
|
For more information about Minim and additional features, |
||||
|
visit http://code.compartmental.net/minim/ |
||||
|
<p> |
||||
|
author: Damien Di Fede |
||||
|
*/ |
||||
|
|
||||
|
import ddf.minim.*; |
||||
|
import ddf.minim.ugens.*; |
||||
|
import ddf.minim.spi.*; // for AudioStream |
||||
|
|
||||
|
Minim minim; |
||||
|
AudioOutput out; |
||||
|
LiveInput in; |
||||
|
|
||||
|
void setup() |
||||
|
{ |
||||
|
// initialize the drawing window |
||||
|
size(512, 200); |
||||
|
|
||||
|
// initialize the minim and out objects |
||||
|
minim = new Minim(this); |
||||
|
out = minim.getLineOut(); |
||||
|
|
||||
|
// construct a LiveInput by giving it an InputStream from minim. |
||||
|
// we ask for an input with the same audio properties as the output. |
||||
|
AudioStream inputStream = minim.getInputStream( Minim.MONO, |
||||
|
out.bufferSize(), |
||||
|
out.sampleRate(), |
||||
|
out.getFormat().getSampleSizeInBits() |
||||
|
); |
||||
|
in = new LiveInput( inputStream ); |
||||
|
|
||||
|
// create the vocoder with a 1024 sample frame FFT and 3 overlapping windows |
||||
|
Vocoder vocode = new Vocoder( 1024, 8 ); |
||||
|
|
||||
|
// patch the input into the vocoder modulator |
||||
|
// we want to modulate the synth sound with the mic input, to create that "robot" effect |
||||
|
in.patch( vocode.modulator ); |
||||
|
|
||||
|
// create a synth with two notes an octave apart |
||||
|
Oscil wave1 = new Oscil( 110, 0.8, Waves.SAW ); |
||||
|
Oscil wave2 = new Oscil( 220, 0.4, Waves.SAW ); |
||||
|
|
||||
|
Summer synth = new Summer(); |
||||
|
wave1.patch( synth ); |
||||
|
wave2.patch( synth ); |
||||
|
|
||||
|
// patch it to the input on the vocoder and on to the output |
||||
|
synth.patch( vocode ).patch( out ); |
||||
|
} |
||||
|
|
||||
|
// draw is run many times |
||||
|
void draw() |
||||
|
{ |
||||
|
// erase the window to black |
||||
|
background( 0 ); |
||||
|
// draw using a white stroke |
||||
|
stroke( 255 ); |
||||
|
// draw the waveforms |
||||
|
for( int i = 0; i < out.bufferSize() - 1; i++ ) |
||||
|
{ |
||||
|
// find the x position of each buffer value |
||||
|
float x1 = map( i, 0, out.bufferSize(), 0, width ); |
||||
|
float x2 = map( i+1, 0, out.bufferSize(), 0, width ); |
||||
|
// draw a line from one buffer position to the next for both channels |
||||
|
line( x1, 50 - out.left.get(i)*50, x2, 50 - out.left.get(i+1)*50); |
||||
|
line( x1, 150 - out.right.get(i)*50, x2, 150 - out.right.get(i+1)*50); |
||||
|
} |
||||
|
} |
After Width: | Height: | Size: 97 KiB |
Binary file not shown.
@ -0,0 +1,34 @@ |
|||||
|
/** |
||||
|
* This is a square wave oscillator. The method .play() starts the oscillator. There |
||||
|
* are several setter functions for configuring the oscillator, such as .amp(), |
||||
|
* .freq(), .pan() and .add(). If you want to set all of them at the same time you can |
||||
|
* use .set(float freq, float amp, float add, float pan) |
||||
|
*/ |
||||
|
|
||||
|
import processing.sound.*; |
||||
|
|
||||
|
SqrOsc sqr; |
||||
|
|
||||
|
void setup() { |
||||
|
size(640, 360); |
||||
|
background(255); |
||||
|
|
||||
|
// create and start the oscillator. |
||||
|
sqr = new SqrOsc(this); |
||||
|
sqr.play(); |
||||
|
} |
||||
|
|
||||
|
void draw() { |
||||
|
// Map mouseY from 1.0 to 0.0 for amplitude (mouseY is 0 at the |
||||
|
// top of the sketch, so the higher the mouse position, the louder) |
||||
|
float amplitude = map(mouseY, 0, height, 1.0, 0.0); |
||||
|
sqr.amp(amplitude); |
||||
|
|
||||
|
// Map mouseX from 20Hz to 1000Hz for frequency |
||||
|
float frequency = map(mouseX, 0, width, 20.0, 1000.0); |
||||
|
sqr.freq(frequency); |
||||
|
|
||||
|
// Map mouseX from -1.0 to 1.0 for panning the audio to the left or right |
||||
|
float panning = map(mouseX, 0, width, -1.0, 1.0); |
||||
|
sqr.pan(panning); |
||||
|
} |
After Width: | Height: | Size: 599 KiB |
After Width: | Height: | Size: 9.0 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
Reference in new issue