Esempio n. 1
0
        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();
            }
        }
Esempio n. 2
0
        public static byte[] EncodeLoop(byte[] hcaBytes, bool loop)
        {
            HcaMetadata metadata = new HcaMetadata(hcaBytes);

            if (metadata.HasLoopData && loop)
            {
                return(hcaBytes);                              //Reuse existing loop data
            }
            return(HcaMetadata.SetLoop(hcaBytes, loop, 0, metadata.DurationSeconds, 0));
        }
Esempio n. 3
0
 /// <summary>
 /// Loop the track from the specified start and end.
 /// </summary>
 public static byte[] EncodeLoop(byte[] hcaBytes, bool loop, double start, double end)
 {
     return(HcaMetadata.SetLoop(hcaBytes, loop, start, end, 0));
 }
        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();
                    }
                }
            }
        }