Example #1
0
        public override void Remux(IFormat format, FormatData data, FormatData destination, ProgressIndicator progress)
        {
            if (!(format is AudioFormatOgg))
            {
                throw new FormatException();
            }

            bool musttranscode = AudioFormatOgg.Instance.GetAudioStreams(data).Count > 1;

            if (musttranscode)               // Remuxing isn't possible with more than one audio stream
            {
                Platform.TranscodeOnly(format, data, AudioFormatMogg.Instance, destination, progress);
                return;
            }

            Util.StreamCopy(destination.AddStream(this, FormatName), AudioFormatOgg.Instance.GetFormatStream(data));

            CryptedMoggStream audio = new CryptedMoggStream(destination.AddStream(this, AudioName));

            audio.WriteHeader();
            Util.StreamCopy(audio, AudioFormatOgg.Instance.GetAudioStream(data));

            destination.CloseStream(this, AudioName);
            destination.CloseStream(this, FormatName);
        }
Example #2
0
        public static void Save(FormatData data, SongData song)
        {
            if (!FormatData.LocalSongCache || (data.PlatformData != null && data.PlatformData.Platform == PlatformLocalStorage.Instance))
            {
                CacheMutex.WaitOne();
                try {
                    Stream stream = data.AddStream("songdata");
                    song.Save(stream);
                    data.CloseStream(stream);
                } catch (Exception ex) {
                    CacheMutex.ReleaseMutex();
                    throw ex;
                }
                CacheMutex.ReleaseMutex();
            }
            SongData songdata = null;

            if (Cache.ContainsKey(data))
            {
                songdata = Cache[data];
            }
            if (FormatData.LocalSongCache && songdata != song)
            {
                songdata = song;
                songdata.PropertyChanged += new Action <SongData>(data.Song_PropertyChanged);
                Cache[data] = songdata;
            }
        }
Example #3
0
        public override void EncodeChart(ChartFormat data, FormatData destination, ProgressIndicator progress)
        {
            Stream stream = destination.AddStream(this, ChartFile);

            data.Save(stream);
            destination.CloseStream(stream);
        }
Example #4
0
        public override void Remux(IFormat format, FormatData data, FormatData destination, ProgressIndicator progress)
        {
            if (!(format is AudioFormatMogg))
            {
                throw new FormatException();
            }

            Stream stream = destination.AddStream(this, AudioName);

            Util.StreamCopy(stream, AudioFormatMogg.Instance.GetDecryptedAudioStream(data));
            destination.CloseStream(stream);

            stream = destination.AddStream(this, FormatName);
            Util.StreamCopy(stream, AudioFormatMogg.Instance.GetFormatStream(data));
            destination.CloseStream(stream);
        }
Example #5
0
 public void Create(FormatData data, Stream audio, AudioFormat format)
 {
     data.SetStream(this, AudioName, audio);
     if (format != null)
     {
         Stream formatstream = data.AddStream(this, FormatName);
         format.Save(formatstream);
         data.CloseStream(formatstream);
     }
 }
Example #6
0
        public void Create(FormatData data, Stream[] streams, AudioFormat format)
        {
            Stream formatstream = data.AddStream(this, FormatName);

            format.Save(formatstream);
            data.CloseStream(formatstream);

            for (int i = 0; i < streams.Length; i++)
            {
                data.SetStream(this, AudioName + (i == 0 ? string.Empty : ("." + i.ToString())), streams[i]);
            }
        }
Example #7
0
        public static void SaveSongItem(FormatData formatdata)
        {
            SongData song = formatdata.Song;

            byte[] data = song.Data.GetValue <byte[]>("NeversoftSongItem");
            if (data == null)
            {
                return;
            }

            Stream stream = formatdata.AddStream(Instance, "neversoftdata");

            stream.Write(data);
            formatdata.CloseStream(Instance, "neversoftdata");
            song.Data.SetValue("NeversoftSongItem", new byte[0]);
        }
Example #8
0
 public virtual void SaveTo(FormatData data, FormatType type = FormatType.Unknown)
 {
     foreach (string name in Data)
     {
         if (type != FormatType.Unknown)
         {
             try {
                 int format = int.Parse(name.Split('.')[0]);
                 if (Platform.GetFormat(format).Type != type)
                 {
                     continue;
                 }
             } catch { }
         }
         Util.StreamCopy(data.AddStream(name), GetStream(name));
         data.CloseStream(name);
         CloseStream(name);
     }
 }
