Trying out different sound waves
This commit is contained in:
1 parent
2912061094
commit
58ee03f8a8
4 files changed
+16
-11
No files matched your search
+7
-5
@@ -1,12 +1,14 @@
|
||||
import {SOUND_MUSIC_VOLUME, SOUND_SFX_VOLUME} from './constants.js';
|
||||
|
||||
// @ts-ignore
|
||||
export const audio = new (window.AudioContext || window.webkitAudioContext)();
|
||||
|
||||
export const music = audio.createGain(audio);
|
||||
music.gain.setValueAtTime(0.4, audio.currentTime);
|
||||
music.gain.setValueAtTime(SOUND_MUSIC_VOLUME, audio.currentTime);
|
||||
music.connect(audio.destination);
|
||||
|
||||
export const sfx = audio.createGain(audio);
|
||||
sfx.gain.setValueAtTime(0.05, audio.currentTime);
|
||||
sfx.gain.setValueAtTime(SOUND_SFX_VOLUME, audio.currentTime);
|
||||
sfx.connect(audio.destination);
|
||||
|
||||
export async function createAudioLoop(src) {
|
||||
@@ -21,15 +23,15 @@ export async function createAudioLoop(src) {
|
||||
})
|
||||
}
|
||||
|
||||
export function createOsc() {
|
||||
export function createOsc(type='triangle') {
|
||||
const osc = audio.createOscillator();
|
||||
osc.type = 'triangle';
|
||||
osc.type = type;
|
||||
osc.connect(sfx);
|
||||
return osc;
|
||||
}
|
||||
|
||||
export function playTickSound() {
|
||||
const osc = createOsc();
|
||||
const osc = createOsc('triangle');
|
||||
osc.frequency.setValueAtTime(440, audio.currentTime);
|
||||
osc.frequency.setValueAtTime(0, audio.currentTime + 0.005);
|
||||
osc.start();
|
||||
|
||||
Reference in new issue
Block a user