コード例 #1
0
        public static void TranscodePreview(IList <int> previewtimes, List <AudioFormat.Mapping> maps, IDecoder decoder, Stream stream, ProgressIndicator progress)
        {
            RawkAudio.Encoder encoder;
            if (maps != null && maps.Count(m => m.Instrument == Instrument.Preview) > 0)
            {
                decoder.Seek(0);
                List <ushort> masks = new List <ushort>();
                foreach (var m in maps)
                {
                    if (m.Instrument == Instrument.Preview)
                    {
                        masks.Add((ushort)(1 << maps.IndexOf(m)));
                    }
                }
                ushort[] mask = masks.ToArray();

                encoder = new RawkAudio.Encoder(stream, mask.Length, decoder.SampleRate, 28000);
                long samples = decoder.Samples;
                progress.NewTask("Transcoding Preview", samples);
                JaggedShortArray buffer = new JaggedShortArray(encoder.Channels, decoder.AudioBuffer.Rank2);
                while (samples > 0)
                {
                    int read = decoder.Read((int)Math.Min(samples, decoder.AudioBuffer.Rank2));
                    if (read <= 0)
                    {
                        break;
                    }

                    decoder.AudioBuffer.DownmixTo(buffer, mask, read);

                    encoder.Write(buffer, read);
                    samples -= read;
                    progress.Progress(read);
                }
                progress.EndTask();
            }
            else
            {
                long start = Math.Min(decoder.Samples, (long)previewtimes[0] * decoder.SampleRate / 1000);
                decoder.Seek(start);
                long duration = Math.Min(decoder.Samples - start, (long)(previewtimes[1] - previewtimes[0]) * decoder.SampleRate / 1000);
                encoder = new RawkAudio.Encoder(stream, 1, decoder.SampleRate);
                AudioFormat.Transcode(encoder, decoder, duration, progress);
            }
            encoder.Dispose();
        }
コード例 #2
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();
        }
コード例 #3
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);
        }
コード例 #4
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();
        }