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 SampleGenerator(GeneratorDescriptor description, AssetManager assets) : base(description) { SampleDataAsset sample = assets.FindSample(IOHelper.GetFileNameWithoutExtension(description.AssetName)); if (sample == null) throw new Exception("Could not find asset: (" + description.AssetName + ")."); data = sample.SampleData; freq = sample.SampleRate; if (end < 0) end = sample.End; if (start < 0) start = sample.Start; if (loopEnd < 0) { if (sample.LoopEnd < 0) loopEnd = end; else loopEnd = sample.LoopEnd; } if (loopStart < 0) { if (sample.LoopStart < 0) loopStart = start; else loopStart = sample.LoopStart; } if (genPeriod < 0) genPeriod = 1; if (root < 0) { root = sample.RootKey; if (tuneCents == 0) tuneCents = sample.Tune; } //check sample end and loop end for consistency if (end > data.Length) end = data.Length; if (loopEnd > end) loopEnd = end; }
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); }