/* * var startTime = System.Diagnostics.Stopwatch.StartNew(); * startTime.Stop(); * var resultTime = startTime.Elapsed; * string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", * resultTime.Hours, * resultTime.Minutes, * resultTime.Seconds, * resultTime.Milliseconds); */ public float GetSampleValue(ModuleMixerChannel mc) { if (mc.instrumentIndex <= 0) { return(0.0f); } ModuleInstrument sampleData = module.Instruments[(int)mc.instrumentIndex - 1]; mc.instrumentPosition = sampleData.CalculateInstrumentPosition(mc.instrumentPosition); return(GetSampleValueSimple(mc)); }
protected virtual float GetSampleValueLinear(ModuleMixerChannel mc) { ModuleInstrument sampleData = module.Instruments[(int)mc.instrumentIndex - 1]; int posInt = (int)mc.instrumentPosition; float posReal = mc.instrumentPosition - posInt; float a1 = sampleData[posInt]; if ((posInt + 1) >= mc.instrumentLength) { return(a1 * mc.channelVolume); } float a2 = sampleData[posInt + 1]; return((a1 + (a2 - a1) * posReal) * mc.channelVolume); }
protected virtual float GetSampleValueSpline(ModuleMixerChannel mc) { ModuleInstrument sampleData = module.Instruments[(int)mc.instrumentIndex - 1]; int posInt = (int)mc.instrumentPosition; float posReal = mc.instrumentPosition - posInt; float a2 = sampleData[posInt]; if (((posInt - 1) < 0) || ((posInt + 2) >= mc.instrumentLength)) { return(a2 * mc.channelVolume); } float a1 = sampleData[posInt - 1]; float a3 = sampleData[posInt + 1]; float a4 = sampleData[posInt + 2]; float b0 = a1 + a2 + a2 + a2 + a2 + a3; float b1 = -a1 + a3; float b2 = a1 - a2 - a2 + a3; float b3 = -a1 + a2 + a2 + a2 - a3 - a3 - a3 + a4; return((((b3 * posReal * 0.1666666f + b2 * 0.5f) * posReal + b1 * 0.5f) * posReal + b0 * 0.1666666f) * mc.channelVolume); }
protected virtual float GetSampleValueSimple(ModuleMixerChannel mc) { ModuleInstrument sampleData = module.Instruments[(int)mc.instrumentIndex - 1]; return(sampleData[(int)mc.instrumentPosition] * mc.channelVolume); }
public void Add(ModuleInstrument instrument) { instruments.Add(instrument); }