// // getOutput // // returns the current oscillator output // public double GetOutput(int i) { SetFrequency(GetToneFrequency(i) / processor.SampleRate); // grab the appropriate wavetable int waveTableIdx = 0; while ((this.phaseInc >= this.waveTables[waveTableIdx].topFreq) && (waveTableIdx < (this.numWaveTables - 1))) { ++waveTableIdx; } WaveTable waveTable = this.waveTables[waveTableIdx]; // linear interpolation double temp = this.phasor * waveTable.waveTableLen; int intPart = (int)temp; double fracPart = temp - intPart; float samp0 = waveTable.waveTable[intPart]; if (++intPart >= waveTable.waveTableLen) { intPart = 0; } float samp1 = waveTable.waveTable[intPart]; UpdatePhase(); return(samp0 + (samp1 - samp0) * fracPart); }
public ModelToWaveService(ThroatModelParameters parameters) { if (parameters.TubeLength <= 0) { throw new Exception("Illegal tube length."); } _parameters = parameters; ///CALCULATE THE SAMPLE RATE, BASED ON NOMINAL ///TUBE LENGTH AND SPEED OF SOUND var speedOfSound = WaveHelper.SpeedOfSound(parameters.TubeTemp); _controlPeriod = Math.Round((speedOfSound * parameters.TotalSections * parameters.SectionLength) / (parameters.TubeLength * parameters.InControlRate)); SampleRate = parameters.InControlRate * _controlPeriod; //var actualTubeLength = (speedOfSound * totalSections * sectionLength) / sampleRate; _nyquist = SampleRate / 2.0; _breathinessFactor = parameters.GlotSrcBreathiness / 100d; _crossmixFactor = 1.0d / WaveHelper.CalculateAmplitude(parameters.NoiseCrossmixOffset); _dampingFactor = (1.0d - (parameters.JunctionLoss / 100d)); _waveTable = new WaveTable(SampleRate, parameters); _bandpassFilter = new BandpassFilter(); _vocalTract = new VocalTract(parameters, _nyquist, SampleRate); // initializeFIRFilter(FIR_BETA, FIR_GAMMA, FIR_CUTOFF); // /* INITIALIZE THE SAMPLE RATE CONVERSION ROUTINES */ // initializeConversion(); /* INITIALIZE THE TEMPORARY OUTPUT FILE */ // tempFilePtr = tmpfile(); // rewind(tempFilePtr); }
/// <summary> /// Метод, восстанавливает объект WaveTableOscillator из потока. /// </summary> /// <param name="stream"></param> /// <returns></returns> public static WaveTableOscillator Deserialize(Stream stream) { using (var reader = new BinaryReader(stream, System.Text.Encoding.Default, true)) { var waveTablesAmount = reader.ReadInt32(); var waveTables = new WaveTable[waveTablesAmount]; for (int i = 0; i < waveTables.Length; ++i) { var length = reader.ReadInt32(); var phaseIncrement = reader.ReadSingle(); var samples = new float[length]; for (int j = 0; j < samples.Length; ++j) { samples[j] = reader.ReadSingle(); } waveTables[i] = new WaveTable { Length = length, PhaseIncrement = phaseIncrement, Samples = samples, }; } return(new WaveTableOscillator { waveTablesAmount = waveTablesAmount, waveTables = waveTables, }); } }
private void loadTone(ToneParam tone) { param = tone.Clone(); { GameObject obj = transform.FindChild("Panel/LFO").gameObject; setSliderValue(obj, "WaveForm", "lw:", 0, 7, param.Lfo.WS); setSliderValue(obj, "Frequency", "lf:", 0, 127, param.Lfo.LF); setSliderValue(obj, "PMPower", "lp:", 0, 127, param.Lfo.LP); setSliderValue(obj, "AMPower", "la:", 0, 127, param.Lfo.LA); if (param.Extended) { setSliderValue(obj, "AttackRate", "ar:", 0, 127, param.Lfo.Env.xAR); setSliderValue(obj, "DecayRate", "dr:", 0, 127, param.Lfo.Env.xDR); setSliderValue(obj, "SustainLevel", "sl:", 0, 127, param.Lfo.Env.xSL); setSliderValue(obj, "SustainRate", "sr:", 0, 127, param.Lfo.Env.xSR); setSliderValue(obj, "ReleaseRate", "rr:", 0, 127, param.Lfo.Env.xRR); } else { setSliderValue(obj, "AttackRate", "ar:", 0, 31, param.Lfo.Env.AR); setSliderValue(obj, "DecayRate", "dr:", 0, 31, param.Lfo.Env.DR); setSliderValue(obj, "SustainLevel", "sl:", 0, 15, param.Lfo.Env.SL); setSliderValue(obj, "SustainRate", "sr:", 0, 31, param.Lfo.Env.SR); setSliderValue(obj, "ReleaseRate", "rr:", 0, 15, param.Lfo.Env.RR); } } { GameObject obj = transform.FindChild("Panel/ENV").gameObject; setSliderValue(obj, "WaveStyle", "ws:", 0, 7, param.WS); setSliderValue(obj, "KeyScale", "ks:", 0, 3, param.Env.KS); setSliderValue(obj, "VelocitySense", "vs:", 0, 7, param.Env.VS); setSliderValue(obj, "TotalLevel", "tl:", 0, 127, param.Env.TL); if (param.Extended) { setSliderValue(obj, "AttackRate", "ar:", 0, 127, param.Env.xAR); setSliderValue(obj, "DecayRate", "dr:", 0, 127, param.Env.xDR); setSliderValue(obj, "SustainLevel", "sl:", 0, 127, param.Env.xSL); setSliderValue(obj, "SustainRate", "sr:", 0, 127, param.Env.xSR); setSliderValue(obj, "ReleaseRate", "rr:", 0, 127, param.Env.xRR); } else { setSliderValue(obj, "AttackRate", "ar:", 0, 31, param.Env.AR); setSliderValue(obj, "DecayRate", "dr:", 0, 31, param.Env.DR); setSliderValue(obj, "SustainLevel", "sl:", 0, 15, param.Env.SL); setSliderValue(obj, "SustainRate", "sr:", 0, 31, param.Env.SR); setSliderValue(obj, "ReleaseRate", "rr:", 0, 15, param.Env.RR); } } { WaveTable wt = transform.FindChild("Panel/WaveTable").GetComponent <WaveTable>(); for (int i = 0; i < 32; i++) { wt.WT[i] = param.WT[i]; } } updateParam(); }
private void Start() { activeWave = "square"; activeMat = DefaultMat; //Setup controller event listeners leftControllerEvents.TriggerClicked += new ControllerInteractionEventHandler(TriggerClicked); leftControllerEvents.TriggerUnclicked += new ControllerInteractionEventHandler(TriggerUnclicked); //Add multislider mapping for wavetable. WaveTable waves = gameObject.AddComponent <WaveTable>(); waves.controllerEvents = rightControllerEvents; }
/// <summary> /// Устанавливает новое значение инкремента фазы. /// </summary> /// <param name="phaseIncrement">Инкремент фазы.</param> public void SetPhaseIncrement(double phaseIncrement) { this.phaseIncrement = (float)phaseIncrement; int wtIndex = 0; while (wtIndex < waveTablesAmount - 1 && phaseIncrement > waveTables[wtIndex].PhaseIncrement) { wtIndex += 1; } waveTable = waveTables[wtIndex]; }
private void ParseWaveTable(CSVLoader csvLoader) { waveTables = new WaveTable[csvLoader.Rows]; for (int i = 0; i < csvLoader.Rows; i++) { waveTables[i] = new WaveTable(); csvLoader.ReadValue(0, i, string.Empty, out string Value); csvLoader.ReadValue(1, i, string.Empty, out string Value2); Value.Trim(); Value2.Trim(); waveTables[i].numWave = Convert.ToInt32(Value); waveTables[i].interval = (float)Convert.ToDouble(Value2); } }
// // getOutputMinusOffset // // for variable pulse width: initialize to sawtooth, // set phaseOfs to duty cycle, use this for osc output // // returns the current oscillator output // public double GetOutputMinusOffset() { // grab the appropriate wavetable int waveTableIdx = 0; while ((this.phaseInc >= this.waveTables[waveTableIdx].topFreq) && (waveTableIdx < (this.numWaveTables - 1))) { ++waveTableIdx; } WaveTable waveTable = this.waveTables[waveTableIdx]; // linear double temp = this.phasor * waveTable.waveTableLen; int intPart = (int)temp; double fracPart = temp - intPart; float samp0 = waveTable.waveTable[intPart]; if (++intPart >= waveTable.waveTableLen) { intPart = 0; } float samp1 = waveTable.waveTable[intPart]; double samp = samp0 + (samp1 - samp0) * fracPart; // and linear again for the offset part double offsetPhasor = this.phasor + this.phaseOfs; if (offsetPhasor > 1.0) { offsetPhasor -= 1.0; } temp = offsetPhasor * waveTable.waveTableLen; intPart = (int)temp; fracPart = temp - intPart; samp0 = waveTable.waveTable[intPart]; if (++intPart >= waveTable.waveTableLen) { intPart = 0; } samp1 = waveTable.waveTable[intPart]; return(samp - (samp0 + (samp1 - samp0) * fracPart)); }
/// <summary> /// Инициализирует новый объект типа WaveTableOscillator с заданными параметрами. /// </summary> /// <param name="generator">Функция-генератор.</param> /// <param name="startFrequency">Минимальная частота, на которой планируется генерировать звук.</param> /// <param name="endFrequency">Максимальная частота, на которой планируется генерировать звук.</param> public WaveTableOscillator( GeneratorFunction generator, double startFrequency, double endFrequency) { waveTablesAmount = (int)(Math.Floor(Math.Log(endFrequency / startFrequency, 2)) + 1); waveTables = new WaveTable[waveTablesAmount]; for (int i = 0; i < waveTables.Length; ++i) { var frequency = startFrequency * (1 << i); var samples = PrepareSamples(generator, frequency, DefaultSampleRate / 2); waveTables[i] = new WaveTable { Length = samples.Length, PhaseIncrement = (float)(frequency / DefaultSampleRate), Samples = samples, }; } Normalize(); }
public void SetWaveTable(WaveTable waveTable) { }
public void SetWaveTable(WaveTable waveTable) { }
void Awake() { syntheStation = GameObject.FindObjectOfType <MySyntheStation>(); sampleTools = GameObject.FindObjectOfType <SampleTools>(); mmlBox = sampleTools.GetComponent <MyMMLBox>(); { Button extend = transform.FindChild("Panel/Extend").GetComponent <Button>(); extend.onClick.AddListener(() => { param.Extended = !param.Extended; updateParam(); loadTone(param); }); } { inputField = transform.FindChild("Panel/InputField").GetComponent <InputField>(); inputField.onEndEdit.AddListener((v) => { if ((v != null) && (v.Length != 0)) { loadTone(new ToneParam(v)); } else { loadTone(new ToneParam(defaultTone)); } }); PresetButton [] presets = GetComponentsInChildren <PresetButton>(); foreach (PresetButton pb in presets) { Button btn = pb.GetComponent <Button>(); ToneParam tp = new ToneParam(pb.ToneData); btn.onClick.AddListener(() => { loadTone(tp); }); } } { GameObject obj = transform.FindChild("Panel/LFO").gameObject; setupSlider(obj, "WaveForm", "lw:", (val) => { param.Lfo.WS = (Byte)val; updateParam(); }); setupSlider(obj, "Frequency", "lf:", (val) => { param.Lfo.LF = (Byte)val; updateParam(); }); setupSlider(obj, "PMPower", "lp:", (val) => { param.Lfo.LP = (Byte)val; updateParam(); }); setupSlider(obj, "AMPower", "la:", (val) => { param.Lfo.LA = (Byte)val; updateParam(); }); setupSlider(obj, "AttackRate", "ar:", (val) => { param.Lfo.Env.AR = (Byte)val; updateParam(); }); setupSlider(obj, "DecayRate", "dr:", (val) => { param.Lfo.Env.DR = (Byte)val; updateParam(); }); setupSlider(obj, "SustainLevel", "sl:", (val) => { param.Lfo.Env.SL = (Byte)val; updateParam(); }); setupSlider(obj, "SustainRate", "sr:", (val) => { param.Lfo.Env.SR = (Byte)val; updateParam(); }); setupSlider(obj, "ReleaseRate", "rr:", (val) => { param.Lfo.Env.RR = (Byte)val; updateParam(); }); } { GameObject obj = transform.FindChild("Panel/ENV").gameObject; setupSlider(obj, "WaveStyle", "ws:", (val) => { param.WS = (Byte)val; updateParam(); }); setupSlider(obj, "KeyScale", "ks:", (val) => { param.Env.KS = (Byte)val; updateParam(); }); setupSlider(obj, "VelocitySense", "vs:", (val) => { param.Env.VS = (Byte)val; updateParam(); }); setupSlider(obj, "TotalLevel", "tl:", (val) => { param.Env.TL = (Byte)val; updateParam(); }); setupSlider(obj, "AttackRate", "ar:", (val) => { param.Env.AR = (Byte)val; updateParam(); }); setupSlider(obj, "DecayRate", "dr:", (val) => { param.Env.DR = (Byte)val; updateParam(); }); setupSlider(obj, "SustainLevel", "sl:", (val) => { param.Env.SL = (Byte)val; updateParam(); }); setupSlider(obj, "SustainRate", "sr:", (val) => { param.Env.SR = (Byte)val; updateParam(); }); setupSlider(obj, "ReleaseRate", "rr:", (val) => { param.Env.RR = (Byte)val; updateParam(); }); } { WaveTable wt = transform.FindChild("Panel/WaveTable").GetComponent <WaveTable>(); wt.OnUpdateAction = (idx) => { param.WT[idx] = wt.WT[idx]; updateParam(); }; } { Keyboard keyboard = transform.FindChild("Panel/Keyboard").GetComponent <Keyboard>(); keyboard.ChNo = ChNo; keyboard.PortNo = PortNo; } { Transform mmlEditorCanvas = transform.parent.FindChild("MMLPlayerCanvas"); Button button = transform.FindChild("Panel/MMLEditorButton").GetComponent <Button>(); button.onClick.AddListener(() => { mmlBox.Play("Click"); sampleTools.MoveCameraTo(mmlEditorCanvas.localPosition); }); } }