/// <summary> /// Create a binary wave. /// </summary> /// <param name="f">FISP.</param> public static BinaryWave FromFISP(FISP f) { //Set data. return(new BinaryWave(StreamFactory.CreateStream(f, 4, 0, 0))); }
/// <summary> /// Create a binary wave. /// </summary> /// <param name="r">Riff wave.</param> public static BinaryWave FromRiff(RiffWave r) { return(new BinaryWave(StreamFactory.CreateStream(r, true, 4, 0, 0))); }
/// <summary> /// Create a wave from a FISP. /// </summary> /// <param name="f"></param> /// <returns></returns> public static b_stm CreateStream(FISP f, byte vMajor, byte vMinor, byte vRevision) { //New stream. b_stm s = new b_stm(); //Trim the fat from each loop. object channels = new short[f.data.data.Count()][]; for (int i = 0; i < (channels as short[][]).Length; i++) { List <short> l = new List <short>(); for (int j = 0; j < f.stream.loopEnd; j++) { l.Add(f.data.data[i][j]); } (channels as short[][])[i] = l.ToArray(); } //PCM8 conversion. if (f.stream.encoding == EncodingTypes.PCM8) { channels = EncoderFactory.Pcm16ToPcm8(channels as short[][]); } //If looped. if (f.stream.isLoop) { s = StreamFactory.CreateStream(f.stream.sampleRate, f.stream.loopEnd, channels, f.stream.encoding, vMajor, vMinor, vRevision, f.stream.loopStart); } //Not looped. else { s = StreamFactory.CreateStream(f.stream.sampleRate, f.stream.loopEnd, channels, f.stream.encoding, vMajor, vMinor, vRevision); } //Make tracks. s.info.tracks = new List <b_stm.TrackInfo>(); foreach (FISP.TrackInfo i in f.tracks) { b_stm.TrackInfo t = new b_stm.TrackInfo(); t.globalChannelIndexTable = new Table <byte>(); t.globalChannelIndexTable.count = (uint)i.channels.Count(); t.globalChannelIndexTable.entries = i.channels; t.pan = i.pan; t.span = i.span; t.surroundMode = i.surroundMode; t.volume = i.volume; s.info.tracks.Add(t); } //Nullify. if (f.tracks.Count() <= 0) { s.info.tracks = null; } //Make regions. EXPERIMENTAL! Yell at me if this doesn't work. s.region = null; if (f.regions.Count > 0) { s.region = new SoundNStreamRegionBlock(); s.region.regions = new SoundNStreamRegionBlock.RegionInfo[f.regions.Count]; int index = 0; foreach (FISP.RegionInfo i in f.regions) { SoundNStreamRegionBlock.RegionInfo r = new SoundNStreamRegionBlock.RegionInfo(); r.start = i.start; r.end = i.end; r.loopInfo = new SoundNStreamRegionBlock.RegionInfo.DspAdpcmLoopInfo[s.info.channels.Count]; if (f.stream.encoding >= EncodingTypes.DSP_ADPCM) { for (int j = 0; j < s.info.channels.Count; j++) { short h1 = 0; short h2 = 0; if (r.start >= 1) { h1 = f.data.data[j][r.start - 1]; } if (r.start >= 2) { h2 = f.data.data[j][r.start - 2]; } r.loopInfo[j] = new SoundNStreamRegionBlock.RegionInfo.DspAdpcmLoopInfo() { loopPredScale = s.info.channels[j].dspAdpcmInfo.loop_pred_scale, loopYn1 = h1, loopYn2 = h2 }; } } s.region.regions[index] = r; index++; } } //Set info. s.info.streamSoundInfo.originalLoopStart = f.stream.originalLoopStart; s.info.streamSoundInfo.originalLoopEnd = f.stream.originalLoopEnd; s.info.streamSoundInfo.secretInfo = f.stream.secretInfo; return(s); }