コード例 #1
0
        public override AudioFormat DecodeAudio(FormatData data, ProgressIndicator progress)
        {
            IList <Stream> streams = GetAudioStreams(data);

            AudioFormat format = DecodeAudioFormat(data);

            format.Decoder = streams.Count == 1 ? null : new MultiDecoder(FFmpegDecoder.BufferSize);
            foreach (Stream stream in streams)
            {
                IDecoder sdecoder = new FFmpegDecoder(stream);
                if (format.Decoder == null)
                {
                    format.Decoder = sdecoder;
                }
                else
                {
                    (format.Decoder as MultiDecoder).AddDecoder(sdecoder);
                }
            }

            format.SetDisposeStreams(data, streams);

            return(format);
        }
コード例 #2
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();
        }
コード例 #3
0
        public override void DeleteSong(PlatformData data, FormatData formatdata, ProgressIndicator progress)
        {
            string path    = data.Session["maindirpath"] as string;
            string dtapath = "rawk/rb2/customs/" + formatdata.Song.ID;

            FileStream dtafile = new FileStream(Path.Combine(path, dtapath + "/data"), FileMode.Open, FileAccess.Read, FileShare.Read);

            EndianReader reader = new EndianReader(dtafile, Endianness.LittleEndian);

            DTB.NodeTree dtb = DTB.Create(reader);
            dtafile.Close();

            SongsDTA dta   = SongsDTA.Create(dtb);
            string   title = dta.Song.Name.Substring(4, 4);
            int      index = int.Parse(dta.Song.Name.Substring(9, 3));

            Util.Delete(Path.Combine(path, "private/wii/data/" + title + "/" + Util.Pad((index).ToString(), 3) + ".bin"));
            Util.Delete(Path.Combine(path, "private/wii/data/" + title + "/" + Util.Pad((index + 1).ToString(), 3) + ".bin"));
            Directory.Delete(Path.Combine(path, dtapath), true);

            base.DeleteSong(data, formatdata, progress);

            SaveDTBCache(data);
        }
コード例 #4
0
        public Stream GetPreviewStream(FormatData data, ProgressIndicator progress)
        {
            if (!data.HasStream(this, PreviewName))
            {
                AudioFormat format = new AudioFormat();

                /* Let it crash if it can't decode it. KIBE biks we don't know about don't belong here.
                 * try { */
                format.Decoder = new RawkAudio.Decoder(GetAudioStream(data), RawkAudio.Decoder.AudioFormat.BinkAudio);

                /*} catch {
                 *      format.Decoder = new ZeroDecoder(1, 28000, 0x7FFFFFFFFFFFFFFF);
                 * }*/
                Stream            previewstream = new TemporaryStream();
                CryptedMoggStream mogg          = new CryptedMoggStream(previewstream);
                mogg.WriteHeader();
                PlatformRB2WiiCustomDLC.TranscodePreview(data.Song.PreviewTimes, null, format.Decoder, mogg, progress);
                previewstream.Position = 0;
                format.Decoder.Dispose();
                return(previewstream);
            }

            return(data.GetStream(this, PreviewName));
        }
