private async void InitValues() { var awbEntry = WaveformWrapper.WrapperRoot.AcbFile.GetAfs2Entry(WaveformWrapper.WaveformRef.AwbId); if (awbEntry != null) { HcaMetadata metadata = new HcaMetadata(awbEntry.bytes); LoopEnabled = metadata.HasLoopData; LoopStartMs = metadata.LoopStartMs; LoopEndMs = metadata.LoopEndMs; TrackLengthMs = metadata.Milliseconds + 1000; //Declared length can be slightly too short, so extend it by 1 second ValuesChanged(); if (metadata.ValidHcaFile) { awbBytes = awbEntry.bytes; await Task.Run(() => wavStream = HCA.Decode(awbEntry.bytes)); SetLoopOnStream(); CommandManager.InvalidateRequerySuggested(); } } else { Close(); } }
private async void PlayPreview() { #if !DEBUG try #endif { if (!wavStream.IsValid) { wavStream = null; await Task.Run(() => wavStream = HCA.Decode(awbBytes)); SetLoopOnStream(); } if (!audioPlayer.HasAudio(wavStream)) { audioPlayer.SetAudio(wavStream); } audioPlayer.Play(); } #if !DEBUG catch (Exception ex) { MessageBox.Show($"An error occured while processing the PlayPreview command.\n\nDetails:{ex.Message}", $"PlayPreview failed", MessageBoxButton.OK, MessageBoxImage.Error); } #endif }
private async void PlayTrack(bool loop) { var track = GetSelectedTrack(TrackType.Track); var cue = GetSelectedCue(); if (track != null && cue != null) { if (track.WaveformWrapper != null) { var afs2Entry = AcbFile.AcbFile.GetAfs2Entry((track.WaveformWrapper.WaveformRef != null) ? track.WaveformWrapper.WaveformRef.AwbId : ushort.MaxValue); if (afs2Entry != null) { audioPlayer.Stop(); await Task.Run(() => { switch (track.WaveformWrapper.WaveformRef.EncodeType) { case EncodeType.HCA: case EncodeType.HCA_ALT: audioPlayer.SetAudio(HCA.Decode(afs2Entry.bytes)); break; case EncodeType.ADX: audioPlayer.SetAudio(ADX.Decode(afs2Entry.bytes)); break; case EncodeType.ATRAC9: audioPlayer.SetAudio(AT9.Decode(afs2Entry.bytes)); break; case EncodeType.BCWAV: audioPlayer.SetAudio(BC_WAV.Decode(afs2Entry.bytes)); break; case EncodeType.DSP: audioPlayer.SetAudio(DSP.Decode(afs2Entry.bytes)); break; } }); //Set volume float cueBaseVolume = cue.GetBaseVolume(); float cueRandom = cue.GetRandomVolume(); float trackBasekVolume = track.GetBaseVolume(); float trackRandom = track.GetRandomVolume(); float cueVolume = cueBaseVolume + Xv2CoreLib.Random.Range(0, cueRandom); float trackVolume = trackBasekVolume + Xv2CoreLib.Random.Range(0, trackRandom); float finalVolume = ((trackVolume * cueVolume) > 1f) ? 1f : trackVolume * cueVolume; audioPlayer.SetVolume(finalVolume); //Set loop if (loop) { if (track.WaveformWrapper.WaveformRef.EncodeType == EncodeType.HCA || track.WaveformWrapper.WaveformRef.EncodeType == EncodeType.HCA_ALT) { HcaMetadata meta = new HcaMetadata(afs2Entry.bytes); if (meta.HasLoopData) { audioPlayer.SetLoop(meta.LoopStartMs, meta.LoopEndMs); } else { audioPlayer.SetLoop(); } } else { audioPlayer.SetLoop(); } } //Play audioPlayer.Play(); //Force Update UI CommandManager.InvalidateRequerySuggested(); } } } }