/// <summary> /// Create a wave from a binary wave. /// </summary> /// <param name="w">The binary wave.</param> /// <param name="version">Version of the file.</param> /// <returns></returns> public static b_wav CreateWave(BinaryWave w, byte vMajor, byte vMinor, byte vRevision) { b_wav b = new b_wav(); b.fileHeader = new FileHeader("FWAV", ByteOrder.BigEndian, vMajor, vMinor, vRevision, 0, new List <SizedReference>()); b.data = w.Data; b.info = new b_wav.InfoBlock(); b.info.sampleRate = w.SampleRate; b.info.originalLoopStart = w.LoopStartSample; b.info.loopStart = w.LoopStartSample; b.info.loopEnd = w.LoopEndSample == 0xFFFFFFFF ? w.NumSamples : w.LoopEndSample; b.info.isLoop = w.Loops && w.LoopEndSample != 0xFFFFFFFF; b.info.encoding = 2; b.info.channelInfo = new List <b_wav.InfoBlock.ChannelInfo>(); foreach (DspAdpcmInfo d in w.DspAdpcmInfo) { b_wav.InfoBlock.ChannelInfo i = new b_wav.InfoBlock.ChannelInfo(); i.dspAdpcmInfo = d; b.info.channelInfo.Add(i); } b.Update(ByteOrder.BigEndian); return(b); }
/// <summary> /// Create a wave from a stream. /// </summary> /// <param name="s">The stream.</param> /// <param name="version">Version of the file.</param> /// <returns></returns> public static b_wav CreateWave(b_stm s, byte vMajor, byte vMinor, byte vRevision) { b_wav b = new b_wav(); b.fileHeader = new FileHeader("FWAV", ByteOrder.BigEndian, vMajor, vMinor, vRevision, 0, new List <SizedReference>()); b.data = s.data; b.info = new b_wav.InfoBlock(); b.info.sampleRate = s.info.streamSoundInfo.sampleRate; b.info.originalLoopStart = s.info.streamSoundInfo.originalLoopStart; b.info.loopStart = s.info.streamSoundInfo.loopStart; b.info.loopEnd = s.info.streamSoundInfo.sampleCount; b.info.isLoop = s.info.streamSoundInfo.isLoop; b.info.encoding = s.info.streamSoundInfo.encoding; b.info.channelInfo = new List <b_wav.InfoBlock.ChannelInfo>(); foreach (b_stm.ChannelInfo c in s.info.channels) { b_wav.InfoBlock.ChannelInfo i = new b_wav.InfoBlock.ChannelInfo(); i.dspAdpcmInfo = c.dspAdpcmInfo; b.info.channelInfo.Add(i); } b.Update(ByteOrder.BigEndian); return(b); }
/// <summary> /// Create a standard b_wav. /// </summary> /// <param name="sampleRate">The sample rate.</param> /// <param name="numSamples">Number of samples.</param> /// <param name="samples">Pcm8[][] or Pcm16[][] audio samples.</param> /// <param name="encoding">If samples is Pcm8[][] always 0. Must be 1 or 2 for if samples is Pcm16[][].</param> /// <param name="version">The version of the file.</param> /// <returns></returns> public static b_wav CreateWave(UInt32 sampleRate, UInt32 numSamples, object samples, byte encoding, byte vMajor, byte vMinor, byte vRevision) { //Create wav. b_wav b = new b_wav(); b.fileHeader = new FileHeader("FWAV", ByteOrder.BigEndian, vMajor, vMinor, vRevision, 0, new List <SizedReference>()); b.info = new b_wav.InfoBlock(); b.info.magic = "INFO".ToCharArray(); b.info.encoding = encoding; b.info.isLoop = false; b.info.loopStart = b_wav.InfoBlock.NULL_LOOP; b.info.loopEnd = numSamples; b.info.originalLoopStart = b_wav.InfoBlock.NULL_LOOP; b.info.padding = 0; b.info.sampleRate = sampleRate; b.info.channelInfo = new List <b_wav.InfoBlock.ChannelInfo>(); //Encoding. switch (encoding) { case EncodingTypes.PCM8: b.data = new SoundNStreamDataBlock(EncoderFactory.Pcm8ToSignedPcm8(samples as byte[][]), encoding); for (int i = 0; i < (samples as byte[][]).Length; i++) { b.info.channelInfo.Add(new b_wav.InfoBlock.ChannelInfo() { reserved = 0, dspAdpcmInfo = null }); } break; case EncodingTypes.PCM16: b.data = new SoundNStreamDataBlock(samples, encoding); for (int i = 0; i < (samples as Int16[][]).Length; i++) { b.info.channelInfo.Add(new b_wav.InfoBlock.ChannelInfo() { reserved = 0, dspAdpcmInfo = null }); } break; case EncodingTypes.DSP_ADPCM: b.data = new SoundNStreamDataBlock(EncoderFactory.Pcm16ToDspApdcmWAV(samples as Int16[][], ref b), encoding); break; } b.Update(ByteOrder.BigEndian); //Return wav. return(b); }