コード例 #5
0
 public static void Transcode(IFormat format, FormatData data, IFormat target, FormatData destination, ProgressIndicator progress)
 {
     if (target.CanRemux(format))
     {
         target.Remux(format, data, destination, progress);
     }
     else if (target.Writable && format.Readable)
     {
         TranscodeOnly(format, data, target, destination, progress);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
コード例 #6
0
        public static void Transcode(FormatType type, FormatData data, IList <IFormat> targets, FormatData destination, ProgressIndicator progress)
        {
            foreach (IFormat format in targets)
            {
                if (format.HasFormat(data))
                {
                    Transfer(format, data, destination, progress);
                    return;
                }
            }

            IList <IFormat> formats = FindTranscodePath(data.GetFormats(type), targets);

            if (formats.Count == 0)
            {
                throw new UnsupportedTranscodeException("Could not find a supported transcode path.");
            }

            if (formats.Count == 1)
            {
                if (formats[0].CanTransfer(data))
                {
                    Transfer(formats[0], data, destination, progress);
                    return;
                }
                else
                {
                    formats.Add(formats[0]);
                }
            }

            FormatData tempdata = null;

            if (formats.Count > 2)
            {
                tempdata = new TemporaryFormatData();
            }

            progress.NewTask(formats.Count - 1);

            for (int i = 1; i < formats.Count; i++)
            {
                FormatData dest = i < formats.Count - 1 ? tempdata : destination;
                Transcode(formats[i - 1], data, formats[i], dest, progress);
                data = dest;
                progress.Progress();
            }

            progress.EndTask();
        }
コード例 #7
0
 public Stream GetFormatStream(FormatData data)
 {
     return(data.GetStream(this, FormatName));
 }
コード例 #8
0
 public override void Remux(IFormat format, FormatData data, FormatData destination, ProgressIndicator progress)
 {
     throw new NotImplementedException();
 }
コード例 #9
0
 public Stream GetAudioStream(FormatData data)
 {
     return(data.GetStream(this, AudioName));
 }
コード例 #10
0
 public virtual object Decode(FormatData data, ProgressIndicator progress)
 {
     return(DecodeAudio(data, progress));
 }
コード例 #11
0
		public bool HasFormat(FormatData data)
		{
			return data.Formats.Contains(this);
		}
コード例 #12
0
 public abstract void EncodeAudio(AudioFormat data, FormatData destination, ProgressIndicator progress);
コード例 #13
0
 public abstract ChartFormat DecodeChart(FormatData data, ProgressIndicator progress);
コード例 #14
0
 public virtual AudioFormat DecodeAudioFormat(FormatData data)
 {
     AudioFormat format = DecodeAudio(data, new ProgressIndicator()); format.Decoder.Dispose(); return(format);
 }
コード例 #15
0
 public abstract AudioFormat DecodeAudio(FormatData data, ProgressIndicator progress);
コード例 #16
0
		public void Create(FormatData data, Stream dtabin, Stream contentbin)
		{
			data.SetStream(this, DtaBinName, dtabin);
			data.SetStream(this, ContentBinName, contentbin);
		}
コード例 #17
0
        public static void TranscodeOnly(IFormat format, FormatData data, IFormat target, FormatData destination, ProgressIndicator progress)
        {
            object decode = format.Decode(data, progress);

            target.Encode(decode, destination, progress);
            if (decode is IDisposable)
            {
                (decode as IDisposable).Dispose();
            }
        }
コード例 #18
0
 public override AudioFormat DecodeAudioFormat(FormatData data)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 public abstract void EncodeChart(ChartFormat data, FormatData destination, ProgressIndicator progress);
コード例 #20
0
		public bool CanTransfer(FormatData data) { return true; }
コード例 #21
0
        public void Create(FormatData data, Stream chart, bool coop)
        {
            data.SetStream(this, ChartFile, chart);

            data.Song.Data.SetValue("GH2ChartCoop", coop);
        }
コード例 #22
0
 public virtual void Remux(IFormat format, FormatData data, FormatData destination, ProgressIndicator progress)
 {
     throw new NotSupportedException();
 }
コード例 #23
0
 public override void EncodeAudio(AudioFormat data, FormatData destination, ProgressIndicator progress)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
 public virtual bool CanTransfer(FormatData data)
 {
     return(true);
 }
コード例 #25
0
        public override void SaveSong(PlatformData data, FormatData formatdata, ProgressIndicator progress)
        {
            string path = data.Session["path"] as string;

            SongData song = formatdata.Song;

            progress.NewTask(8);

            int    i;
            string songpath = null;

            for (i = 0; i < 0x1000; i++)
            {
                songpath = Path.Combine(path, song.ID + (i == 0 ? "" : i.ToString()));
                if (!Directory.Exists(songpath))
                {
                    break;
                }
            }
            Directory.CreateDirectory(songpath);
            AudioFormat audio = (formatdata.GetFormat(FormatType.Audio) as IAudioFormat).DecodeAudio(formatdata, progress);

            progress.Progress();
            ChartFormat chart = (formatdata.GetFormat(FormatType.Chart) as IChartFormat).DecodeChart(formatdata, progress);

            progress.Progress();

            Stream chartstream = new FileStream(Path.Combine(songpath, "notes.mid"), FileMode.Create, FileAccess.Write);

            chart.Save(chartstream);
            chartstream.Close();

            Ini ini = new Ini();

            ini.SetValue("song", "name", song.Name);
            ini.SetValue("song", "artist", song.Artist);
            ini.SetValue("song", "album", song.Album);
            ini.SetValue("song", "genre", song.Genre);
            ini.SetValue("song", "year", song.Year.ToString());
            ini.SetValue("song", "diff_band", ImportMap.GetBaseTier(Instrument.Ambient, song.Difficulty[Instrument.Ambient]).ToString());
            ini.SetValue("song", "diff_guitar", ImportMap.GetBaseTier(Instrument.Guitar, song.Difficulty[Instrument.Guitar]).ToString());
            ini.SetValue("song", "diff_bass", ImportMap.GetBaseTier(Instrument.Bass, song.Difficulty[Instrument.Bass]).ToString());
            ini.SetValue("song", "diff_drums", ImportMap.GetBaseTier(Instrument.Drums, song.Difficulty[Instrument.Drums]).ToString());
            Stream inistream = new FileStream(Path.Combine(songpath, "song.ini"), FileMode.Create, FileAccess.Write);

            ini.Save(inistream);
            inistream.Close();

            if (song.AlbumArt != null)
            {
                Stream albumart = new FileStream(Path.Combine(songpath, "album.png"), FileMode.Create, FileAccess.Write);
                song.AlbumArt.Save(albumart, ImageFormat.Png);
                albumart.Close();
            }

            JaggedShortArray encoderdata;

            var instruments = audio.Mappings.GroupBy(m => m.Instrument == Instrument.Vocals ? Instrument.Ambient : m.Instrument);

            encoderdata = new JaggedShortArray(2, RawkAudio.Decoder.BufferSize);
            int count = instruments.Count();

            Stream[]   streams  = new Stream[count];
            IEncoder[] encoders = new IEncoder[count];
            ushort[][] masks    = new ushort[count][];

            i = 0;
            foreach (var item in instruments)
            {
                string filename = null;
                switch (item.Key)
                {
                case Instrument.Guitar:
                    filename = "guitar.ogg";
                    break;

                case Instrument.Bass:
                    filename = "rhythm.ogg";
                    break;

                case Instrument.Drums:
                    filename = "drums.ogg";
                    break;

                case Instrument.Ambient:
                    filename = "song.ogg";
                    break;

                case Instrument.Preview:
                    filename = "preview.ogg";
                    break;
                }

                streams[i] = new FileStream(Path.Combine(songpath, filename), FileMode.Create, FileAccess.Write);
                masks[i]   = new ushort[2];

                foreach (var map in item)
                {
                    int index = audio.Mappings.IndexOf(map);
                    if (map.Balance <= 0)
                    {
                        masks[i][0] |= (ushort)(1 << index);
                    }
                    if (map.Balance >= 0)
                    {
                        masks[i][1] |= (ushort)(1 << index);
                    }
                }

                encoders[i] = new RawkAudio.Encoder(streams[i], 2, audio.Decoder.SampleRate, 44100);

                i++;
            }

            if (audio.InitialOffset > 0)
            {
                AudioFormat.ProcessOffset(audio.Decoder, encoders[0], audio.InitialOffset);
            }
            else
            {
                for (i = 0; i < encoders.Length; i++)
                {
                    AudioFormat.ProcessOffset(audio.Decoder, encoders[i], audio.InitialOffset);
                }
            }

            long samples = audio.Decoder.Samples;

            progress.NewTask("Transcoding Audio", samples, 6);
            while (samples > 0)
            {
                int read = audio.Decoder.Read();
                if (read <= 0)
                {
                    break;
                }

                // TODO: Apply volumes to each channel
                for (i = 0; i < count; i++)
                {
                    audio.Decoder.AudioBuffer.DownmixTo(encoderdata, masks[i], read, false);
                    encoders[i].Write(encoderdata, read);
                }

                samples -= read;
                progress.Progress(read);
            }

            for (i = 0; i < count; i++)
            {
                encoders[i].Dispose();
                streams[i].Close();
            }
            progress.EndTask();
            progress.Progress(6);
            progress.EndTask();
        }
コード例 #26
0
 public virtual bool HasFormat(FormatData data)
 {
     return(data.Formats.Contains(this));
 }
コード例 #27
0
 public Stream GetPreviewStream(FormatData data)
 {
     return(data.GetStream(this, PreviewName));
 }
コード例 #28
0
 public virtual void SaveSong(PlatformData data, FormatData formatdata, ProgressIndicator progress)
 {
     throw new NotImplementedException();
 }
コード例 #29
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);
        }
コード例 #30
0
 public virtual void DeleteSong(PlatformData data, FormatData formatdata, ProgressIndicator progress)
 {
     data.Mutex.WaitOne(); formatdata.Dispose(); data.RemoveSong(formatdata); data.Mutex.ReleaseMutex();
 }