public SampleDataAsset(string name, WaveFile wave) { if (name == null) { throw new ArgumentNullException("An asset must be given a valid name."); } assetName = name; SamplerChunk smpl = wave.FindChunk <SamplerChunk>(); if (smpl != null) { sampleRate = (int)(44100.0 * (1.0 / (smpl.SamplePeriod / 22675.0))); rootKey = (short)smpl.UnityNote; tune = (short)(smpl.PitchFraction * 100); if (smpl.Loops.Length > 0) { //--WARNING ASSUMES: smpl.Loops[0].Type == SamplerChunk.SampleLoop.LoopType.Forward loopStart = smpl.Loops[0].Start; loopEnd = smpl.Loops[0].End + smpl.Loops[0].Fraction + 1; } } else { sampleRate = wave.Format.SampleRate; } byte[] data = wave.Data.RawSampleData; if (wave.Format.ChannelCount != audioChannels) //reformat to supported channels { data = WaveHelper.GetChannelPcmData(data, wave.Format.BitsPerSample, wave.Format.ChannelCount, audioChannels); } sampleData = PcmData.Create(wave.Format.BitsPerSample, data, true); start = 0; end = sampleData.Length; }
public SampleDataAsset(int size, BinaryReader reader) { assetName = IOHelper.Read8BitString(reader, 20); sampleRate = reader.ReadInt32(); rootKey = reader.ReadInt16(); tune = reader.ReadInt16(); loopStart = reader.ReadDouble(); loopEnd = reader.ReadDouble(); byte bits = reader.ReadByte(); byte chans = reader.ReadByte(); byte[] data = reader.ReadBytes(size - 46); if (chans != audioChannels) //reformat to supported channels { data = WaveHelper.GetChannelPcmData(data, bits, chans, audioChannels); } sampleData = PcmData.Create(bits, data, true); start = 0; end = sampleData.Length; }