Ejemplo n.º 1
0
 public static byte[] Encode(byte[] wavBytes)
 {
     using (var wavStream = new MemoryStream(wavBytes))
     {
         return(ConvertStream.ConvertFile(new Options(), wavStream, FileType.Wave, FileType.Hca));
     }
 }
Ejemplo n.º 2
0
        public void ExtractTrack(AFS2_AudioFile entry, string name, FileType format)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Title = "Extract track...";

            if (format != FileType.Hca && format != FileType.Adx && format != FileType.Wave)
            {
                saveDialog.Filter = "Binary file |*.bin;";
            }
            else
            {
                saveDialog.Filter = "WAV |*.wav; |HCA |*.hca; |ADX |*.adx;";
            }

            saveDialog.AddExtension = true;
            saveDialog.FileName     = name;

            if (saveDialog.ShowDialog() == true)
            {
                if (string.IsNullOrWhiteSpace(saveDialog.FileName))
                {
                    return;
                }
                FileType outputType = FileType.NotSet;

                switch (System.IO.Path.GetExtension(saveDialog.FileName).ToLower())
                {
                case ".hca":
                    outputType = FileType.Hca;
                    break;

                case ".adx":
                    outputType = FileType.Adx;
                    break;

                case ".atrac9":
                    outputType = FileType.Atrac9;
                    break;

                case ".wav":
                    outputType = FileType.Wave;
                    break;
                }

                if (outputType == FileType.NotSet)
                {
                    File.WriteAllBytes(saveDialog.FileName, entry.bytes);
                }
                else
                {
                    using (MemoryStream stream = new MemoryStream(entry.bytes))
                    {
                        byte[] bytes = ConvertStream.ConvertFile(new Options(), stream, format, outputType);
                        File.WriteAllBytes(saveDialog.FileName, bytes);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static WavStream Decode(byte[] adxBytes)
        {
            byte[] wavBytes;

            using (MemoryStream stream = new MemoryStream(adxBytes))
            {
                wavBytes = ConvertStream.ConvertFile(new Options(), stream, FileType.Adx, FileType.Wave);
            }

            return(new WavStream(wavBytes));
        }
Ejemplo n.º 4
0
        public static byte[] ConvertFile(byte[] bytes, FileType encodeType, FileType convertToType, bool loop)
        {
            using (var ms = new MemoryStream(bytes))
            {
                byte[] track = ConvertStream.ConvertFile(new Options(), ms, encodeType, convertToType);

                if (convertToType == FileType.Hca && loop)
                {
                    track = HCA.EncodeLoop(track, loop);
                }

                return(track);
            }
        }
Ejemplo n.º 5
0
        private async Task ExtractAllTracks(string extractDirectory, bool convertToWav)
        {
            if (!IsAcbLoaded())
            {
                return;
            }
            List <AFS2_Entry> extractedAwbEntries = new List <AFS2_Entry>();

            var controller = await this.ShowProgressAsync("Extracting all tracks (this may take a while)", "", true, DialogSettings.Default);

            controller.Maximum = AcbFile.AcbFile.Cues.Count;

            try
            {
                await Task.Run(() =>
                {
                    int progress = 0;
                    foreach (var cue in AcbFile.AcbFile.Cues)
                    {
                        if (controller.IsCanceled)
                        {
                            break;
                        }

                        controller.SetMessage($"Extracting \"{cue.Name}\" (Cue ID: {cue.ID})...");
                        var waveforms = AcbFile.AcbFile.GetWaveformsFromCue(cue);

                        foreach (var waveform in waveforms)
                        {
                            if (waveform.AwbId != ushort.MaxValue)
                            {
                                var awbEntry = AcbFile.AcbFile.GetAfs2Entry(waveform.AwbId);

                                if (!extractedAwbEntries.Contains(awbEntry))
                                {
                                    string trackName = $"{cue.ID}_{cue.Name}_({waveform.AwbId})";
                                    byte[] trackBytes;

                                    if (convertToWav)
                                    {
                                        using (MemoryStream stream = new MemoryStream(awbEntry.bytes))
                                        {
                                            trackBytes = ConvertStream.ConvertFile(new Options(), stream, Helper.GetFileType(waveform.EncodeType), FileType.Wave);
                                        }

                                        File.WriteAllBytes($"{extractDirectory}/{trackName}.wav", trackBytes);
                                    }
                                    else
                                    {
                                        File.WriteAllBytes($"{extractDirectory}/{trackName}.{waveform.EncodeType}", awbEntry.bytes);
                                    }
                                    extractedAwbEntries.Add(awbEntry);
                                }
                            }
                        }

                        progress++;
                        controller.SetProgress(progress);
                    }
                });
            }
            catch (Exception ex)
            {
                ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
            }
            finally
            {
                await controller.CloseAsync();
            }
        }