Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfarahmand/e5b895446879c71661e267c68067c636 to your computer and use it in GitHub Desktop.
Save benfarahmand/e5b895446879c71661e267c68067c636 to your computer and use it in GitHub Desktop.
Binaural Beat Generation, Creating an Illusory Sound with Processing
//this code will generate two different frequencies in each ear
//which is then experienced as a third frequency that exists due to
//the brain listening to both
//need to be wearing headphones for this to work correctly
import processing.sound.*;
SinOsc[] sines;
float f = 7.0;//freqeuncy of illusory sound
void setup() {
size(640, 360);
background(255);
sines = new SinOsc[2];
for(int i = 0 ; i < sines.length ; i++){
sines[i] = new SinOsc(this);
sines[i].freq(100+i*f);
if(i%2==0) sines[i].pan(-1.0);
else sines[i].pan(1.0);
sines[i].amp(0.4);
sines[i].play();
}
}
float downtime = 60*1000*5.0; //transition time from start freq to end freq
//the draw function will start at a higher illusory frequency and then
//make its way down to the ending frequency over the course of some time
//denoted by downtime
void draw() {
int m = millis();
float freq = 2.5; //ending frequency
if(m for(int i = 0 ; i < sines.length ; i++){
sines[i].freq(100+i*freq);
}
println(freq);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment