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(SampleHeader sample, SoundFontSampleData sampleData) { this.assetName = sample.Name; this.sampleRate = sample.SampleRate; this.rootKey = sample.RootKey; this.tune = sample.Tune; this.start = sample.Start; this.end = sample.End; this.loopStart = sample.StartLoop; this.loopEnd = sample.EndLoop; this.sampleData = PcmData.Create(sampleData.BitsPerSample, sampleData.SampleData, true); }
public SampleDataAsset(SampleHeader sample, SoundFontSampleData sampleData) { Channels = 1; Name = sample.Name; SampleRate = sample.SampleRate; RootKey = sample.RootKey; Tune = sample.Tune; Start = sample.Start; End = sample.End; LoopStart = sample.StartLoop; LoopEnd = sample.EndLoop; SampleData = PcmData.Create(sampleData.BitsPerSample, sampleData.SampleData, true); }
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; }
public SampleDataAsset(SampleHeader sample, SoundFontSampleData sampleData) { Channels = 1; Name = sample.Name; SampleRate = sample.SampleRate; RootKey = sample.RootKey; Tune = sample.Tune; Start = sample.Start; End = sample.End; LoopStart = sample.StartLoop; LoopEnd = sample.EndLoop; if ((sample.SoundFontSampleLink & SFSampleLink.OggVobis) != 0) { throw new Exception("Ogg Vobis encoded soundfonts not supported"); } else { SampleData = PcmData.Create(sampleData.BitsPerSample, sampleData.SampleData, true); } }