|
@@ -14,6 +14,10 @@ import { evaluatingData } from "/src/view/evaluating";
|
|
|
import { cloudToggleState } from "/src/helpers/midiPlay"
|
|
|
import { storeData } from "/src/store";
|
|
|
import { handleStartTick } from "../tick";
|
|
|
+import Crunker from "/src/utils/crunker"
|
|
|
+import tickMp3 from "/src/assets/tick.wav"
|
|
|
+import tockMp3 from "/src/assets/tock.wav"
|
|
|
+import { metronomeData } from "/src/helpers/metronome";
|
|
|
|
|
|
export const audioData = reactive({
|
|
|
songEle: null as HTMLAudioElement | null, // 原生
|
|
@@ -200,6 +204,118 @@ export const changeMingSongType = () =>{
|
|
|
audioData.songCollection.beatMingSongEle = mingSongType === 1 ? beatMingSongEle : beatMingSongGirlEle
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 处理加载节拍器音频
|
|
|
+let CrunkerInstance: Crunker
|
|
|
+export const handleLoadBeatMusic = async () => {
|
|
|
+ if(metronomeData.disable) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const playType = state.playType
|
|
|
+ const playSource = state.playSource
|
|
|
+ const mingSongType = audioData.mingSongType
|
|
|
+ // 当前模式下 如果已经有合成音频了,就不走合成逻辑了
|
|
|
+ let isBeatMusic = false
|
|
|
+ let currentMusic //当前的音频
|
|
|
+ const beatPlayObj = {
|
|
|
+ "play_music":"beatSongEle",
|
|
|
+ "play_background":"beatBackgroundEle",
|
|
|
+ "sing_music":"beatFanSongEle",
|
|
|
+ "sing_background":"beatBanSongEle"
|
|
|
+ }
|
|
|
+ const playObj = {
|
|
|
+ "play_music":"music",
|
|
|
+ "play_background":"accompany",
|
|
|
+ "sing_music":"fanSong",
|
|
|
+ "sing_background":"banSong",
|
|
|
+ }
|
|
|
+ if(playSource === "mingSong") {
|
|
|
+ // 当男声女声都有的时候 才区分
|
|
|
+ if(state.mingSong && state.mingSongGirl){
|
|
|
+ isBeatMusic = mingSongType === 1 ? !!audioData.mingSongTypeCollection.beatMingSongEle : !!audioData.mingSongTypeCollection.beatMingSongGirlEle
|
|
|
+ currentMusic = mingSongType === 1 ? state.mingSong : state.mingSongGirl
|
|
|
+ }else{
|
|
|
+ isBeatMusic = !!audioData.mingSongTypeCollection.beatMingSongEle
|
|
|
+ currentMusic = state.mingSong
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // @ts-ignore
|
|
|
+ isBeatMusic = !!audioData.songCollection[beatPlayObj[`${playType}_${playSource}`]]
|
|
|
+ // @ts-ignore
|
|
|
+ currentMusic = state[playObj[`${playType}_${playSource}`]]
|
|
|
+ }
|
|
|
+ if(isBeatMusic || !currentMusic){
|
|
|
+ return
|
|
|
+ }
|
|
|
+ state.loadingText = "音频资源加载中,请稍后…"
|
|
|
+ state.isLoading = true
|
|
|
+ /* 音频合成 */
|
|
|
+ if(!CrunkerInstance){
|
|
|
+ CrunkerInstance = new Crunker()
|
|
|
+ }
|
|
|
+ console.time("音频加载时间")
|
|
|
+ const [audioBuffer, tickBuff, tockBuff] = await CrunkerInstance.fetchAudio(`${currentMusic}?v=${Date.now()}`, tickMp3, tockMp3)
|
|
|
+ console.timeEnd("音频加载时间")
|
|
|
+ // 计算音频空白时间
|
|
|
+ const silenceDuration = audioBuffer&&!state.isEvxml ? CrunkerInstance.calculateSilenceDuration(audioBuffer) : 0
|
|
|
+ console.log(`音频空白时间:${silenceDuration}`)
|
|
|
+ const beats:AudioBuffer[] = []
|
|
|
+ const beatsTime:number[] = []
|
|
|
+ metronomeData.metroMeasure.map(measures=>{
|
|
|
+ measures.map((item:any)=>{
|
|
|
+ beats.push(item.index===0?tickBuff!:tockBuff!)
|
|
|
+ beatsTime.push(item.time+silenceDuration) //不是妙极客的曲子才加上空白
|
|
|
+ })
|
|
|
+ })
|
|
|
+ console.time("音频合并时间")
|
|
|
+ const musicBuffMeg = audioBuffer && CrunkerInstance.mergeAudioBuffers([audioBuffer!,...beats],[0,...beatsTime])
|
|
|
+ console.timeEnd("音频合并时间")
|
|
|
+ console.time("音频audioDom生成时间")
|
|
|
+ const musicAudio = musicBuffMeg && CrunkerInstance.exportAudioElement(musicBuffMeg) as any
|
|
|
+ console.timeEnd("音频audioDom生成时间")
|
|
|
+ const playEleObj = {
|
|
|
+ "play_music":"beatSongEle",
|
|
|
+ "play_background":"beatBackgroundEle",
|
|
|
+ "sing_music":"beatFanSongEle",
|
|
|
+ "sing_background":"beatBanSongEle"
|
|
|
+ }
|
|
|
+ // 给音频赋值
|
|
|
+ if(playSource === "mingSong"){
|
|
|
+ // 当男声女声都有的时候 才区分
|
|
|
+ if(state.mingSong && state.mingSongGirl){
|
|
|
+ if(mingSongType === 1) {
|
|
|
+ audioData.mingSongTypeCollection.beatMingSongEle = musicAudio
|
|
|
+ }else {
|
|
|
+ audioData.mingSongTypeCollection.beatMingSongGirlEle = musicAudio
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ audioData.songCollection.beatMingSongEle = musicAudio
|
|
|
+ audioData.mingSongTypeCollection.beatMingSongEle = musicAudio
|
|
|
+ }
|
|
|
+ if(musicAudio){
|
|
|
+ musicAudio.addEventListener("play", onPlay);
|
|
|
+ musicAudio.addEventListener("ended", onEnded);
|
|
|
+ }
|
|
|
+ changeMingSongType()
|
|
|
+ }else{
|
|
|
+ if(playType === "play" && !audioData.songCollection.beatSongEle && !audioData.songCollection.beatBackgroundEle){
|
|
|
+ if(musicAudio){
|
|
|
+ musicAudio.addEventListener("play", onPlay);
|
|
|
+ musicAudio.addEventListener("ended", onEnded);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(playType === "sing" && !audioData.songCollection.beatFanSongEle && !audioData.songCollection.beatBanSongEle){
|
|
|
+ if(musicAudio){
|
|
|
+ musicAudio.addEventListener("play", onPlay);
|
|
|
+ musicAudio.addEventListener("ended", onEnded);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // @ts-ignore
|
|
|
+ audioData.songCollection[playEleObj[`${playType}_${playSource}`]] = musicAudio
|
|
|
+ }
|
|
|
+ state.isLoading = false
|
|
|
+}
|
|
|
+
|
|
|
export default defineComponent({
|
|
|
name: "audio-list",
|
|
|
setup() {
|
|
@@ -383,7 +499,7 @@ export default defineComponent({
|
|
|
mingSongGirl.addEventListener("play", onPlay);
|
|
|
mingSongGirl.addEventListener("ended", onEnded);
|
|
|
}
|
|
|
- // 处理带节拍器的音源
|
|
|
+ /* // 处理带节拍器的音源
|
|
|
const [beatMusic, beatAccompany, beatFanSong, beatBanSong, beatMingSong, beatMingSongGirl] = await loadBeatAudio()
|
|
|
Object.assign(audioData.songCollection, {
|
|
|
beatSongEle:beatMusic,
|
|
@@ -421,7 +537,7 @@ export default defineComponent({
|
|
|
if(beatMingSongGirl){
|
|
|
beatMingSongGirl.addEventListener("play", onPlay);
|
|
|
beatMingSongGirl.addEventListener("ended", onEnded);
|
|
|
- }
|
|
|
+ }*/
|
|
|
// 给男声女声赋值
|
|
|
const userGender = storeData.user.gender
|
|
|
// 当不为null 和undefined的时候 取userGender的值
|