This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let swappedNode = null; | |
| draggable.on('drag:start', () => { | |
| SoundFx.Synth.play('up'); | |
| }); | |
| draggable.on('swappable:swapped', ({swappedElement}) => { | |
| swappedNode = swappedElement; | |
| SoundFx.Synth.play('swap'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function disabledAudio() { | |
| return null; | |
| } | |
| export default class SoundToggle { | |
| constructor(activator, sounds) { | |
| this.activator = activator; | |
| this.sounds = sounds; | |
| this.keys = Object.keys(sounds); | |
| this.backups = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function distortionCurve(amount = 0) { | |
| const sampleRate = 44100; | |
| const curve = new Float32Array(sampleRate); | |
| const deg = Math.PI / 180; | |
| for (let i = 0; i < sampleRate; ++i) { | |
| const x = (i * 2 / sampleRate) - 1; | |
| curve[i] = ( | |
| ( | |
| (3 + amount) * x * 20 * deg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default function reverseBuffer(buffer, context) { | |
| const reverse = context.createBuffer( | |
| buffer.numberOfChannels, | |
| buffer.length, | |
| buffer.sampleRate | |
| ); | |
| for (let channels = 0; channels < buffer.numberOfChannels; channels++) { | |
| const dest = reverse.getChannelData(channels); | |
| const src = buffer.getChannelData(channels); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _setGain(reverse, duration) { | |
| this.gainNode.gain.setValueAtTime(1, this.context.currentTime); | |
| if (reverse) { | |
| this.gainNode.gain.exponentialRampToValueAtTime(0.5, this.context.currentTime + duration); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const defaultOptions = { | |
| speed: 10, | |
| duration: 1, | |
| volume: { | |
| min: 0.1, | |
| max: 1, | |
| }, | |
| }; | |
| tremolo(options = {}) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const defaultLFO = { | |
| type: 'sine', | |
| freq: 12, | |
| volume: 40, | |
| }; | |
| // Uses same `duration` as "source" oscillator | |
| vibrato(duration, options = {}) { | |
| const config = Object.assign(defaultLFO, options); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fetchAudioBuffer from './helpers/fetch-audio-buffer'; | |
| const zeroGain = 0.001; | |
| const maxGain = 0.6; | |
| const durationRamp = { | |
| up: 0.2, | |
| down: 0.3, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SoundFx from '../../SoundFx'; | |
| export default function AccessibleFeature() { | |
| const target = document.getElementById('AccessibleFeature'); | |
| target.addEventListener('mouseenter', () => { | |
| SoundFx.Accessible.play(); | |
| }); | |
| target.addEventListener('mouseleave', () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| speed(speed = 1) { | |
| // Ramp up faster when increasing speed, slower if decreasing | |
| const duration = (speed > 1) ? durationRamp.up : durationRamp.down; | |
| for (let i = 0; i < this.trackCount; i++) { | |
| this.sources[`source${i}`].playbackRate.exponentialRampToValueAtTime( | |
| speed, | |
| this.context.currentTime + duration | |
| ); | |
| } |