This file contains 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 const AudioContext = window.AudioContext || window.webkitAudioContext; | |
const myContext = new AudioContext(); |
This file contains 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 methodPatch = { | |
start(source) { | |
return (source.start) ? source.start : (startTime = 0) => source.noteOn(startTime); | |
}, | |
stop(source) { | |
return (source.stop) ? source.stop : (stopTime = 0) => source.noteOff(stopTime); | |
}, | |
}; | |
export default methodPatch; |
This file contains 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 methodPatch from './method-patch'; | |
export default class MobileAudioFix { | |
constructor(context) { | |
this.context = context; | |
this.source = this.context.createBufferSource(); | |
// now fill that buffer with an extremely brief and silent sound | |
this.source.buffer = this.context.createBuffer(1, 1, 22050); | |
// and connect it to the context destination (audio output speakers) | |
this.source.connect(this.context.destination); |
This file contains 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 fetchAudioBuffer(path, context) { | |
const audioRequest = new Request(path); | |
return fetch(audioRequest).then((response) => { | |
return response.arrayBuffer(); | |
}).then((arrayBuffer) => { | |
return context.decodeAudioData(arrayBuffer); | |
}).catch((error) => { | |
throw Error(`Asset failed to load: ${error.message}`); | |
}); |
This file contains 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'; | |
import methodPatch from './helpers/method-patch'; | |
import MobileAudioFix from './helpers/mobile-audio-fix'; | |
// All of my MP3s were built to be a consistent volume on export, | |
// so I can safely set the same gain on all of them. | |
const singleGain = 0.6; | |
const assetPaths = { | |
cubeUp: 'assets/audio/cube-up.mp3', |
This file contains 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 AnimationFeature() { | |
const target1 = document.getElementById('AnimationCube1'); | |
// ...more targets... | |
target1.addEventListener('mouseenter', () => { | |
SoundFx.Single.play('animationUp1'); | |
}); |
This file contains 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 context = new AudioContext(); | |
const oscNode = context.createOscillator(); | |
const gainNode = context.createGain(); | |
oscNode.connect(gainNode); | |
gainNode.connect(context.destination); | |
oscNode.start(); | |
oscNode.stop(1); |
This file contains 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 duration = 0.2; | |
const volume = { | |
min: 0.001, | |
max: 1, | |
}; | |
gainNode.gain.setValueAtTime( | |
volume.min, | |
context.currentTime | |
); |
This file contains 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 up = { | |
wave: 'sine', | |
freq: { | |
start: 392, | |
end: 493.88, | |
}, | |
volume: 1, | |
duration: 0.2, | |
}; |
This file contains 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 synthPresets from './helpers/synth-presets'; | |
import methodPatch from './helpers/method-patch'; | |
import MobileAudioFix from './helpers/mobile-audio-fix'; | |
const initialGain = 0.001; | |
export default class Synth { | |
static synthKeys = Object.keys(synthPresets); | |
constructor() { |
OlderNewer