@@ -11,15 +11,16 @@ import {
1111 toggleBeatSync ,
1212 updateBeatSyncParameters ,
1313} from ' @proj-airi/stage-shared/beat-sync/browser'
14- import { AudioSpectrumVisualizer } from ' @proj-airi/stage-ui/components'
14+ import { Alert , AudioSpectrumVisualizer } from ' @proj-airi/stage-ui/components'
1515import { Button , FieldCheckbox , FieldRange } from ' @proj-airi/ui'
1616import { createTimeline } from ' animejs'
1717import { nanoid } from ' nanoid'
18- import { onMounted , onUnmounted , ref , toRaw , watch } from ' vue'
18+ import { computed , onMounted , onUnmounted , ref , toRaw , watch } from ' vue'
1919import { useI18n } from ' vue-i18n'
2020
2121const state = ref <BeatSyncDetectorState >()
2222const frequencies = ref <number []>([])
23+ const totalFreqHistory = ref <number []>([])
2324const isUpdatingFrequencies = ref (false )
2425
2526const { t } = useI18n ()
@@ -72,13 +73,30 @@ function resetDefaultParameters() {
7273
7374async function updateFrequencies() {
7475 frequencies .value = Array .from (await getBeatSyncInputByteFrequencyData ())
76+ totalFreqHistory .value .push (frequencies .value .reduce ((a , b ) => a + b , 0 ))
7577
76- if (isUpdatingFrequencies .value )
78+ while (totalFreqHistory .value .length > 50 )
79+ totalFreqHistory .value .shift ()
80+
81+ if (isUpdatingFrequencies .value ) {
7782 requestAnimationFrame (updateFrequencies )
78- else
79- frequencies .value = [0 ]
83+ }
84+ else {
85+ frequencies .value = frequencies .value .map (() => 0 )
86+ totalFreqHistory .value = []
87+ }
8088}
8189
90+ const noAudioDetected = computed (() => {
91+ if (! isUpdatingFrequencies .value )
92+ return false
93+
94+ if (totalFreqHistory .value .length < 50 )
95+ return false
96+
97+ return totalFreqHistory .value .reduce ((a , b ) => a + b , 0 ) === 0
98+ })
99+
82100watch (state , async (newState ) => {
83101 if (newState ?.isActive ) {
84102 if (! isUpdatingFrequencies .value ) {
@@ -145,6 +163,18 @@ onUnmounted(() => {
145163 </div >
146164 </div >
147165
166+ <Alert
167+ v-if =" noAudioDetected"
168+ type =" warning"
169+ >
170+ <template #title >
171+ No audio detected
172+ </template >
173+ <template #content >
174+ Please make sure that the correct permissions are granted and the audio source is playing sound.
175+ </template >
176+ </Alert >
177+
148178 <div flex =" ~ col gap-4" >
149179 <div flex =" ~ row" items-center justify-between >
150180 <div >
0 commit comments