public static Stream AddPreviewDecoder(FormatData data, AudioFormat format, ProgressIndicator progress) { if (data.Song.PreviewTimes != null) { MultiDecoder multi = new MultiDecoder(RawkAudio.Decoder.BufferSize); multi.AddDecoder(format.Decoder); Stream previewstream = new TemporaryStream(); PlatformRB2WiiCustomDLC.TranscodePreview(data.Song.PreviewTimes, format.Mappings, format.Decoder, previewstream, progress); previewstream.Position = 0; IDecoder previewdecoder = new RawkAudio.Decoder(previewstream, RawkAudio.Decoder.AudioFormat.VorbisOgg); multi.AddDecoder(previewdecoder); format.Mappings.Add(new AudioFormat.Mapping(0, previewdecoder.Channels == 1 ? 0 : -1, Instrument.Preview)); if (previewdecoder.Channels == 2) { format.Mappings.Add(new AudioFormat.Mapping(0, 1, Instrument.Preview)); } format.Decoder = multi; multi.Seek(0); return(previewstream); } return(null); }
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); }
internal IDecoder DecodeOggAudio(params Stream[] streamparams) { IList <Stream> streams = streamparams.Where(s => s != null).ToList(); IDecoder decoder = streams.Count == 1 ? null : new MultiDecoder(RawkAudio.Decoder.BufferSize); foreach (Stream stream in streams) { IDecoder sdecoder = new RawkAudio.Decoder(stream, RawkAudio.Decoder.AudioFormat.VorbisOgg); if (decoder == null) { decoder = sdecoder; } else { (decoder as MultiDecoder).AddDecoder(sdecoder); } } return(decoder); }
public override AudioFormat DecodeAudio(FormatData data, ProgressIndicator progress) { AudioFormat format = DecodeFormat(data); Stream audio = data.GetStream(this, AudioName); uint magic = new EndianReader(audio, Endianness.BigEndian).ReadUInt32(); if (magic != 0x5241574b && (magic & 0xFFFFFF00) != 0x42494b00) { throw new FormatException(); // Must start with "RAWK" or "BIK", this is to prevent encrypted biks from being decoded } audio.Position = 0; Stream preview = null; format.Decoder = new RawkAudio.Decoder(audio, RawkAudio.Decoder.AudioFormat.BinkAudio); if (data.HasStream(this, PreviewName)) { preview = data.GetStream(this, PreviewName); magic = new EndianReader(preview, Endianness.BigEndian).ReadUInt32(); preview.Position = 0; if (magic != 0x5241574b && (magic & 0xFFFFFF00) != 0x42494b00) { throw new FormatException(); } IDecoder decoder = new RawkAudio.Decoder(preview, RawkAudio.Decoder.AudioFormat.BinkAudio); MultiDecoder multi = new MultiDecoder(RawkAudio.Decoder.BufferSize); multi.AddDecoder(format.Decoder); multi.AddDecoder(decoder); format.Decoder = multi; } format.SetDisposeStreams(data, new Stream[] { audio, preview }); Game game = data.Song.Game; if (NeversoftMetadata.IsGuitarHero4(game) || NeversoftMetadata.IsGuitarHero5(game)) { format.Decoder = new AmplifyDecoder(format.Decoder, 1.30f); } return(format); }
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(RawkAudio.Decoder.BufferSize); foreach (Stream stream in streams) { IDecoder sdecoder = new RawkAudio.Decoder(stream, RawkAudio.Decoder.AudioFormat.VorbisOgg); if (format.Decoder == null) { format.Decoder = sdecoder; } else { (format.Decoder as MultiDecoder).AddDecoder(sdecoder); } } format.SetDisposeStreams(data, streams); 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); }