コード例 #1
0
        internal static void Export360(string path, FormatData original)
        {
            Program.Form.Progress.QueueTask(progress => {
                progress.NewTask("Exporting to 360 DLC file", 16);

                SongData song = original.Song;

                StfsArchive stfs      = new StfsArchive();
                stfs.Stfs.ContentType = StfsFile.ContentTypes.Marketplace;
                stfs.Stfs.TitleID     = 0x45410829;
                for (int i = 0; i < stfs.Stfs.DisplayName.Length; i++)
                {
                    stfs.Stfs.DisplayName[i] = song.Artist + " - " + song.Name;
                }
                for (int i = 0; i < stfs.Stfs.DisplayDescription.Length; i++)
                {
                    stfs.Stfs.DisplayDescription[i] = "RawkSD DLC - http://rawksd.japaneatahand.com";
                }
                stfs.Stfs.TitleName      = "Rawk Band 2";
                stfs.Stfs.Publisher      = "RawkSD";
                stfs.Stfs.TitleThumbnail = WiiImage.Create(new EndianReader(new MemoryStream(ConsoleHaxx.RawkSD.Properties.Resources.rawksd_albumart), Endianness.LittleEndian)).Bitmap;
                if (song.AlbumArt != null)
                {
                    stfs.Stfs.Thumbnail = song.AlbumArt;
                }
                else
                {
                    stfs.Stfs.Thumbnail = stfs.Stfs.TitleThumbnail;
                }
                StfsFile.SignedHeader header    = new StfsFile.SignedHeader(StfsFile.FileTypes.LIVE);
                stfs.Stfs.Header                = header;
                header.Licenses[0].ID           = 0xFFFFFFFFFFFFFFFF;
                stfs.Stfs.MetadataVersion       = 2;
                StfsFile.PackageDescriptor desc = new StfsFile.PackageDescriptor();
                stfs.Stfs.Descriptor            = desc;
                desc.StructSize          = 0x24;
                desc.BlockSeparation     = 1;
                desc.FileTableBlockCount = 0x100;                 // byte apparently
                stfs.Stfs.TransferFlags  = 0xC0;

                FormatData data = original;

                Program.Form.TaskMutex.WaitOne();
                bool local     = data.PlatformData.Platform == PlatformLocalStorage.Instance;
                bool ownformat = false;
                if (!local && Configuration.MaxConcurrentTasks > 1)
                {
                    data = new TemporaryFormatData(data.Song, data.PlatformData);
                    original.SaveTo(data);
                    ownformat = true;
                }
                Program.Form.TaskMutex.ReleaseMutex();

                Stream songs   = null;
                Stream audio   = null;
                Stream chart   = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.ChartFile);
                Stream pan     = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.PanFile);
                Stream weights = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.WeightsFile);
                Stream milo    = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.MiloFile);
                milo           = new MemoryStream(Properties.Resources.rbn_milo);       // TODO: properly convert milo

                if (milo == null)
                {
                    milo = new MemoryStream(ConsoleHaxx.RawkSD.Properties.Resources.rawksd_milo);
                }

                using (DelayedStreamCache cache = new DelayedStreamCache()) {
                    AudioFormat audioformat = (data.GetFormat(FormatType.Audio) as IAudioFormat).DecodeAudio(data, progress);

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

                    progress.Progress();

                    // RBN Required DTA settings
                    SongsDTA dta      = PlatformRB2WiiCustomDLC.GetSongsDTA(song, audioformat, false);
                    dta.AlbumArt      = false;
                    dta.Song.Name     = "songs/" + song.ID + "/" + song.ID;
                    dta.Song.MidiFile = "songs/" + song.ID + "/" + song.ID + ".mid";
                    dta.Rating        = 4;
                    dta.SubGenre      = "subgenre_core";
                    dta.Format        = 4;
                    //dta.SongID = 0;
                    dta.Origin = "rb2";
                    //dta.Ugc = 1;
                    //dta.SongLength = 300000;
                    dta.Context    = 2000;
                    dta.BasePoints = 0;
                    if (!dta.TuningOffsetCents.HasValue)
                    {
                        dta.TuningOffsetCents = 0;
                    }

                    audio = new TemporaryStream();
                    cache.AddStream(audio);

                    progress.Progress();

                    progress.SetNextWeight(10);
                    long samples           = audioformat.Decoder.Samples;
                    CryptedMoggStream mogg = new CryptedMoggStream(audio);
                    mogg.WriteHeader();
                    RawkAudio.Encoder encoder = new RawkAudio.Encoder(mogg, audioformat.Mappings.Count, audioformat.Decoder.SampleRate);
                    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, audioformat.Decoder.AudioBuffer.Rank2));
                        if (read <= 0)
                        {
                            break;
                        }

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

                        encoder.Write(buffer, read);
                        samples -= read;
                        progress.Progress(read);
                    }
                    progress.EndTask();
                    progress.Progress(10);

                    encoder.Dispose();
                    audioformat.Decoder.Dispose();
                    audio.Position = 0;

                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Drums));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Bass));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Guitar));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Vocals));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Ambient));

                    for (int i = 0; i < dta.Song.Cores.Count; i++)
                    {
                        dta.Song.Cores[i] = -1;
                    }

                    songs = new TemporaryStream();
                    cache.AddStream(songs);
                    dta.ToDTB().SaveDTA(songs);

                    ChartFormat chartformat = (data.GetFormat(FormatType.Chart) as IChartFormat).DecodeChart(data, progress);
                    if (chart != null && ChartFormatRB.Instance.NeedsFixing(data))
                    {
                        data.CloseStream(chart);
                        chart = null;
                    }

                    if (chart == null)
                    {
                        chart = new TemporaryStream();
                        cache.AddStream(chart);
                        PlatformRB2WiiCustomDLC.AdjustChart(song, audioformat, chartformat).ToMidi().ToMid().Save(chart);
                        chart.Position = 0;
                    }

                    if (weights == null)
                    {
                        weights = new TemporaryStream();
                        cache.AddStream(weights);
                        PlatformRB2WiiCustomDLC.CreateWeights(weights, chartformat);
                        weights.Position = 0;
                    }

                    if (pan == null)
                    {
                        pan = new TemporaryStream();
                        cache.AddStream(pan);
                        PlatformRB2WiiCustomDLC.CreatePan(pan, chartformat);
                        pan.Position = 0;
                    }

                    progress.Progress(3);

                    DirectoryNode dir = new DirectoryNode("songs");
                    stfs.Root.AddChild(dir);
                    dir.AddChild(new FileNode("songs.dta", songs));
                    DirectoryNode songdir = new DirectoryNode(song.ID);
                    dir.AddChild(songdir);
                    songdir.AddChild(new FileNode(song.ID + ".mogg", audio));
                    songdir.AddChild(new FileNode(song.ID + ".mid", chart));
                    DirectoryNode gendir = new DirectoryNode("gen");
                    songdir.AddChild(gendir);
                    gendir.AddChild(new FileNode(song.ID + ".milo_xbox", milo));
                    gendir.AddChild(new FileNode(song.ID + "_weights.bin", weights));

                    Stream ostream = new FileStream(path, FileMode.Create);
                    stfs.Save(ostream);
                    ostream.Close();

                    data.CloseStream(audio);
                    data.CloseStream(chart);
                    data.CloseStream(pan);
                    data.CloseStream(weights);
                    data.CloseStream(milo);

                    if (ownformat)
                    {
                        data.Dispose();
                    }

                    progress.Progress();
                    progress.EndTask();
                }
            });
        }
