Skip to content

Instantly share code, notes, and snippets.

import "core-js/stable";
import "regenerator-runtime/runtime";
import { render, html, nothing } from 'lit/html.js';
import { resumeAudioContext } from '@ircam/resume-audio-context';
import { getTime } from '@ircam/sc-gettime';
import { Scheduler, Transport, MTCSend, MTCReceive } from '../../../src/index.js';
import '@ircam/simple-components/sc-bang.js';
import '@ircam/simple-components/sc-clock.js';
function quantize(val, precision = 1e-9) {
return Math.round(val / precision) * precision;
}
// works by reference
function swap(arr, i1, i2) {
const tmp = arr[i1];
arr[i1] = arr[i2];
arr[i2] = tmp;
}
@b-ma
b-ma / main.rs
Last active November 5, 2023 09:46
Struct drops itself in GC
use llq::{Node, Queue};
struct AudioRenderer {
is_real_node: bool,
garbage_collector: Option<llq::Producer<Self>>,
garbage_node: Option<llq::Node<Self>>,
}
impl AudioRenderer {
fn new(garbage_collector: llq::Producer<Self>) -> Self {
use web_audio_api::context::{AudioContext, AudioContextOptions, BaseAudioContext};
use web_audio_api::media_devices;
use web_audio_api::media_devices::{enumerate_devices_sync, MediaDeviceInfo, MediaDeviceInfoKind};
use web_audio_api::media_devices::{MediaStreamConstraints, MediaTrackConstraints};
use web_audio_api::node::AudioNode;
fn ask_source_id() -> Option<String> {
println!("Enter the input 'device_id' and press <Enter>");
println!("- Use 0 for the default audio input device");
/**
* Simple Linear Regression for 2 dimensionnal data
*
* @param {Array<Array>} observations - data
*/
function simpleLinearRegression(observations) {
// means
let xSum = 0;
let ySum = 0;
const length = observations.length;
export default class Scheduler {
constructor(ctx, period = 0.025, lookahead = 0.1) {
this.queue = [];
this.ctx = ctx;
this.period = period;
this.lookahead = lookahead;
this.tick = this.tick.bind(this);
// @todo - launch only if there is somthing to do
@b-ma
b-ma / index.html
Created November 11, 2015 20:30
have fun with buffer
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<button>play/pause</button>
<script>
var audioCtx = new AudioContext();
@b-ma
b-ma / index.html
Last active November 11, 2015 20:30
transport buttons
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Transport Buttons</title>
<link rel="stylesheet" type="text/css" href="./transport-btns.css" />
</head>
<body>
<code>Play/Pause Button</code>
@b-ma
b-ma / orthogonal-data.js
Last active August 29, 2015 14:23
Simple model to keep orthogonal representation of data in sync
class OrthogonalData {
constructor() {
this._cols = null; // object of arrays
this._rows = null; // array of objects
}
// verify that data are consistents
_checkConsistency() {
let size = null;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>css</title>
<style>
a {
display: block;
border :1px solid #787878;
width: 300px;