Esempio n. 1
0
        private async void PlaySelectedTrack()
        {
            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();

                        switch (track.WaveformWrapper.WaveformRef.EncodeType)
                        {
                        case EncodeType.HCA:
                        case EncodeType.HCA_ALT:
                            await audioPlayer.AsyncSetHcaAudio(afs2Entry.bytes);

                            break;

                        case EncodeType.ADX:
                            audioPlayer.SetAudio(ADX.Decode(afs2Entry.bytes));
                            break;

                        case EncodeType.ATRAC9:
                            audioPlayer.SetAudio(AT9.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);

                        //Play
                        audioPlayer.Play();

                        //Force Update UI
                        CommandManager.InvalidateRequerySuggested();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }