/// <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); }
/// <summary> /// New binary wave. /// </summary> /// <param name="wave">Wave to create this from.</param> public BinaryWave(b_wav wave) { //Set data. ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; Major = 0; Minor = 1; SampleRate = wave.info.sampleRate; NumSamples = wave.info.loopEnd; switch (wave.info.encoding) { case 0: wave.data.dspAdpcm = EncoderFactory.Pcm16ToDspApdcmWAV(EncoderFactory.SignedPcm8ToPcm16(wave.data.pcm8), ref wave); break; case 1: wave.data.dspAdpcm = EncoderFactory.Pcm16ToDspApdcmWAV(wave.data.pcm16, ref wave); break; } DspAdpcmInfo = new DspAdpcmInfo[wave.info.channelInfo.Count]; for (int i = 0; i < DspAdpcmInfo.Length; i++) { DspAdpcmInfo[i] = wave.info.channelInfo[i].dspAdpcmInfo; } Loops = wave.info.isLoop; LoopStartSample = wave.info.loopStart; LoopEndSample = wave.info.loopEnd; Data = wave.data; //Do channel pans. ChannelPans = new ChannelPan[wave.info.channelInfo.Count()]; for (int i = 0; i < wave.info.channelInfo.Count(); i++) { if (i == wave.info.channelInfo.Count() - 1) { ChannelPans[i] = ChannelPan.Middle; } else if (i % 2 == 0) { ChannelPans[i] = ChannelPan.Left; ChannelPans[i] = ChannelPan.Right; } } }