Example #9
0
        internal void EncodeOggAudio(AudioFormat data, FormatData destination, IFormat format, Stream stream, ProgressIndicator progress)
        {
            IDecoder decoder = data.Decoder;

            RawkAudio.Encoder encoder = new RawkAudio.Encoder(stream, decoder.Channels, decoder.SampleRate);

            AudioFormat.ProcessOffset(decoder, encoder, data.InitialOffset);

            progress.NewTask(1);

            AudioFormat.Transcode(encoder, decoder, progress);
            progress.Progress();

            encoder.Dispose();
            destination.CloseStream(format, AudioName);

            decoder.Dispose();

            data.Save(destination.AddStream(format, FormatName));
            destination.CloseStream(format, FormatName);

            progress.EndTask();
        }
Example #10
0
        public static void Transfer(IFormat format, FormatData data, FormatData destination, ProgressIndicator progress)
        {
            string[] streams = data.GetStreamNames();
            progress.NewTask(streams.Length);
            foreach (string fullname in streams)
            {
                if (fullname.StartsWith(format.ID + "."))
                {
                    string name = fullname.Split(new char[] { '.' }, 2)[1];

                    Stream ostream = destination.AddStream(format, name);
                    Stream istream = data.GetStream(format, name);

                    Util.StreamCopy(ostream, istream);

                    destination.CloseStream(ostream);
                    data.CloseStream(istream);

                    progress.Progress();
                }
            }

            progress.EndTask();
        }
Example #11
0
        public override void EncodeAudio(AudioFormat audioformat, FormatData formatdata, ProgressIndicator progress)
        {
            progress.NewTask(20);

            Stream audio = formatdata.AddStream(this, AudioName);

            progress.SetNextWeight(1);
            List <AudioFormat.Mapping> oldmaps = audioformat.Mappings;

            ushort[] masks = PlatformRB2WiiCustomDLC.RemixAudioTracks(formatdata.Song, audioformat);

            progress.SetNextWeight(14);
            long samples           = audioformat.Decoder.Samples;
            CryptedMoggStream mogg = new CryptedMoggStream(audio);

            //mogg.WriteHeader(samples);
            mogg.WriteHeader();
            RawkAudio.Encoder encoder = new RawkAudio.Encoder(mogg, audioformat.Channels, audioformat.Decoder.SampleRate, 28000);
            progress.NewTask("Transcoding Audio", samples);
            JaggedShortArray buffer = new JaggedShortArray(encoder.Channels, audioformat.Decoder.AudioBuffer.Rank2);

            AudioFormat.ProcessOffset(audioformat.Decoder, encoder, audioformat.InitialOffset);
            while (samples > 0)
            {
                //int read = audioformat.Decoder.Read((int)Math.Min(samples, 0x4E20));
                //int read = audioformat.Decoder.Read((int)Math.Min(samples, 0x20));
                int read = audioformat.Decoder.Read((int)Math.Min(samples, buffer.Rank2));
                if (read <= 0)
                {
                    break;
                }

                audioformat.Decoder.AudioBuffer.DownmixTo(buffer, masks, read);

                encoder.Write(buffer, read);
                samples -= read;
                progress.Progress(read);
                //mogg.Update(read);
            }
            progress.EndTask();
            progress.Progress(14);
            encoder.Dispose();
            mogg.WriteEntries();
            formatdata.CloseStream(audio);

            progress.SetNextWeight(6);
            Stream preview = formatdata.AddStream(this, PreviewName);

            mogg = new CryptedMoggStream(preview);
            mogg.WriteHeader();
            PlatformRB2WiiCustomDLC.TranscodePreview(formatdata.Song.PreviewTimes, oldmaps, audioformat.Decoder != null ? audioformat.Decoder : new ZeroDecoder(1, 28000, 0x7FFFFFFFFFFFFFFF), mogg, progress);
            formatdata.CloseStream(preview);

            progress.EndTask();
            progress.Progress(6);

            Stream formatstream = formatdata.AddStream(this, FormatName);

            audioformat.Save(formatstream);
            formatdata.CloseStream(formatstream);
        }
Example #12
0
 public override void EncodeAudio(AudioFormat data, FormatData destination, ProgressIndicator progress)
 {
     EncodeOggAudio(data, destination, this, destination.AddStream(this, AudioName), progress);
 }