Commit 4475c6bc authored by Joseph Larralde's avatar Joseph Larralde
Browse files

started adding some basic waves-audio examples

parent 982d8ddf
......@@ -48,4 +48,6 @@ flycheck_*.el
# directory configuration
.dir-locals.el
**/.DS_Store
# End of https://www.gitignore.io/api/emacs
\ No newline at end of file
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="./assets/waves-audio.min.js"></script>
<script src="./assets/waves-loaders.min.js"></script>
</head>
<body>
<canvas width="100%" height="100%"></canvas>
<script type="text/javascript">
(function() {
var audioContext = wavesAudio.audioContext;
var loader = new wavesLoaders.AudioBufferLoader(); // instantiate loader
var audioFile = './assets/amen.mp3';
loader.load(audioFile).then(function(loaded) {
var frac = loaded.duration / 8;
var posArray = [];
var durArray = [];
for (var i = 0; i < 8; i++) {
posArray.push(i * frac);
durArray.push(frac);
}
var scheduler = wavesAudio.getScheduler();
var segEngine = new wavesAudio.SegmentEngine({
buffer: loaded,
periodAbs: loaded.duration / 8,
periodRel: 0,
positionArray: posArray,
durationArray: durArray,
});
segEngine.connect(audioContext.destination);
scheduler.add(segEngine);
setInterval(function() {
segEngine.segmentIndex = Math.floor(Math.random() * 8);
}, frac * 1000);
});
})();
</script>
</body>
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="./assets/waves-audio.min.js"></script>
<script src="./assets/waves-loaders.min.js"></script>
</head>
<body>
<canvas width="100%" height="100%"></canvas>
<script type="text/javascript">
(function() {
var audioContext = wavesAudio.audioContext;
var loader = new wavesLoaders.AudioBufferLoader(); // instantiate loader
var audioFile = './assets/amen.mp3';
loader.load(audioFile).then(function(loaded) {
var scheduler = wavesAudio.getScheduler();
var gEngine = new wavesAudio.GranularEngine({
buffer: loaded
});
var gain = audioContext.createGain();
gEngine.periodAbs = 0.01; // 10 ms
gEngine.durationAbs = 0.12; // 120 ms
var x = 0, y = 0, prevx = 0, prevy = 0, dx = 0, dy = 0, speed = 0;
// update granular parameters from mouse position
document.addEventListener('mousemove', function(e) {
x = e.x;
y = e.y;
var normX = e.x / window.innerWidth;
gEngine.position = gEngine.buffer.duration * normX;
var normY = e.y / window.innerHeight;
gEngine.resampling = normY * -2400 + 1200;
}, false);
// control gain from mouse speed
// (todo : improve speed calculation with delta time in some way)
setInterval(function() {
dx = x - prevx;
dy = y - prevy;
prevx = x;
prevy = y;
speed = Math.sqrt(dx * dx + dy * dy);
gain.gain.value = Math.min(speed * 0.1, 1);
}, 20);
gEngine.connect(gain);
gain.connect(audioContext.destination);
scheduler.add(gEngine);
});
})();
</script>
</body>
This diff is collapsed.
This diff is collapsed.
Markdown is supported
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