diff options
| author | おさむのひと <46447427+samunohito@users.noreply.github.com> | 2023-11-21 20:05:04 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-21 20:05:04 +0900 |
| commit | 4b13179ff919e4424eb60a37db0e72df4bd12101 (patch) | |
| tree | 176a7b06e84dad0706cd3fb2a23cb2af8e42b6b9 /packages/frontend/src/scripts | |
| parent | 広告掲載ページにてfilterをわかりやすく (#12385) (diff) | |
| download | sharkey-4b13179ff919e4424eb60a37db0e72df4bd12101.tar.gz sharkey-4b13179ff919e4424eb60a37db0e72df4bd12101.tar.bz2 sharkey-4b13179ff919e4424eb60a37db0e72df4bd12101.zip | |
サウンド再生方法の変更に追従できていなかった所を修正 (#12368)
Co-authored-by: osamu <46447427+sam-osamu@users.noreply.github.com>
Diffstat (limited to 'packages/frontend/src/scripts')
| -rw-r--r-- | packages/frontend/src/scripts/sound.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/packages/frontend/src/scripts/sound.ts b/packages/frontend/src/scripts/sound.ts index 4b0cd0bb39..2b604bd98a 100644 --- a/packages/frontend/src/scripts/sound.ts +++ b/packages/frontend/src/scripts/sound.ts @@ -61,7 +61,7 @@ export const soundsTypes = [ 'noizenecio/kick_gaba7', ] as const; -export async function getAudio(file: string, useCache = true) { +export async function loadAudio(file: string, useCache = true) { if (useCache && cache.has(file)) { return cache.get(file)!; } @@ -77,12 +77,6 @@ export async function getAudio(file: string, useCache = true) { return audioBuffer; } -export function setVolume(audio: HTMLAudioElement, volume: number): HTMLAudioElement { - const masterVolume = defaultStore.state.sound_masterVolume; - audio.volume = masterVolume - ((1 - volume) * masterVolume); - return audio; -} - export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notification') { const sound = defaultStore.state[`sound_${type}`]; if (_DEV_) console.log('play', type, sound); @@ -91,16 +85,22 @@ export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notifica } export async function playFile(file: string, volume: number) { + const buffer = await loadAudio(file); + createSourceNode(buffer, volume)?.start(); +} + +export function createSourceNode(buffer: AudioBuffer, volume: number) : AudioBufferSourceNode | null { const masterVolume = defaultStore.state.sound_masterVolume; if (masterVolume === 0 || volume === 0) { - return; + return null; } const gainNode = ctx.createGain(); gainNode.gain.value = masterVolume * volume; const soundSource = ctx.createBufferSource(); - soundSource.buffer = await getAudio(file); + soundSource.buffer = buffer; soundSource.connect(gainNode).connect(ctx.destination); - soundSource.start(); + + return soundSource; } |