public override AudioFormat DecodeAudio(FormatData data, ProgressIndicator progress)
        {
            if (!data.HasStream(this, WadName) && !data.HasStream(this, DatName))
            {
                throw new FormatException();
            }

            AudioFormat format = new AudioFormat();

            format.Decoder = new MultiDecoder(RawkAudio.Decoder.BufferSize);

            Stream wad = data.GetStream(this, WadName);
            Stream dat = data.GetStream(this, DatName);

            DatWad audio = new DatWad(new EndianReader(dat, Endianness.BigEndian), wad);

            data.CloseStream(dat);

            foreach (DatWad.Node node in audio.Nodes)
            {
                string     name       = node.Filename.Substring(node.Filename.LastIndexOf('_') + 1).ToLower().Trim();
                Instrument instrument = Instrument.Ambient;
                if ("preview.wav".StartsWith(name))
                {
                    instrument = Instrument.Preview;
                }
                else if ("guitar.wav".StartsWith(name))
                {
                    instrument = Instrument.Guitar;
                }
                else if ("rhythm.wav".StartsWith(name))
                {
                    instrument = Instrument.Bass;
                }
                else if ("song.wav".StartsWith(name))
                {
                    instrument = Instrument.Ambient;
                }
                else
                {
                    continue;
                }

                IDecoder decoder = new RawkAudio.Decoder(node.Data, RawkAudio.Decoder.AudioFormat.FmodSoundBank);
                (format.Decoder as MultiDecoder).AddDecoder(decoder);

                for (int i = 0; i < decoder.Channels; i++)
                {
                    format.Mappings.Add(new AudioFormat.Mapping(0, 0, instrument));
                }
            }

            format.SetDisposeStreams(data, new Stream[] { wad, dat });

            format.AutoBalance();

            return(format);
        }
        public override bool AddSong(PlatformData data, SongData song, ProgressIndicator progress)
        {
            FormatData formatdata = new TemporaryFormatData(song, data);

            DirectoryNode dir = data.Session["songdir"] as DirectoryNode;

            int         delay      = 0;
            bool        eighthhopo = false;
            int         hopofreq   = -1;
            AudioFormat format     = new AudioFormat();
            FileNode    songini    = dir.Navigate("song.ini", false, true) as FileNode;

            if (songini != null)
            {
                Ini ini = Ini.Create(songini.Data);
                songini.Data.Close();
                string value = ini.GetValue("song", "name"); if (value != null)
                {
                    song.Name = value;
                }
                value = ini.GetValue("song", "artist"); if (value != null)
                {
                    song.Artist = value;
                }
                value = ini.GetValue("song", "album"); if (value != null)
                {
                    song.Album = value;
                }
                value = ini.GetValue("song", "genre"); if (value != null)
                {
                    song.Genre = value;
                }
                value = ini.GetValue("song", "year"); if (value != null)
                {
                    song.Year = int.Parse(value);
                }
                value = ini.GetValue("song", "version"); if (value != null)
                {
                    song.Version = int.Parse(value);
                }
                value = ini.GetValue("song", "delay"); if (value != null)
                {
                    delay = int.Parse(value);
                }
                value = ini.GetValue("song", "eighthnote_hopo"); if (value != null)
                {
                    eighthhopo = string.Compare(value, "true", true) == 0 ? true : false;
                }
                value = ini.GetValue("song", "hopofreq"); if (value != null)
                {
                    hopofreq = int.Parse(value);
                }
                value = ini.GetValue("song", "tags"); if (value != null)
                {
                    song.Master = string.Compare(value, "cover", true) == 0 ? false : true;
                }
                value = ini.GetValue("song", "icon"); if (value != null)
                {
                    song.Game = GetGameFromIcon(value);
                }
                value = ini.GetValue("song", "diff_band"); if (value != null)
                {
                    song.Difficulty[Instrument.Ambient] = ImportMap.GetBaseRank(Instrument.Ambient, int.Parse(value));
                }
                value = ini.GetValue("song", "diff_bass"); if (value != null)
                {
                    song.Difficulty[Instrument.Bass] = ImportMap.GetBaseRank(Instrument.Bass, int.Parse(value));
                }
                value = ini.GetValue("song", "diff_drums"); if (value != null)
                {
                    song.Difficulty[Instrument.Drums] = ImportMap.GetBaseRank(Instrument.Drums, int.Parse(value));
                }
                value = ini.GetValue("song", "diff_guitar"); if (value != null)
                {
                    song.Difficulty[Instrument.Guitar] = ImportMap.GetBaseRank(Instrument.Guitar, int.Parse(value));
                }
            }

            format.InitialOffset = -delay;

            FileNode album = dir.Navigate("album.png", false, true) as FileNode;

            if (album != null)
            {
                song.AlbumArt = new Bitmap(album.Data);
            }

            FileNode  chartfile = dir.Navigate("notes.mid", false, true) as FileNode;
            NoteChart chart     = null;

            if (chartfile != null)
            {
                ChartFormatRB.Instance.Create(formatdata, chartfile.Data, null, 0, null, null, 0, false, true);
                chart = NoteChart.Create(Midi.Create(Mid.Create(chartfile.Data)));
                chartfile.Data.Close();
            }

            if (chart != null && eighthhopo)
            {
                song.HopoThreshold = chart.Division.TicksPerBeat / 2 + 10;
            }
            else if (hopofreq >= 0)
            {
                // TODO: This
            }

            List <Stream> streams = new List <Stream>();

            foreach (Node node in dir)
            {
                FileNode file = node as FileNode;
                if (file == null)
                {
                    continue;
                }
                string extension = Path.GetExtension(file.Name).ToLower();
                if (extension != ".ogg")
                {
                    continue;
                }

                string            name       = Path.GetFileNameWithoutExtension(file.Name);
                Instrument        instrument = Platform.InstrumentFromString(name);
                RawkAudio.Decoder decoder    = new RawkAudio.Decoder(file.Data, RawkAudio.Decoder.AudioFormat.VorbisOgg);
                for (int i = 0; i < decoder.Channels; i++)
                {
                    format.Mappings.Add(new AudioFormat.Mapping(0, 0, instrument));
                }
                decoder.Dispose();
                file.Data.Close();

                streams.Add(file.Data);
            }
            format.AutoBalance();

            if (streams.Count > 0)
            {
                AudioFormatOgg.Instance.Create(formatdata, streams.ToArray(), format);
            }
            else if (chartfile == null)
            {
                return(false);
            }

            data.AddSong(formatdata);

            return(true);
        }