コード例 #2
0
        public static void ExportRBN(string path, FormatData original)
        {
            Program.Form.Progress.QueueTask(progress => {
                progress.NewTask("Exporting to RBA file", 16);
                RBA rba = new RBA();

                FormatData data = original;

                Program.Form.TaskMutex.WaitOne();
                bool local     = data.PlatformData.Platform == PlatformLocalStorage.Instance;
                bool ownformat = false;
                if (!local && Configuration.MaxConcurrentTasks > 1)
                {
                    data = new TemporaryFormatData(data.Song, data.PlatformData);
                    original.SaveTo(data);
                    ownformat = true;
                }
                Program.Form.TaskMutex.ReleaseMutex();

                using (DelayedStreamCache cache = new DelayedStreamCache()) {
                    AudioFormat audioformat = (data.GetFormat(FormatType.Audio) as IAudioFormat).DecodeAudio(data, progress);

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

                    progress.Progress();

                    // RBN Required DTA settings
                    SongsDTA dta      = PlatformRB2WiiCustomDLC.GetSongsDTA(data.Song, audioformat, false);
                    dta.AlbumArt      = true;
                    dta.BaseName      = "song";
                    dta.Song.Name     = "songs/" + dta.BaseName + "/" + dta.BaseName;
                    dta.Song.MidiFile = "songs/" + dta.BaseName + "/" + dta.BaseName + ".mid";
                    dta.Rating        = 4;
                    dta.Genre         = "rock";
                    dta.SubGenre      = "subgenre_rock";
                    dta.Format        = 4;
                    dta.SongID        = 0;
                    dta.Origin        = "rb2";
                    dta.Ugc           = 1;
                    dta.SongLength    = 300000;
                    dta.Preview[0]    = 0;
                    dta.Preview[1]    = 30000;
                    dta.Context       = 2000;
                    dta.BasePoints    = 0;
                    if (!dta.TuningOffsetCents.HasValue)
                    {
                        dta.TuningOffsetCents = 0;
                    }

                    rba.Audio = new TemporaryStream();
                    cache.AddStream(rba.Audio);

                    progress.Progress();

                    progress.SetNextWeight(10);
                    long samples           = audioformat.Decoder.Samples;
                    CryptedMoggStream mogg = new CryptedMoggStream(rba.Audio);
                    mogg.WriteHeader();
                    RawkAudio.Encoder encoder = new RawkAudio.Encoder(mogg, audioformat.Mappings.Count, audioformat.Decoder.SampleRate);
                    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, audioformat.Decoder.AudioBuffer.Rank2));
                        if (read <= 0)
                        {
                            break;
                        }

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

                        encoder.Write(buffer, read);
                        samples -= read;
                        progress.Progress(read);
                    }
                    progress.EndTask();
                    progress.Progress(10);

                    encoder.Dispose();
                    audioformat.Decoder.Dispose();
                    rba.Audio.Position = 0;

                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Drums));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Bass));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Guitar));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Vocals));
                    dta.Song.TracksCount.Add(audioformat.Mappings.Count(m => m.Instrument == Instrument.Ambient));

                    for (int i = 0; i < dta.Song.Cores.Count; i++)
                    {
                        dta.Song.Cores[i] = -1;
                    }

                    rba.Data = new TemporaryStream();
                    cache.AddStream(rba.Data);
                    dta.Save(rba.Data);

                    Stream stream = new MemoryStream(Properties.Resources.rbn_metadata);
                    rba.Metadata  = stream;
                    stream        = new MemoryStream(Properties.Resources.rbn_album);
                    rba.AlbumArt  = stream;
                    stream        = new MemoryStream(Properties.Resources.rbn_milo);
                    rba.Milo      = stream;
                    stream        = new MemoryStream(Properties.Resources.rbn_weights);
                    rba.Weights   = stream;

                    if (data.Formats.Contains(ChartFormatRB.Instance) && !ChartFormatRB.Instance.NeedsFixing(data))
                    {
                        rba.Chart = data.GetStream(ChartFormatRB.Instance, ChartFormatRB.ChartFile);
                    }
                    else
                    {
                        IChartFormat chartformat = data.GetFormat(FormatType.Chart) as IChartFormat;
                        NoteChart chart          = PlatformRB2WiiCustomDLC.AdjustChart(data.Song, audioformat, chartformat.DecodeChart(data, progress));
                        rba.Chart = new TemporaryStream();
                        cache.AddStream(rba.Chart);
                        chart.ToMidi().ToMid().Save(rba.Chart);
                    }

                    progress.Progress(3);

                    rba.Strings.Add(((char)0x02).ToString());
                    rba.Strings.Add(((char)0x22).ToString());
                    rba.Strings.Add((char)0x02 + "090923");
                    rba.Strings.Add("090923");
                    rba.Strings.Add(string.Empty);
                    rba.Strings.Add(string.Empty);
                    rba.Strings.Add((char)0x02 + "090923");
                    rba.Strings.Add("s/rawk/a");

                    Stream ostream = new FileStream(path, FileMode.Create);
                    rba.Save(ostream);
                    ostream.Close();

                    data.CloseStream(rba.Chart);

                    if (ownformat)
                    {
                        data.Dispose();
                    }

                    progress.Progress();
                    progress.EndTask();
                }
            });
        }