{ "source": "JSON", "data": "BLOCK", "version": "0.0.1", "type": "javascript.oscillator", "language": "javascript", "extension": "webaudio", "help": "Sound output", "label": "Oscillator", "color": "#D3C124", "group": "Sound", "codes": [ { "name": "declaration", "code": "\n// block_$id$ = Oscillator\nvar block_$id$ = context.createOscillator();\nvar $port[osc_freq]$ = block_$id$.frequency;\nvar $port[sound]$ = block_$id$;\nvar $port[freq]$ = function(value){\n block_$id$.frequency.value = value;\n};\n\nvar $port[type]$ = function(value){\n oscillator = ''\n if (value < 1) oscillator = 'square';\n if (value == 1) oscillator = 'sine';\n if (value == 2) oscillator = 'sawtooth';\n if (value > 2) oscillator = 'triangle';\n block_$id$.type = oscillator;\n};\n" }, { "name": "execution", "code": "\nblock_$id$.type = '$prop[type]$';\nblock_$id$.frequency.value = $prop[freq]$; // value in hertz\nblock_$id$.detune.value = 100; // value in cents\nblock_$id$.start(0);\n" } ], "properties": [ { "name": "freq", "label": "Frequency", "type": "Float", "lower": 0, "upper": 20000, "step": 1, "value": 440 }, { "name": "type", "label": "Type", "type": "Combo", "values": [ "square", "sine", "sawtooth", "triangle" ], "value": "sine" } ], "ports": [ { "conn_type": "input", "name": "osc_freq", "label": "Osc Frequency", "type": "javascript.sound" }, { "conn_type": "input", "name": "freq", "label": "Frequency", "type": "javascript.float" }, { "conn_type": "input", "name": "type", "label": "Type", "type": "javascript.float" }, { "conn_type": "output", "name": "sound", "label": "Sound", "type": "javascript.sound" } ] }