Skip to content

Instantly share code, notes, and snippets.

@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;
@b-ma
b-ma / utils.js
Created June 19, 2014 13:14
filesystem node utilities
/**
* find recursively in a given folder for a given pattern into file names
* returns an array of matching files
*/
var fs = require('fs'),
path = require('path'),
util = require('util');
@b-ma
b-ma / jquery-placeholder.js
Created May 7, 2014 09:35
jquery AMD placeholder plugin
define([
'jquery'
], function($) {
'use strict';
// extends $.support
// http://stackoverflow.com/questions/3937818/how-to-test-if-the-browser-supports-the-native-placeholder-attribute
$.support.placeholder = (function() {
var input = document.createElement( 'input' );