Skip to content

Instantly share code, notes, and snippets.

Last active Feb 19, 2019
What would you like to do?
oscillator component
import { h, Component } from 'preact';
import style from './style';
const audioContext = new (window.AudioContext || window.webkitAudioContext);
export default class Oscillator extends Component {
play() {
if( this.oscillator ) return;
this.oscillator = audioContext.createOscillator();
this.oscillator.type = this.props.type || 'sine';
this.oscillator.frequency.value = this.props.frequency || 329.63; //E(1) is default
stop() {
if(!this.oscillator) return;
this.oscillator = null;
render() {
return (
<div class={style.home}>
<td><button onClick={}>start</button></td>
<td><button onClick={this.stop.bind(this)}>stop</button></td>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment