Skip to content

Instantly share code, notes, and snippets.

@tado
Last active December 8, 2015 21:24
Show Gist options
  • Save tado/3e478fd114646b960e17 to your computer and use it in GitHub Desktop.
Save tado/3e478fd114646b960e17 to your computer and use it in GitHub Desktop.
Processing Beads library Granular synthesis
import beads.*;
import java.util.Arrays;
AudioContext ac;
GranularSamplePlayer player;
void setup() {
size(800, 600);
ac = new AudioContext();
Sample sample = SampleManager.sample(dataPath("Violet.mp3"));
player = new GranularSamplePlayer(ac, sample);
player.setLoopType(SamplePlayer.LoopType.LOOP_FORWARDS);
Gain g = new Gain(ac, 2, 1.0);
g.addInput(player);
ac.out.addInput(g);
ac.start();
}
void draw() {
background(0);
if (player != null) {
float rate = map(mouseX, 0, width, 0.0, 3.0);
Static rateValue = new Static(ac, rate);
player.setRate(rateValue);
float speed = map(mouseY, 0, height, 0.0, 3.0);
Static speedValue = new Static(ac, speed);
player.setPitch(speedValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment